Java Code Examples for com.sun.tools.classfile.Field

The following examples show how to use com.sun.tools.classfile.Field. These examples are extracted from open source projects. 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Driver.java    License: 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 Project: dragonwell8_jdk   Author: alibaba   File: ClassReader.java    License: 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 #3
Source Project: TencentKona-8   Author: Tencent   File: ClassWriter.java    License: 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 #4
Source Project: TencentKona-8   Author: Tencent   File: DetectMutableStaticFields.java    License: 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 #5
Source Project: TencentKona-8   Author: Tencent   File: ReferenceInfoUtil.java    License: 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 #6
Source Project: TencentKona-8   Author: Tencent   File: ReferenceInfoUtil.java    License: 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 #7
Source Project: TencentKona-8   Author: Tencent   File: ClassReader.java    License: 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 #8
Source Project: jdk8u60   Author: chenghanpeng   File: ClassWriter.java    License: 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 #9
Source Project: jdk8u60   Author: chenghanpeng   File: DetectMutableStaticFields.java    License: 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 #10
Source Project: jdk8u60   Author: chenghanpeng   File: ReferenceInfoUtil.java    License: 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 #11
Source Project: jdk8u60   Author: chenghanpeng   File: ReferenceInfoUtil.java    License: 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 #12
Source Project: jdk8u60   Author: chenghanpeng   File: ClassReader.java    License: 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 #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ClassWriter.java    License: 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 #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DetectMutableStaticFields.java    License: 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 #15
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #17
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ClassReader.java    License: 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 #18
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ClassWriter.java    License: 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 #19
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DetectMutableStaticFields.java    License: 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #21
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #22
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ClassReader.java    License: 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ClassWriter.java    License: 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 #24
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DeprecatedTest.java    License: 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 #25
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DetectMutableStaticFields.java    License: 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 #26
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #27
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ReferenceInfoUtil.java    License: 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 #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StringSharingPlugin.java    License: 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 #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ClassReader.java    License: 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 Project: jdk8u-jdk   Author: lambdalab-mirror   File: ClassReader.java    License: 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");
    }
}