com.sun.tools.classfile.Field Java Examples

The following examples show how to use com.sun.tools.classfile.Field. 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: Driver.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void testFields(Map<String, ExpectedSignature> expectedSignatures, ClassFile classFile)
        throws ConstantPoolException {
    String className = classFile.getName();
    Set<String> foundFields = new HashSet<>();
    for (Field field : classFile.fields) {
        String fieldName = field.getName(classFile.constant_pool);
        printf("Testing field %s\n", fieldName);
        testAttribute(
                fieldName,
                classFile,
                () -> (Signature_attribute) field.attributes.get(Attribute.Signature),
                expectedSignatures.get(fieldName));
        foundFields.add(fieldName);
    }
    checkAllMembersFound(foundFields, expectedSignatures,
            "Checking that all fields of class " + className + " with Signature attribute found");
}
 
Example #2
Source File: ClassWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
String getFieldName(Field f) {
    try {
        return f.getName(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #3
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #4
Source File: ReferenceInfoUtil.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, Field m, String name, List<TypeAnnotation> annos) {
    int index = m.attributes.getIndex(cf.constant_pool, name);
    if (index != -1) {
        Attribute attr = m.attributes.get(index);
        assert attr instanceof RuntimeTypeAnnotations_attribute;
        RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
        annos.addAll(Arrays.asList(tAttr.annotations));
    }
}
 
Example #5
Source File: ClassReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #6
Source File: DetectMutableStaticFields.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #7
Source File: ClassWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
String getFieldName(Field f) {
    try {
        return f.getName(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #8
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #9
Source File: ReferenceInfoUtil.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, List<TypeAnnotation> annos) {
    findAnnotations(cf, Attribute.RuntimeVisibleTypeAnnotations, annos);
    findAnnotations(cf, Attribute.RuntimeInvisibleTypeAnnotations, annos);

    for (Field f : cf.fields) {
        findAnnotations(cf, f, annos);
    }
    for (Method m: cf.methods) {
        findAnnotations(cf, m, annos);
    }
}
 
Example #10
Source File: DetectMutableStaticFields.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #11
Source File: ReferenceInfoUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, List<TypeAnnotation> annos) {
    findAnnotations(cf, Attribute.RuntimeVisibleTypeAnnotations, annos);
    findAnnotations(cf, Attribute.RuntimeInvisibleTypeAnnotations, annos);

    for (Field f : cf.fields) {
        findAnnotations(cf, f, annos);
    }
    for (Method m: cf.methods) {
        findAnnotations(cf, m, annos);
    }
}
 
Example #12
Source File: ReferenceInfoUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, Field m, String name, List<TypeAnnotation> annos) {
    int index = m.attributes.getIndex(cf.constant_pool, name);
    if (index != -1) {
        Attribute attr = m.attributes.get(index);
        assert attr instanceof RuntimeTypeAnnotations_attribute;
        RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
        annos.addAll(Arrays.asList(tAttr.annotations));
    }
}
 
Example #13
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #14
Source File: ClassReader.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #15
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #16
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #17
Source File: ReferenceInfoUtil.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, Field m, String name, List<TypeAnnotation> annos) {
    int index = m.attributes.getIndex(cf.constant_pool, name);
    if (index != -1) {
        Attribute attr = m.attributes.get(index);
        assert attr instanceof RuntimeTypeAnnotations_attribute;
        RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
        annos.addAll(Arrays.asList(tAttr.annotations));
    }
}
 
Example #18
Source File: ReferenceInfoUtil.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, List<TypeAnnotation> annos) {
    findAnnotations(cf, Attribute.RuntimeVisibleTypeAnnotations, annos);
    findAnnotations(cf, Attribute.RuntimeInvisibleTypeAnnotations, annos);

    for (Field f : cf.fields) {
        findAnnotations(cf, f, annos);
    }
    for (Method m: cf.methods) {
        findAnnotations(cf, m, annos);
    }
}
 
Example #19
Source File: DetectMutableStaticFields.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #20
Source File: ClassWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
String getFieldName(Field f) {
    try {
        return f.getName(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #21
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #22
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #23
Source File: StringSharingPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void scanFields(Set<Integer> utf8Descriptors)
        throws Exception {
    for (Field field : cf.fields) {
        int descriptorIndex = field.descriptor.index;
        utf8Descriptors.add(descriptorIndex);
        scanAttributes(field.attributes, utf8Descriptors);
    }

}
 
Example #24
Source File: ReferenceInfoUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, Field m, String name, List<TypeAnnotation> annos) {
    int index = m.attributes.getIndex(cf.constant_pool, name);
    if (index != -1) {
        Attribute attr = m.attributes.get(index);
        assert attr instanceof RuntimeTypeAnnotations_attribute;
        RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
        annos.addAll(Arrays.asList(tAttr.annotations));
    }
}
 
Example #25
Source File: ReferenceInfoUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, List<TypeAnnotation> annos) {
    findAnnotations(cf, Attribute.RuntimeVisibleTypeAnnotations, annos);
    findAnnotations(cf, Attribute.RuntimeInvisibleTypeAnnotations, annos);

    for (Field f : cf.fields) {
        findAnnotations(cf, f, annos);
    }
    for (Method m: cf.methods) {
        findAnnotations(cf, m, annos);
    }
}
 
Example #26
Source File: DetectMutableStaticFields.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void analyzeClassFile(ClassFile classFileToCheck)
    throws
        IOException,
        ConstantPoolException,
        Descriptor.InvalidDescriptor {
    boolean enumClass =
            (classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
    boolean nonFinalStaticEnumField;
    boolean nonFinalStaticField;

    currentFieldsToIgnore =
            classFieldsToIgnoreMap.get(classFileToCheck.getName());

    for (Field field : classFileToCheck.fields) {
        if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
            continue;
        }
        nonFinalStaticEnumField =
                (field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
        nonFinalStaticField =
                (field.access_flags.flags & ACC_STATIC) != 0 &&
                (field.access_flags.flags & ACC_FINAL) == 0;
        if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
            errors.add("There is a mutable field named " +
                    field.getName(classFileToCheck.constant_pool) +
                    ", at class " +
                    classFileToCheck.getName());
        }
    }
}
 
Example #27
Source File: DeprecatedTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void testFields(ClassFile cf) throws ConstantPoolException {
    for (Field f : cf.fields) {
        String fieldName = cf.constant_pool.getUTF8Value(f.name_index);
        echo("Testing field : " + fieldName);
        Deprecated_attribute attr = (Deprecated_attribute)
                f.attributes.get(Attribute.Deprecated);
        testAttribute(fieldName, attr, cf);
    }
}
 
Example #28
Source File: ClassWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
String getFieldName(Field f) {
    try {
        return f.getName(constant_pool);
    } catch (ConstantPoolException e) {
        return report(e);
    }
}
 
Example #29
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private AccessFlags.Kind getKind(Element e) {
    switch(e.getName()) {
        case "Class":
            return AccessFlags.Kind.Class;
        case "InnerClass":
            return AccessFlags.Kind.InnerClass;
        case "Field":
            return AccessFlags.Kind.Field ;
        case "Method":
            return AccessFlags.Kind.Method;
        default: throw new RuntimeException("should not reach here");
    }
}
 
Example #30
Source File: ReferenceInfoUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void findAnnotations(ClassFile cf, Field m, String name, List<TypeAnnotation> annos) {
    int index = m.attributes.getIndex(cf.constant_pool, name);
    if (index != -1) {
        Attribute attr = m.attributes.get(index);
        assert attr instanceof RuntimeTypeAnnotations_attribute;
        RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
        annos.addAll(Arrays.asList(tAttr.annotations));
    }
}