Example usage for java.lang.reflect Modifier isStatic

List of usage examples for java.lang.reflect Modifier isStatic

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isStatic.

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

Return true if the integer argument includes the static modifier, false otherwise.

Usage

From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java

private boolean _isJSONWebServiceClass(Class<?> clazz) {
    if (!clazz.isAnonymousClass() && !clazz.isArray() && !clazz.isEnum() && !clazz.isLocalClass()
            && !clazz.isPrimitive() && !(clazz.isMemberClass() ^ Modifier.isStatic(clazz.getModifiers()))) {

        return true;
    }//from   ww w .  j  a v  a  2 s .c  o  m

    return false;
}

From source file:com.ms.commons.test.common.ReflectUtil.java

public static Field[] getStaticFields(Field[] fields) {
    if (fields == null) {
        return null;
    }/*  www.j a va2s  .  c  om*/
    List<Field> staticFields = new ArrayList<Field>();
    for (Field field : fields) {
        if (Modifier.isStatic(field.getModifiers())) {
            staticFields.add(field);
        }
    }
    return staticFields.toArray(new Field[0]);
}

From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java

/**
 * Creates a serializable copy of a given object
 *///w  w w.j  a  v  a 2 s  . c  om
protected Object createClone(Object source) {
    try {
        Object target = source.getClass().newInstance();
        List<Field> fieldList = new ArrayList<Field>();
        getAllFields(source.getClass(), fieldList);
        for (Field field : fieldList) {
            Object obj = field.get(source);

            if (obj instanceof Integer || obj instanceof Float || obj instanceof Double
                    || obj instanceof Character || obj instanceof Long || obj instanceof Boolean
                    || obj instanceof String) {
                if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) {
                    field.setAccessible(true);
                    field.set(target, obj);
                }
            }
        }
        return target;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.niolex.commons.reflect.FieldFilter.java

/**
 * Filter the fields without static fields.
 *
 * @return this//  w  w w  .j ava  2 s  .co  m
 */
public final FieldFilter<FT> noStatic() {
    return this.add(new Filter() {
        @Override
        public boolean isValid(Field f) {
            return !Modifier.isStatic(f.getModifiers());
        }
    });
}

From source file:com.google.gdt.eclipse.designer.model.property.DateTimeFormatPropertyEditor.java

public void configure(EditorState state, Map<String, Object> parameters) throws Exception {
    m_loader = new CompositeClassLoader() {
        @Override/*w w  w  .  j av a2s.c  o  m*/
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            if (ReflectionUtils.class.getCanonicalName().equals(name)) {
                return ReflectionUtils.class;
            }
            return super.loadClass(name);
        }
    };
    m_loader.add(state.getEditorLoader(), null);
    // get static formats
    {
        m_formatClass = m_loader.loadClass("com.google.gwt.i18n.client.DateTimeFormat");
        m_formatMethods = Lists.newArrayList();
        for (Method method : m_formatClass.getMethods()) {
            int modifiers = method.getModifiers();
            if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)
                    && method.getParameterTypes().length == 0 && method.getName().endsWith("Format")) {
                m_formatMethods.add(method);
            }
        }
    }
    // extract script
    {
        final String EXTRACT_PARAM = "extract";
        if (parameters.containsKey(EXTRACT_PARAM)) {
            m_extractScript = (String) parameters.get(EXTRACT_PARAM);
        } else {
            m_extractScript = "";
        }
    }
    // source template
    {
        final String SOURCE_PARAM = "source";
        if (parameters.containsKey(SOURCE_PARAM)) {
            m_sourceTemplate = (String) parameters.get(SOURCE_PARAM);
        } else {
            m_sourceTemplate = "";
        }
    }
}

From source file:com.laxser.blitz.web.impl.module.ControllerRef.java

private boolean quicklyPass(List<Method> pastMethods, Method method, Class<?> controllerClass) {
    // public, not static, not abstract, @Ignored
    if (!Modifier.isPublic(method.getModifiers()) || Modifier.isAbstract(method.getModifiers())
            || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(Ignored.class)) {
        if (logger.isDebugEnabled()) {
            logger.debug("ignores method of controller " + controllerClass.getName() + "." + method.getName()
                    + "  [@ignored?not public?abstract?static?]");
        }/* ww w.ja v a 2s  . c  o m*/
        return true;
    }
    // ?(?)?????
    for (Method past : pastMethods) {
        if (past.getName().equals(method.getName())) {
            if (Arrays.equals(past.getParameterTypes(), method.getParameterTypes())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.codehaus.griffon.commons.AbstractGriffonClass.java

private <T> T getGroovyProperty(String propName, Class<T> type, boolean onlyStatic) {
    Object value = null;/*w ww. j  a  v  a 2  s .  co m*/
    if (GroovyObject.class.isAssignableFrom(getClazz())) {
        MetaProperty metaProperty = getMetaClass().getMetaProperty(propName);
        if (metaProperty != null) {
            int modifiers = metaProperty.getModifiers();
            if (Modifier.isStatic(modifiers)) {
                value = metaProperty.getProperty(clazz);
            } else if (!onlyStatic) {
                value = metaProperty.getProperty(getReferenceInstance());
            }
        }
    }
    return returnOnlyIfInstanceOf(value, type);
}

From source file:io.coala.json.JsonUtil.java

/**
 * @param om the {@link ObjectMapper} used to parse/deserialize/unmarshal
 * @param tree the partially parsed JSON {@link TreeNode}
 * @param resultType the type of result {@link Object}
 * @param imports the {@link Properties} instances for default values, etc.
 * @return the parsed/deserialized/unmarshalled {@link Object}
 */// w w  w.  j a v  a 2 s  .c o m
public static <T> T valueOf(final ObjectMapper om, final TreeNode tree, final Class<T> resultType,
        final Properties... imports) {
    if (tree == null)
        return null;
    // TODO add work-around for Wrapper sub-types?
    if (resultType.isMemberClass() && !Modifier.isStatic(resultType.getModifiers()))
        return Thrower.throwNew(IllegalArgumentException.class, "Unable to deserialize non-static member: {}",
                resultType);

    try {
        return (T) om.treeToValue(tree, checkRegistered(om, resultType, imports));
    } catch (final Exception e) {
        return Thrower.rethrowUnchecked(e);
    }
}

From source file:com.smartitengineering.loadtest.engine.impl.management.AbstracltTestCaseBatchCreator.java

private TestCaseCreationFactory getTestCaseCreationFactory(UnitTestInstance testInstance)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    final String instanceFactoryClassName = testInstance.getInstanceFactoryClassName();
    if (!StringUtils.isEmpty(instanceFactoryClassName)) {
        try {/*ww  w  .  ja v  a2  s .c om*/
            final Class<? extends TestCaseCreationFactory> classForName = (Class<? extends TestCaseCreationFactory>) Class
                    .forName(instanceFactoryClassName);
            try {
                Method method = classForName.getDeclaredMethod("getInstance");
                if (method != null && Modifier.isStatic(method.getModifiers())) {
                    return (TestCaseCreationFactory) method.invoke(classForName);
                }
            } catch (NoSuchMethodException exception) {
                exception.printStackTrace();
            }
            return classForName.newInstance();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    return DefaultTestCaseCreationFactory.getInstance();
}

From source file:org.apache.flink.api.java.Utils.java

private static String getGenericTypeTree(Class<?> type, int indent) {
    String ret = "";
    for (Field field : type.getDeclaredFields()) {
        if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
            continue;
        }/*from   w  ww .j av a 2  s.  c o m*/
        ret += StringUtils.repeat(' ', indent) + field.getName() + ":" + field.getType().getName()
                + (field.getType().isEnum() ? " (is enum)" : "") + "\n";
        if (!field.getType().isPrimitive()) {
            ret += getGenericTypeTree(field.getType(), indent + 4);
        }
    }
    return ret;
}