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:Main.java

public static List<Method> findAnnotatedMethods(final Class<?> type,
        final Class<? extends Annotation> annotation) {
    final List<Method> methods = new ArrayList<>();
    Method[] ms = type.getDeclaredMethods();
    for (Method method : ms) {
        // Must not static
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }/* ww w . j ava  2 s  .  c o m*/
        // Must be public
        if (Modifier.isPublic(method.getModifiers())) {
            continue;
        }
        // Must has only one parameter
        if (method.getParameterTypes().length != 1) {
            continue;
        }
        // Must has annotation
        if (!method.isAnnotationPresent(annotation)) {
            continue;
        }
        methods.add(method);
    }
    return methods;
}

From source file:Main.java

private static void init() {
    try {/* w  w  w  . j  av a 2  s  . c  om*/
        // read all com.android.internal.R
        Class clazz = Class.forName("com.android.internal.R$layout");
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            // public static final
            if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())
                    && Modifier.isFinal(field.getModifiers())) {
                try {
                    int id = field.getInt(null);
                    sSystemLayoutResIds.put(id, field.getName());
                } catch (IllegalAccessException e) {
                }
            }
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

/**
 * Only contains transient or static fields, which is the case for a model that is empty, but
 * says it "implements Parcelable"/*from   w w  w .j  a  v  a 2  s  . co m*/
 * @param fields the list of fields
 * @return true if contains only transient and static fields, false otherwise
 */
private static boolean containsOnlyTransientAndStaticFields(List<Field> fields) {
    boolean containsNormalField = false;
    for (Field field : fields) {
        if (!Modifier.isTransient(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
            containsNormalField = true;
        }
    }
    return !containsNormalField;
}

From source file:Main.java

public static String[] getClassStaticFieldNames(Class c, Type fieldType, String nameContains) {
    Field[] fields = c.getDeclaredFields();
    List<String> list = new ArrayList<>();
    for (Field field : fields) {
        try {// w ww.j  ava2 s  .  c om
            boolean isString = field.getType().equals(fieldType);
            boolean containsExtra = field.getName().contains(nameContains);
            boolean isStatic = Modifier.isStatic(field.getModifiers());
            if (field.getType().equals(String.class) && field.getName().contains("EXTRA_")
                    && Modifier.isStatic(field.getModifiers()))
                list.add(String.valueOf(field.get(null)));
        } catch (IllegalAccessException iae) {
            Log.d(TAG,
                    "!!!!!!!!!!!! class Static field, illegal access exception message: " + iae.getMessage());
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:Main.java

/**
 * @param context//w  ww .ja  v  a 2s.  c o  m
 * @param type
 * @param field
 * @param errResId
 * @param methodPrefix
 * @param methodParameters
 */
public static void checkIfMethodExists(Context context, Class<?> type, Field field, int errResId,
        String methodPrefix, Class<?>... methodParameters) {
    try {
        Method m = type.getDeclaredMethod(methodPrefix + getFirstLetterUppercased(field.getName()),
                methodParameters);

        if (!Modifier.isPublic(m.getModifiers()) || Modifier.isStatic(m.getModifiers()))
            throw new RuntimeException(context.getString(errResId, field.getName()));
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(context.getString(errResId, field.getName()));
    }
}

From source file:Main.java

public static String isLocalType(Class<?> type) {
    /* As per [JACKSON-187], GAE seems to throw SecurityExceptions
     * here and there... and GAE itself has a bug, too
     * (see []). Bah.//from w  w w .ja  v a2  s.c om
     */
    try {
        // one more: method locals, anonymous, are not good:
        if (type.getEnclosingMethod() != null) {
            return "local/anonymous";
        }

        /* But how about non-static inner classes? Can't construct
         * easily (theoretically, we could try to check if parent
         * happens to be enclosing... but that gets convoluted)
         */
        if (type.getEnclosingClass() != null) {
            if (!Modifier.isStatic(type.getModifiers())) {
                return "non-static member class";
            }
        }
    } catch (SecurityException e) {
    } catch (NullPointerException e) {
    }
    return null;
}

From source file:Main.java

public static boolean isStaticVariableField(Field field) {
    final int mod = field.getModifiers();
    return Modifier.isStatic(mod) && !Modifier.isFinal(mod);
}

From source file:Main.java

public static boolean isInstanceVariableField(Field field) {
    final int mod = field.getModifiers();
    return !Modifier.isStatic(mod) && !Modifier.isFinal(mod);
}

From source file:Main.java

public static String isLocalType(Class<?> type, boolean allowNonStatic) {
    /* As per [JACKSON-187], GAE seems to throw SecurityExceptions
     * here and there... and GAE itself has a bug, too
     * (see []). Bah. So we need to catch some wayward exceptions on GAE
     *///from w ww  .ja v  a2 s  .co  m
    try {
        // one more: method locals, anonymous, are not good:
        if (type.getEnclosingMethod() != null) {
            return "local/anonymous";
        }

        /* But how about non-static inner classes? Can't construct
         * easily (theoretically, we could try to check if parent
         * happens to be enclosing... but that gets convoluted)
         */
        if (!allowNonStatic) {
            if (type.getEnclosingClass() != null) {
                if (!Modifier.isStatic(type.getModifiers())) {
                    return "non-static member class";
                }
            }
        }
    } catch (SecurityException e) {
    } catch (NullPointerException e) {
    }
    return null;
}

From source file:Main.java

private static Method findMethod(final Class<?> beanType, final Type[] paramTypeHolder,
        final String methodName) {
    for (final Method m : beanType.getMethods()) {
        if (methodName.equals(m.getName()) && !Modifier.isStatic(m.getModifiers())) {
            final Type[] paramTypes = m.getGenericParameterTypes();
            if (paramTypes.length == 1) {
                paramTypeHolder[0] = paramTypes[0];
                return m;
            }/*from  ww  w.  jav a2 s  .  co m*/
        }
    }
    return null;
}