Java Code Examples for java.lang.reflect.Field.getModifiers()

The following are Jave code examples for showing how to use getModifiers() of the java.lang.reflect.Field class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: HTAPBench   File: Procedure.java   View Source Code Vote up 7 votes
protected static Map<String, SQLStmt> getStatments(Procedure proc) {
    Class<? extends Procedure> c = proc.getClass();
    Map<String, SQLStmt> stmts = new HashMap<String, SQLStmt>();
    for (Field f : c.getDeclaredFields()) {
        int modifiers = f.getModifiers();
        if (Modifier.isTransient(modifiers) == false &&
            Modifier.isPublic(modifiers) == true &&
            Modifier.isStatic(modifiers) == false) {
            try {
                Object o = f.get(proc);
                if (o instanceof SQLStmt) {
                    stmts.put(f.getName(), (SQLStmt)o);
                }
            } catch (Exception ex) {
                throw new RuntimeException("Failed to retrieve " + f + " from " + c.getSimpleName(), ex);
            }
        }
    } // FOR
    return (stmts);
}
 
Example 2
Project: thjson   File: POJOtoTHJSONConverter.java   View Source Code Vote up 6 votes
public void write(Object object) throws IllegalArgumentException, IllegalAccessException {

		alreadyWritten.clear();
		alreadyWritten.put(object, object);

		Class<?> clazz = object.getClass();
		while (clazz != Object.class) {
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				field.setAccessible(true);
				int modifiers = field.getModifiers();
				if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isVolatile(modifiers)) {
					// Skip
					continue;
				}
				if (field.isSynthetic()) {
					// Skip
					continue;
				}

				writeProperty(field.getName(), field.get(object));
			}

			clazz = clazz.getSuperclass();
		}
	}
 
Example 3
Project: easybinder   File: AutoBinder.java   View Source Code Vote up 6 votes
protected <T> void buildAndBind(Class<?> currentClazz, String path, List<Component> components,
		Set<Class<?>> nestedClasses) {
	List<Field> fields = getFieldsInDeclareOrder(currentClazz);

	for (Field field : fields) {
		if ((field.getModifiers() & Modifier.STATIC) != 0) {
			continue;
		}
		if (boundProperties.containsKey(path + field.getName())) {
			// property already bound, skip
			continue;
		}
		if (nestedClasses.contains(field.getType())) {
			buildAndBind(field.getType(), path + field.getName() + ".", components,
					nestedClasses);
		} else {
			components.add(createAndBind(field, path));
		}
	}
}
 
Example 4
Project: mpd-tools   File: DataTypeTest.java   View Source Code Vote up 6 votes
private void validate(Object object, Class<?> clazz) throws Exception {
    for (Field field : FieldUtils.getAllFields(clazz)) {
        int modifiers = field.getModifiers();

        // Ignore static fields
        if (Modifier.isStatic(modifiers)) {
            continue;
        }

        assertTrue("Field is private", Modifier.isPrivate(modifiers));
        assertTrue("Field is final", Modifier.isFinal(modifiers));

        Method getter = clazz.getMethod(getterName(field.getName()));
        assertNotNull("Getter exists", getter);
        assertTrue("Getter is public", Modifier.isPublic(getter.getModifiers()));
    }

    // Check that hashCode, toString and equals are defined
    assertNotNull(clazz.getDeclaredMethod("hashCode").invoke(object));
    assertNotNull(clazz.getDeclaredMethod("toString").invoke(object));
    assertTrue((Boolean) clazz.getDeclaredMethod("equals", Object.class).invoke(object, object));
}
 
Example 5
Project: atlas   File: Hack.java   View Source Code Vote up 6 votes
/** @param modifiers the modifiers this field must have */
HackedField(final Class<C> clazz, final String name, int modifiers) throws HackAssertionException {
	Field field = null;
	try {
		if (clazz == null) return;
		field = clazz.getDeclaredField(name);
		if (modifiers > 0 && (field.getModifiers() & modifiers) != modifiers)
			fail(new HackAssertionException(field + " does not match modifiers: " + modifiers));
		field.setAccessible(true);
	} catch (final NoSuchFieldException e) {
		HackAssertionException hae = new HackAssertionException(e);
		hae.setHackedClass(clazz);
		hae.setHackedFieldName(name);
		fail(hae);
	} finally { mField = field; }
}
 
Example 6
Project: weex-uikit   File: WXHack.java   View Source Code Vote up 6 votes
/**
 * @param modifiers the modifiers this field must have
 */
HackedField(final Class<C> clazz, final String name, int modifiers) throws HackAssertionException {
  Field field = null;
  try {
    if (clazz == null) {
      return;
    }
    field = clazz.getDeclaredField(name);
    if (modifiers > 0 && (field.getModifiers() & modifiers) != modifiers) {
      fail(new HackAssertionException(field + " does not match modifiers: " + modifiers));
    }
    field.setAccessible(true);
  } catch (final NoSuchFieldException e) {
    HackAssertionException hae = new HackAssertionException(e);
    hae.setHackedClass(clazz);
    hae.setHackedFieldName(name);
    fail(hae);
  } finally {
    mField = field;
  }
}
 
Example 7
Project: openjdk-jdk10   File: EventTool.java   View Source Code Vote up 6 votes
public ListenerSet() {
    eventTypes = new Vector<>();
    try {
        Class<?> eventClass = Class.forName("java.awt.AWTEvent");
        Field[] fields = eventClass.getFields();
        theWholeMask = 0;
        long eventMask;
        for (Field field : fields) {
            if ((field.getModifiers()
                    & (Modifier.PUBLIC | Modifier.STATIC)) != 0
                    && field.getType().equals(Long.TYPE)
                    && field.getName().endsWith("_EVENT_MASK")) {
                eventMask = (Long) field.get(null);
                eventTypes.add(new EventType(eventMask));
                theWholeMask = theWholeMask | eventMask;
            }
        }
    } catch (ClassNotFoundException | IllegalAccessException e) {
        JemmyProperties.getCurrentOutput().printStackTrace(e);
    }
}
 
Example 8
Project: jdk8u-jdk   File: ObjectStreamClass.java   View Source Code Vote up 5 votes
/**
 * Returns explicit serial version UID value declared by given class, or
 * null if none.
 */
private static Long getDeclaredSUID(Class<?> cl) {
    try {
        Field f = cl.getDeclaredField("serialVersionUID");
        int mask = Modifier.STATIC | Modifier.FINAL;
        if ((f.getModifiers() & mask) == mask) {
            f.setAccessible(true);
            return Long.valueOf(f.getLong(null));
        }
    } catch (Exception ex) {
    }
    return null;
}
 
Example 9
Project: hekate   File: ToString.java   View Source Code Vote up 5 votes
public ClassFormat(Class<?> type) {
    this.name = type.getSimpleName();

    int approxSize = 0;

    LinkedList<FieldFormat> fields = new LinkedList<>();

    do {
        Field[] declaredFields = type.getDeclaredFields();

        if (declaredFields.length > 0) {
            List<FieldFormat> typeFields = new ArrayList<>(declaredFields.length);

            for (Field field : declaredFields) {
                if (!field.isSynthetic()) {
                    int mod = field.getModifiers();

                    if (!Modifier.isStatic(mod) && field.getAnnotation(ToStringIgnore.class) == null) {
                        field.setAccessible(true);

                        typeFields.add(new FieldFormat(field));

                        // This is really approximate.
                        approxSize += field.getName().length() * 2;
                    }
                }
            }

            if (!typeFields.isEmpty()) {
                fields.addAll(0, typeFields);
            }
        }

        type = type.getSuperclass();
    }
    while (type != null && type != Object.class);

    this.fields = fields;
    this.approxSize = approxSize;
}
 
Example 10
Project: solo-spring   File: Reflections.java   View Source Code Vote up 5 votes
public static boolean matchInheritance(final Field subclassField, final Field superclassField) {
	if (Modifier.isStatic(superclassField.getModifiers()) || subclassField.equals(superclassField)) {
		return false;
	}

	final Package subclassPackage = superclassField.getDeclaringClass().getPackage();
	final Package superclassPackage = superclassField.getDeclaringClass().getPackage();
	final int superFieldModifiers = superclassField.getModifiers();

	return isAccessable(subclassPackage, superclassPackage, superFieldModifiers);
}
 
Example 11
Project: BUbiNG   File: StartupConfiguration.java   View Source Code Vote up 5 votes
@Override
public String toString() {
	final Class<?> thisClass = getClass();
	final Map<String,Object> values = new Object2ObjectOpenHashMap<>();
	for (final Field f : thisClass.getDeclaredFields()) {
		if ((f.getModifiers() & Modifier.PUBLIC) == 0 || (f.getModifiers() & Modifier.STATIC) != 0) continue;
		try {
			values.put(f.getName(), f.get(this));
		} catch (final IllegalAccessException e) {
			values.put(f.getName(), "<THIS SHOULD NOT HAPPEN>");
		}
	}
	return values.toString();
}
 
Example 12
Project: Recaf   File: Config.java   View Source Code Vote up 5 votes
/**
 * Save current settings to configuration.
 */
public void save() {
	try {
		if (!confFile.exists() && !confFile.createNewFile()) {
			// Return if config file cannot be found and cannot be created.
			return;
		}
		JsonObject json = Json.object();
		for (Field field : this.getClass().getDeclaredFields()) {
			// Skip private and static fields.
			int mod = field.getModifiers();
			if (Modifier.isPrivate(mod) || Modifier.isStatic(mod)) {
				continue;
			}
			// Access via reflection, add value to json object.
			field.setAccessible(true);
			String name = field.getName();
			Object value = field.get(this);
			if (value instanceof Boolean) {
				json.set(name, (boolean) value);
			} else if (value instanceof Integer) {
				json.set(name, (int) value);
			} else if (value instanceof String) {
				json.set(name, (String) value);
			} else {
				JsonValue converted = convert(field.getType(), value);
				if (converted != null) {
					json.set(name, converted);
				}
			}
		}
		// Write json to file
		StringWriter w = new StringWriter();
		json.writeTo(w, WriterConfig.PRETTY_PRINT);
		Files.writeFile(confFile.getAbsolutePath(), w.toString());
	} catch (Exception e) {
		Recaf.INSTANCE.logging.error(e);
	}
}
 
Example 13
Project: OpenJSharp   File: AtomicLongFieldUpdater.java   View Source Code Vote up 5 votes
CASUpdater(final Class<T> tclass, final String fieldName,
           final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
          sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    Class<?> fieldt = field.getType();
    if (fieldt != long.class)
        throw new IllegalArgumentException("Must be long type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    this.cclass = (Modifier.isProtected(modifiers) &&
                   caller != tclass) ? caller : null;
    this.tclass = tclass;
    offset = unsafe.objectFieldOffset(field);
}
 
Example 14
Project: OpenJSharp   File: ObjectStreamClass.java   View Source Code Vote up 5 votes
/**
 * Returns explicit serial version UID value declared by given class, or
 * null if none.
 */
private static Long getDeclaredSUID(Class<?> cl) {
    try {
        Field f = cl.getDeclaredField("serialVersionUID");
        int mask = Modifier.STATIC | Modifier.FINAL;
        if ((f.getModifiers() & mask) == mask) {
            f.setAccessible(true);
            return Long.valueOf(f.getLong(null));
        }
    } catch (Exception ex) {
    }
    return null;
}
 
Example 15
Project: openjdk-jdk10   File: AtomicReferenceFieldUpdater.java   View Source Code Vote up 4 votes
AtomicReferenceFieldUpdaterImpl(final Class<T> tclass,
                                final Class<V> vclass,
                                final String fieldName,
                                final Class<?> caller) {
    final Field field;
    final Class<?> fieldClass;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
        fieldClass = field.getType();
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (vclass != fieldClass)
        throw new ClassCastException();
    if (vclass.isPrimitive())
        throw new IllegalArgumentException("Must be reference type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.vclass = vclass;
    this.offset = U.objectFieldOffset(field);
}
 
Example 16
Project: openjdk-jdk10   File: ObjectStreamClassUtil_1_3.java   View Source Code Vote up 4 votes
public static long computeStructuralUID(boolean hasWriteObject, Class<?> cl) {
    ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);

    long h = 0;
    try {

        if ((!java.io.Serializable.class.isAssignableFrom(cl)) ||
            (cl.isInterface())){
            return 0;
        }

        if (java.io.Externalizable.class.isAssignableFrom(cl)) {
            return 1;
        }

        MessageDigest md = MessageDigest.getInstance("SHA");
        DigestOutputStream mdo = new DigestOutputStream(devnull, md);
        DataOutputStream data = new DataOutputStream(mdo);

        //In the old case, for the caller class, the write Method wasn't considered
        // for rep-id calculations correctly, but for parent classes it was taken
        // into account.  That is the reason there is the klude of getting the write
        // Object method in there

        // Get SUID of parent
        Class<?> parent = cl.getSuperclass();
        if ((parent != null) && (parent != java.lang.Object.class)) {
            boolean hasWriteObjectFlag = false;
            Class [] args = {java.io.ObjectOutputStream.class};
            Method hasWriteObjectMethod = ObjectStreamClassUtil_1_3.getDeclaredMethod(parent, "writeObject", args,
                   Modifier.PRIVATE, Modifier.STATIC);
            if (hasWriteObjectMethod != null)
                hasWriteObjectFlag = true;
            data.writeLong(ObjectStreamClassUtil_1_3.computeStructuralUID(hasWriteObjectFlag, parent));
        }

        if (hasWriteObject)
            data.writeInt(2);
        else
            data.writeInt(1);

        /* Sort the field names to get a deterministic order */
        Field[] field = ObjectStreamClassUtil_1_3.getDeclaredFields(cl);
        Arrays.sort(field, compareMemberByName);

        for (int i = 0; i < field.length; i++) {
            Field f = field[i];

                            /* Include in the hash all fields except those that are
                             * transient or static.
                             */
            int m = f.getModifiers();
            if (Modifier.isTransient(m) || Modifier.isStatic(m))
                continue;

            data.writeUTF(f.getName());
            data.writeUTF(getSignature(f.getType()));
        }

        /* Compute the hash value for this class.
         * Use only the first 64 bits of the hash.
         */
        data.flush();
        byte hasharray[] = md.digest();
        int minimum = Math.min(8, hasharray.length);
        for (int i = minimum; i > 0; i--) {
            h += (long)(hasharray[i] & 255) << (i * 8);
        }
    } catch (IOException ignore) {
        /* can't happen, but be deterministic anyway. */
        h = -1;
    } catch (NoSuchAlgorithmException complain) {
        throw new SecurityException(complain.getMessage());
    }
    return h;
}
 
Example 17
Project: openjdk-jdk10   File: AtomicIntegerFieldUpdater.java   View Source Code Vote up 4 votes
AtomicIntegerFieldUpdaterImpl(final Class<T> tclass,
                              final String fieldName,
                              final Class<?> caller) {
    final Field field;
    final int modifiers;
    try {
        field = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    return tclass.getDeclaredField(fieldName);
                }
            });
        modifiers = field.getModifiers();
        sun.reflect.misc.ReflectUtil.ensureMemberAccess(
            caller, tclass, null, modifiers);
        ClassLoader cl = tclass.getClassLoader();
        ClassLoader ccl = caller.getClassLoader();
        if ((ccl != null) && (ccl != cl) &&
            ((cl == null) || !isAncestor(cl, ccl))) {
            sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
        }
    } catch (PrivilegedActionException pae) {
        throw new RuntimeException(pae.getException());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    if (field.getType() != int.class)
        throw new IllegalArgumentException("Must be integer type");

    if (!Modifier.isVolatile(modifiers))
        throw new IllegalArgumentException("Must be volatile type");

    // Access to protected field members is restricted to receivers only
    // of the accessing class, or one of its subclasses, and the
    // accessing class must in turn be a subclass (or package sibling)
    // of the protected member's defining class.
    // If the updater refers to a protected field of a declaring class
    // outside the current package, the receiver argument will be
    // narrowed to the type of the accessing class.
    this.cclass = (Modifier.isProtected(modifiers) &&
                   tclass.isAssignableFrom(caller) &&
                   !isSamePackage(tclass, caller))
                  ? caller : tclass;
    this.tclass = tclass;
    this.offset = U.objectFieldOffset(field);
}
 
Example 18
Project: CodeBroker   File: FileLoad.java   View Source Code Vote up 4 votes
public static void findClazz() {
	ClassScanner cs = new ClassScanner() {
		@Override
		protected void onEntry(EntryData entryData)
				throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
			if (entryData.getName().endsWith("PBSystem.java")) {
				return;
			}
			System.out.println(
					"---> " + entryData.getName() + ':' + entryData.getArchiveName() + "\t\t" );
			Class loadClass = ClassLoaderUtil.loadClass(
					entryData.getName().replaceAll("\\/", ".").substring(1, entryData.getName().length() - 5));
			Class[] subclasss = loadClass.getClasses();
			for (Class string : subclasss) {
				// 找到消息实体类
				if (com.google.protobuf.GeneratedMessage.class.isAssignableFrom(string)) {
					message.put(string.getSimpleName(), string);
					classNames.add(string.getSimpleName()); 
				}
				// Builder
				else if (com.google.protobuf.MessageOrBuilder.class.isAssignableFrom(string)) {
					messageBuilder.put(string.getSimpleName(), string);
				}
				Class[] innerSubClass = string.getClasses();
				for (Class clazz : innerSubClass) {
					// 取得枚举类
					if (clazz.isEnum()) {
						Object[] enumConstants = clazz.getEnumConstants();
						for (Object string3 : enumConstants) {
							Field[] accessibleFields = ClassUtil.getAccessibleFields(string3.getClass());
							for (Field string4 : accessibleFields) {
								if (string4.getModifiers() == (java.lang.reflect.Modifier.PUBLIC
										+ java.lang.reflect.Modifier.STATIC + java.lang.reflect.Modifier.FINAL)) {
									messageKey.put(string4.getName(),string4.getDeclaringClass().getName().replaceAll("\\$", ".") + "."
													+ string4.getName());
								}
							}
						}
					}
				}
			}
		}
	};
	cs.setIncludeResources(true);
	cs.scan("./src-gen");
}
 
Example 19
Project: DeskChan   File: HackJavaFX.java   View Source Code Vote up 4 votes
private static Object createObjectProxy(Object realObject, Class realClass, ObjectProxyMethodHook hook) throws Throwable {
	ClassPool pool = ClassPool.getDefault();
	CtClass cc = pool.makeClass(HackJavaFX.class.getPackage().getName() + "." +
			realClass.getSimpleName() + "_Proxy");
	cc.setSuperclass(pool.get(realClass.getName()));
	CtField realObjectField = new CtField(cc.getSuperclass(), "realObject", cc);
	realObjectField.setModifiers(Modifier.FINAL | Modifier.PRIVATE);
	cc.addField(realObjectField);
	CtField realClassField = new CtField(pool.get("java.lang.Class"), "realClass", cc);
	realClassField.setModifiers(Modifier.FINAL | Modifier.PRIVATE);
	cc.addField(realClassField);
	CtConstructor constructor = new CtConstructor(
			new CtClass[]{realObjectField.getType(), realClassField.getType()}, cc
	);
	constructor.setModifiers(Modifier.PUBLIC);
	constructor.setBody("{ realObject = $1; realClass = $2; }");
	cc.addConstructor(constructor);
	for (CtMethod method : cc.getSuperclass().getDeclaredMethods()) {
		if ((method.getModifiers() & Modifier.FINAL) != 0) {
			continue;
		}
		if ((method.getModifiers() & Modifier.STATIC) != 0) {
			continue;
		}
		CtMethod newMethod = new CtMethod(method.getReturnType(), method.getName(),
				method.getParameterTypes(), cc);
		newMethod.setModifiers(method.getModifiers() & ~(Modifier.NATIVE | Modifier.SYNCHRONIZED));
		newMethod.setExceptionTypes(method.getExceptionTypes());
		if (newMethod.getReturnType().equals(CtClass.voidType)) {
			if ((newMethod.getModifiers() & Modifier.PUBLIC) != 0) {
				newMethod.setBody("realObject." + method.getName() + "($$);");
			} else {
				newMethod.setBody("{ java.lang.reflect.Method method = realClass.getDeclaredMethod(\""
						+ method.getName() + "\", $sig);" + "method.setAccessible(true);"
						+ "method.invoke(this.realObject, $args); }");
			}
		} else {
			if ((newMethod.getModifiers() & Modifier.PUBLIC) != 0) {
				newMethod.setBody("return realObject." + method.getName() + "($$);");
			} else {
				newMethod.setBody("{ java.lang.reflect.Method method = realClass.getDeclaredMethod(\""
						+ method.getName() + "\", $sig);" + "method.setAccessible(true);"
						+ "java.lang.Object retVal = method.invoke(realObject, $args);"
						+ "return ($r) retVal; }");
			}
		}
		if (hook != null) {
			hook.processMethod(newMethod);
		}
		cc.addMethod(newMethod);
	}
	Class cls = cc.toClass();
	Constructor c = cls.getDeclaredConstructor(cls.getSuperclass(), Class.class);
	Object proxy = c.newInstance(realObject, realClass);
	for (Field field : realClass.getDeclaredFields()) {
		if ((field.getModifiers() & Modifier.STATIC) != 0) {
			continue;
		}
		if ((field.getModifiers() & Modifier.FINAL) != 0) {
			continue;
		}
		field.setAccessible(true);
		field.set(proxy, field.get(realObject));
	}
	return proxy;
}
 
Example 20
Project: OperatieBRP   File: Entiteit.java   View Source Code Vote up 2 votes
/**
 * Controleert of het meegegeven veld een constante is in een class.
 *
 * @param field het veld wat gecontroleerd moet worden
 * @return true als het veld een constante (static final) is.
 */
static boolean isFieldConstant(final Field field) {
    final int modifiers = field.getModifiers();
    return Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
}