Java Code Examples for com.sun.tools.classfile.ClassFile#getName()

The following examples show how to use com.sun.tools.classfile.ClassFile#getName() . 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: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 2
Source File: LambdaAsm.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 3
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 4
Source File: LambdaAsm.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 5
Source File: ClassReader.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 6
Source File: LambdaAsm.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 7
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        if (c.super_class != 0) {
            klass.setAttr("super", c.getSuperclassName());
        }
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 8
Source File: StripDebugPluginTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void checkDebugAttributes(byte[] strippedClassFile) throws IOException, ConstantPoolException {
    ClassFile classFile = ClassFile.read(new ByteArrayInputStream(strippedClassFile));
    String[] debugAttributes = new String[]{
            Attribute.LineNumberTable,
            Attribute.LocalVariableTable,
            Attribute.LocalVariableTypeTable
    };
    for (Method method : classFile.methods) {
        String methodName = method.getName(classFile.constant_pool);
        Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code);
        for (String attr : debugAttributes) {
            if (code.attributes.get(attr) != null) {
                throw new AssertionError("Debug attribute was not removed: " + attr +
                        " from method " + classFile.getName() + "#" + methodName);
            }
        }
    }
}
 
Example 9
Source File: LambdaAsm.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 10
Source File: LambdaAsm.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 11
Source File: LambdaAsm.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 12
Source File: LambdaAsm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 13
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 14
Source File: LambdaAsm.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 15
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 16
Source File: LambdaAsm.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 17
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 18
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void readClass(ClassFile c) throws IOException,
                                           ConstantPoolException,
                                           InvalidDescriptor {
    klass = new Element("Class");
    cfile.add(klass);
    String thisk = c.getName();

    klass.setAttr("name", thisk);

    AccessFlags af = new AccessFlags(c.access_flags.flags);
    klass.setAttr("flags", flagString(af, klass));
    if (!"java/lang/Object".equals(thisk)) {
        klass.setAttr("super", c.getSuperclassName());
    }
    for (int i : c.interfaces) {
        klass.add(new Element("Interface", "name", getCpString(i)));
    }
    readFields(c, klass);
    readMethods(c, klass);
    readAttributesFor(c, c.attributes, klass);
    klass.trimToSize();
}
 
Example 19
Source File: LambdaAsm.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in "
                + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool,
                            (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
 
Example 20
Source File: ClassFileReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Set<String> scan() {
    try {
        ClassFile cf = ClassFile.read(path);
        String name = cf.access_flags.is(AccessFlags.ACC_MODULE)
            ? "module-info" : cf.getName();
        return Collections.singleton(name);
    } catch (ConstantPoolException|IOException e) {
        throw new ClassFileError(e);
    }
}