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.cli.support.util.ReflectionUtils.java

/**
 * Determine whether the given field is a "public static final" constant.
 * //from  w ww  .  j  a v  a  2s  .co  m
 * @param field the field to check
 */
public static boolean isPublicStaticFinal(final Field field) {
    final int modifiers = field.getModifiers();
    return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
}

From source file:org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.java

/**
 * Get all the declared non-static fields of Class c.
 *///from w w w  .j  av a 2s  .com
public static Field[] getDeclaredNonStaticFields(Class<?> c) {
    Field[] f = c.getDeclaredFields();
    ArrayList<Field> af = new ArrayList<Field>();
    for (int i = 0; i < f.length; ++i) {
        if (!Modifier.isStatic(f[i].getModifiers())) {
            af.add(f[i]);
        }
    }
    Field[] r = new Field[af.size()];
    for (int i = 0; i < af.size(); ++i) {
        r[i] = af.get(i);
    }
    return r;
}

From source file:com.adaptris.core.runtime.AdapterRegistry.java

@Override
public String getClassDefinition(String className) throws CoreException {
    final ClassDescriptor classDescriptor = new ClassDescriptor(className);
    try {//from w  ww . ja v a2s  .  c  om
        Class<?> clazz = Class.forName(className);

        classDescriptor.setClassType(ClassDescriptor.ClassType.getTypeForClass(clazz).name().toLowerCase());

        List<String> displayOrder = new ArrayList<>();
        for (Annotation annotation : clazz.getAnnotations()) {
            if (XStreamAlias.class.isAssignableFrom(annotation.annotationType())) {
                classDescriptor.setAlias(((XStreamAlias) annotation).value());
            } else if (ComponentProfile.class.isAssignableFrom(annotation.annotationType())) {
                classDescriptor.setTags(((ComponentProfile) annotation).tag());
                classDescriptor.setSummary(((ComponentProfile) annotation).summary());
            } else if (DisplayOrder.class.isAssignableFrom(annotation.annotationType())) {
                displayOrder = Arrays.asList(((DisplayOrder) annotation).order());
            }
        }

        for (Field field : clazz.getDeclaredFields()) {
            if ((!Modifier.isStatic(field.getModifiers()))
                    && (field.getDeclaredAnnotation(Transient.class) == null)) { // if we're not transient
                ClassDescriptorProperty fieldProperty = new ClassDescriptorProperty();
                fieldProperty.setOrder(
                        displayOrder.contains(field.getName()) ? displayOrder.indexOf(field.getName()) + 1
                                : 999);
                fieldProperty.setAdvanced(false);
                fieldProperty.setClassName(field.getType().getName());
                fieldProperty.setType(field.getType().getSimpleName());
                fieldProperty.setName(field.getName());
                fieldProperty.setAutoPopulated(field.getDeclaredAnnotation(AutoPopulated.class) != null);
                fieldProperty.setNullAllowed(field.getDeclaredAnnotation(NotNull.class) != null);

                for (Annotation annotation : field.getDeclaredAnnotations()) {
                    if (AdvancedConfig.class.isAssignableFrom(annotation.annotationType())) {
                        fieldProperty.setAdvanced(true);
                    } else if (InputFieldDefault.class.isAssignableFrom(annotation.annotationType())) {
                        fieldProperty.setDefaultValue(((InputFieldDefault) annotation).value());
                    }
                }
                classDescriptor.getClassDescriptorProperties().add(fieldProperty);
            }
        }

        try (ScanResult result = new ClassGraph().enableAllInfo().blacklistPackages(FCS_BLACKLIST).scan()) {

            List<String> subclassNames = result.getSubclasses(className).getNames();

            for (String subclassName : subclassNames) {
                classDescriptor.getSubTypes().add(subclassName);
            }
        }

    } catch (ClassNotFoundException e) {
        throw new CoreException(e);
    }
    return new XStreamJsonMarshaller().marshal(classDescriptor);
}

From source file:com.android.camera2.its.ItsSerializer.java

@SuppressWarnings("unchecked")
public static JSONObject serialize(CameraMetadata md) throws ItsException {
    JSONObject jsonObj = new JSONObject();
    Field[] allFields = md.getClass().getDeclaredFields();
    if (md.getClass() == TotalCaptureResult.class) {
        allFields = CaptureResult.class.getDeclaredFields();
    }/*from w ww. j  a  v a 2s . c  om*/
    for (Field field : allFields) {
        if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())
                && (field.getType() == CaptureRequest.Key.class || field.getType() == CaptureResult.Key.class
                        || field.getType() == TotalCaptureResult.Key.class
                        || field.getType() == CameraCharacteristics.Key.class)
                && field.getGenericType() instanceof ParameterizedType) {
            ParameterizedType paramType = (ParameterizedType) field.getGenericType();
            Type[] argTypes = paramType.getActualTypeArguments();
            if (argTypes.length > 0) {
                try {
                    Type keyType = argTypes[0];
                    Object keyObj = field.get(md);
                    MetadataEntry entry;
                    if (keyType instanceof GenericArrayType) {
                        entry = serializeArrayEntry(keyType, keyObj, md);
                    } else {
                        entry = serializeEntry(keyType, keyObj, md);
                    }

                    // TODO: Figure this weird case out.
                    // There is a weird case where the entry is non-null but the toString
                    // of the entry is null, and if this happens, the null-ness spreads like
                    // a virus and makes the whole JSON object null from the top level down.
                    // Not sure if it's a bug in the library or I'm just not using it right.
                    // Workaround by checking for this case explicitly and not adding the
                    // value to the jsonObj when it is detected.
                    if (entry != null && entry.key != null && entry.value != null
                            && entry.value.toString() == null) {
                        Logt.w(TAG, "Error encountered serializing value for key: " + entry.key);
                    } else if (entry != null) {
                        jsonObj.put(entry.key, entry.value);
                    } else {
                        // Ignore.
                    }
                } catch (IllegalAccessException e) {
                    throw new ItsException("Access error for field: " + field + ": ", e);
                } catch (org.json.JSONException e) {
                    throw new ItsException("JSON error for field: " + field + ": ", e);
                }
            }
        }
    }
    return jsonObj;
}

From source file:com.github.abel533.mapperhelper.EntityHelper.java

/**
 * ?Field/*w  w  w .  ja v a 2  s  .  co m*/
 *
 * @param entityClass
 * @param fieldList
 * @return
 */
private static List<Field> getAllField(Class<?> entityClass, List<Field> fieldList) {
    if (fieldList == null) {
        fieldList = new ArrayList<Field>();
    }
    if (entityClass.equals(Object.class)) {
        return fieldList;
    }
    Field[] fields = entityClass.getDeclaredFields();
    for (Field field : fields) {
        //??bug#2
        if (!Modifier.isStatic(field.getModifiers())) {
            fieldList.add(field);
        }
    }
    Class<?> superClass = entityClass.getSuperclass();
    if (superClass != null && !superClass.equals(Object.class) && (superClass.isAnnotationPresent(Entity.class)
            || (!Map.class.isAssignableFrom(superClass) && !Collection.class.isAssignableFrom(superClass)))) {
        return getAllField(entityClass.getSuperclass(), fieldList);
    }
    return fieldList;
}

From source file:org.teavm.flavour.json.emit.ClassInformationProvider.java

private void scanFields(ClassInformation information, ReflectClass<?> cls) {
    for (ReflectField field : cls.getDeclaredFields()) {
        if (Modifier.isStatic(field.getModifiers())) {
            continue;
        }//w ww .  ja  v a2s  .c  o m
        if (hasExplicitPropertyDeclaration(field) || information.getterVisibility.match(field.getModifiers())) {
            addField(information, field.getName(), field);
        }
    }
}

From source file:adalid.core.EntityAtlas.java

private void finaliseFields() {
    String name;/*from  w  w  w. ja  v  a 2  s  .c o  m*/
    Class<?> type;
    int modifiers;
    boolean restricted;
    Object o;
    int depth = _declaringArtifact.depth();
    int round = _declaringArtifact.round();
    int index = _declaringArtifact.getStartWith();
    Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class,
            NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class };
    Class<?> dac = _declaringArtifact.getClass();
    Class<?> top = Entity.class;
    for (Class<?> c : classes) {
        for (Field field : XS1.getFields(dac, top)) {
            field.setAccessible(true);
            logger.trace(field);
            name = field.getName();
            type = field.getType();
            if (!c.isAssignableFrom(type)) {
                continue;
            }
            if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) {
                continue;
            }
            modifiers = field.getModifiers();
            restricted = Modifier.isPrivate(modifiers);
            if (restricted) {
                continue;
            }
            restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
            if (restricted) {
                continue;
            }
            String errmsg = "failed to initialize field \"" + field + "\" at " + _declaringArtifact;
            try {
                o = field.get(_declaringArtifact);
                if (o == null) {
                    logger.debug(message(type, name, o, depth, round));
                } else if (o instanceof Property) {
                    finaliseProperty(field, (Property) o);
                } else if (o instanceof Key) {
                    finaliseKey(field, (Key) o);
                } else if (o instanceof Tab) {
                    finaliseTab(field, (Tab) o);
                } else if (o instanceof View) {
                    finaliseView(field, (View) o);
                } else if (o instanceof Instance) {
                    finaliseInstance(field, (Instance) o, index++);
                } else if (o instanceof NamedValue) {
                    finaliseNamedValue(field, (NamedValue) o);
                } else if (o instanceof Expression) {
                    finaliseExpression(field, (Expression) o);
                } else if (o instanceof Transition) {
                    finaliseTransition(field, (Transition) o);
                } else if (o instanceof Operation) {
                    finaliseOperation(field, (Operation) o);
                } else if (o instanceof Trigger) {
                    finaliseTrigger(field, (Trigger) o);
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                logger.error(errmsg, ThrowableUtils.getCause(ex));
                TLC.getProject().getParser().increaseErrorCount();
            }
        }
    }
}

From source file:net.lightbody.bmp.proxy.jetty.xml.XmlConfiguration.java

private Object call(Object obj, XmlParser.Node node) throws NoSuchMethodException, ClassNotFoundException,
        InvocationTargetException, IllegalAccessException {
    String id = node.getAttribute("id");
    Class oClass = nodeClass(node);
    if (oClass != null)
        obj = null;/*from w  ww  .  j  a  v a2s . c  o  m*/
    else if (obj != null)
        oClass = obj.getClass();
    if (oClass == null)
        throw new IllegalArgumentException(node.toString());

    int size = 0;
    int argi = node.size();
    for (int i = 0; i < node.size(); i++) {
        Object o = node.get(i);
        if (o instanceof String)
            continue;
        if (!((XmlParser.Node) o).getTag().equals("Arg")) {
            argi = i;
            break;
        }
        size++;
    }

    Object[] arg = new Object[size];
    for (int i = 0, j = 0; j < size; i++) {
        Object o = node.get(i);
        if (o instanceof String)
            continue;
        arg[j++] = value(obj, (XmlParser.Node) o);
    }

    String method = node.getAttribute("name");
    if (log.isDebugEnabled())
        log.debug("call " + method);

    // Lets just try all methods for now
    Method[] methods = oClass.getMethods();
    for (int c = 0; methods != null && c < methods.length; c++) {
        if (!methods[c].getName().equals(method))
            continue;
        if (methods[c].getParameterTypes().length != size)
            continue;
        if (Modifier.isStatic(methods[c].getModifiers()) != (obj == null))
            continue;
        if ((obj == null) && methods[c].getDeclaringClass() != oClass)
            continue;

        Object n = null;
        boolean called = false;
        try {
            n = methods[c].invoke(obj, arg);
            called = true;
        } catch (IllegalAccessException e) {
            LogSupport.ignore(log, e);
        } catch (IllegalArgumentException e) {
            LogSupport.ignore(log, e);
        }
        if (called) {
            if (id != null)
                _idMap.put(id, n);
            configure(n, node, argi);
            return n;
        }
    }

    throw new IllegalStateException("No Method: " + node + " on " + oClass);
}

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

/**
 * Determine whether the method is declared public static
 * @param m//w ww  .ja  va  2 s.  c  o m
 * @return True if the method is declared public static
 */
public static boolean isPublicStatic(Method m) {
    final int modifiers = m.getModifiers();
    return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers);
}

From source file:de.codesourcery.eve.apiclient.parsers.HttpAPIClientTest.java

private static Method findParserMethod(String name, Class<?>... args) throws Exception {
    try {/*from  w  ww.  j  a  va 2 s  .  co  m*/
        return AbstractResponseParser.class.getDeclaredMethod(name, args);
    } catch (Exception e) {
        try {
            return AbstractResponseParser.class.getMethod(name, args);
        } catch (Exception e2) {

            for (Method m : AbstractResponseParser.class.getMethods()) {

                if (!m.getName().equals(name)) {
                    System.out.println("# Name mismatch: " + m);
                    continue;
                }

                if (!ObjectUtils.equals(m.getParameterTypes(), args)) {
                    System.out.println("# Param mismatch: " + m);
                    continue;
                }

                final int modifiers = m.getModifiers();

                if (Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers)
                        || Modifier.isFinal(modifiers)) {
                    System.out.println("# Modifier mismatch: " + m);
                    continue;
                }

                return m;
            }
            throw e2;
        }
    }
}