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

The following are Jave code examples for showing how to use toString() 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: OpenJSharp   File: ReflectionNavigator.java   View Source Code Vote up 5 votes
public Location getFieldLocation(final Field field) {
    return new Location() {

        @Override
        public String toString() {
            return field.toString();
        }
    };
}
 
Example 2
Project: openjdk-jdk10   File: ReflectionNavigator.java   View Source Code Vote up 5 votes
public Location getFieldLocation(final Field field) {
    return new Location() {

        @Override
        public String toString() {
            return field.toString();
        }
    };
}
 
Example 3
Project: vscrawler   File: AwkCompilerImpl.java   View Source Code Vote up 5 votes
private static boolean assertStaticClassVarsAreFromPackage() {
	//String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt");
	String packagename = "org.jawk.jrt";
	if (packagename != null) {
		// use reflection to get all static Class definitions
		// and verify that they are members of the
		// runtime package
		Class c = AwkCompilerImpl.class;
		// foreach field in declared in the class...
		for (Field f : c.getDeclaredFields()) {
			int mod = f.getModifiers();
			// if a "private static final" member...
			if (       (mod & Modifier.PRIVATE) > 0
					&& (mod & Modifier.STATIC) > 0
					&& (mod & Modifier.FINAL) > 0
					&& f.getType() == Class.class)
			{
				try {
					// obtain the value of the field
					// and apply it here!
					Object o = f.get(null);
					Class cls = (Class) o;
					if (!cls.getPackage().getName().equals(packagename)) {
						throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString());
					}
				} catch (IllegalAccessException iae) {
					throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it.
				}
			}
		}
	}
	// all's well
	return true;
}