List of usage examples for java.lang.reflect Field getModifiers
public int getModifiers()
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 boolean isStaticVariableField(Field field) { final int mod = field.getModifiers(); return Modifier.isStatic(mod) && !Modifier.isFinal(mod); }
From source file:ReflectionUtils.java
/** * Determine whether the given field is a "public static final" constant. * @param field the field to check/*from ww w . j a v a 2 s . c o m*/ */ public static boolean isPublicStaticFinal(Field field) { int modifiers = field.getModifiers(); return (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)); }
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"/* w w w. ja v a 2 s . c om*/ * @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 void setField(Field field, Object target, Object value) { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true);//from w w w. j a va 2s . c o m } try { field.set(target, value); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("Could not set field " + field, iae); } }
From source file:Main.java
public static Object getField(Field field, Object target) { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true);/*from w w w .j a va 2 s . c o m*/ } try { return field.get(target); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("Could not get field " + field, iae); } }
From source file:ReflectionUtils.java
/** * Make the given field accessible, explicitly setting it accessible if necessary. * The <code>setAccessible(true)</code> method is only called when actually necessary, * to avoid unnecessary conflicts with a JVM SecurityManager (if active). * @param field the field to make accessible * @see java.lang.reflect.Field#setAccessible */// w w w. ja va 2s . co m public static void makeAccessible(Field field) { if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) { field.setAccessible(true); } }
From source file:ShowClass.java
public static void printField(Field f) { System.out.println(" " + modifiers(f.getModifiers()) + typeName(f.getType()) + " " + f.getName() + ";"); }
From source file:Main.java
public static void print_field(Field f) { System.out.println(" " + modifiers(f.getModifiers()) + typename(f.getType()) + " " + f.getName() + ";"); }
From source file:ReflectUtils.java
/** * Adds all static Fields (from Class.getFields) to the list * @param aClass//ww w . j a v a 2s . c o m * @param list * @return number of fields added */ public static int addStaticFields(Class aClass, List<Member> list) { Field[] fields = aClass.getFields(); for (Field f : fields) { if (Modifier.isStatic(f.getModifiers())) { list.add(f); } } return fields.length; }