Java Code Examples for java.lang.Class#getField()

The following examples show how to use java.lang.Class#getField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Inheritance1.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 2
Source File: Inheritance1.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 3
Source File: DefaultValue.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 4
Source File: Inheritance1.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 5
Source File: DefaultValue.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 6
Source File: Inheritance1.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 7
Source File: DefaultValue.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 8
Source File: Inheritance1.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 9
Source File: DefaultValue.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 10
Source File: DefaultValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 11
Source File: DefaultValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 12
Source File: Inheritance1.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 13
Source File: DefaultValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 14
Source File: Inheritance1.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 15
Source File: DefaultValue.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 16
Source File: Inheritance1.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
    Field f1 = klass.getField(field1);
    Field f2 = klass.getField(field2);

    int diff = offset(f1) - offset(f2);
    if (diff < 0) {
        // f1 is first
        return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
    } else {
        // f2 is first
        return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
    }
}
 
Example 17
Source File: AnnotationProxyMaker.java    From Mindustry with GNU General Public License v3.0 4 votes vote down vote up
private Map<MethodSymbol, Attribute> getAllValues(){
    LinkedHashMap map = new LinkedHashMap();
    ClassSymbol cl = (ClassSymbol)this.anno.type.tsym;

    //try to use Java 8 API for this if possible
    try{
        Class entryClass = Class.forName("com.sun.tools.javac.code.Scope$Entry");
        Object members = cl.members();
        Field field = members.getClass().getField("elems");
        Object elems = field.get(members);
        Field siblingField = entryClass.getField("sibling");
        Field symField = entryClass.getField("sym");
        for(Object currEntry = elems; currEntry != null; currEntry = siblingField.get(currEntry)){
            handleSymbol((Symbol)symField.get(currEntry), map);
        }

    }catch(Throwable e){
        //otherwise try other API

        try{
            Class lookupClass = Class.forName("com.sun.tools.javac.code.Scope$LookupKind");
            Field nonRecField = lookupClass.getField("NON_RECURSIVE");
            Object nonRec = nonRecField.get(null);
            Scope scope = cl.members();
            Method getSyms = scope.getClass().getMethod("getSymbols", lookupClass);
            Iterable<Symbol> it = (Iterable<Symbol>)getSyms.invoke(scope, nonRec);
            Iterator<Symbol> i = it.iterator();
            while(i.hasNext()){
                handleSymbol(i.next(), map);
            }

        }catch(Throwable death){
            //I tried
            throw new RuntimeException(death);
        }
    }

    for(Pair var7 : this.anno.values){
        map.put(var7.fst, var7.snd);
    }

    return map;
}