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

The following examples show how to use com.sun.tools.classfile.AccessFlags. 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: jdk8u-dev-jdk   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 2
Source Project: TencentKona-8   Source File: Options.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks access of class, field or method.
 */
public boolean checkAccess(AccessFlags flags){

    boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
    boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
    boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
    boolean isPackage = !(isPublic || isProtected || isPrivate);

    if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
        return false;
    else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
        return false;
    else if ((showAccess == 0) && (isPrivate))
        return false;
    else
        return true;
}
 
Example 3
Source Project: openjdk-8   Source File: CompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 4
Source Project: TencentKona-8   Source File: ClassReader.java    License: 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 5
Source Project: hottub   Source File: CompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 6
Source Project: TencentKona-8   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 7
Source Project: hottub   Source File: Options.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks access of class, field or method.
 */
public boolean checkAccess(AccessFlags flags){

    boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
    boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
    boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
    boolean isPackage = !(isPublic || isProtected || isPrivate);

    if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
        return false;
    else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
        return false;
    else if ((showAccess == 0) && (isPrivate))
        return false;
    else
        return true;
}
 
Example 8
Source Project: jdk8u60   Source File: Options.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks access of class, field or method.
 */
public boolean checkAccess(AccessFlags flags){

    boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
    boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
    boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
    boolean isPackage = !(isPublic || isProtected || isPrivate);

    if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
        return false;
    else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
        return false;
    else if ((showAccess == 0) && (isPrivate))
        return false;
    else
        return true;
}
 
Example 9
Source Project: jdk8u60   Source File: FindNativeFiles.java    License: GNU General Public License v2.0 6 votes vote down vote up
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    in.close();
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 10
Source Project: openjdk-8-source   Source File: Options.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks access of class, field or method.
 */
public boolean checkAccess(AccessFlags flags){

    boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
    boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
    boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
    boolean isPackage = !(isPublic || isProtected || isPrivate);

    if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
        return false;
    else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
        return false;
    else if ((showAccess == 0) && (isPrivate))
        return false;
    else
        return true;
}
 
Example 11
Source Project: jdk8u-jdk   Source File: ClassReader.java    License: 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 12
Source Project: jdk8u60   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 13
Source Project: openjdk-jdk8u   Source File: Options.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks access of class, field or method.
 */
public boolean checkAccess(AccessFlags flags){

    boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
    boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
    boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
    boolean isPackage = !(isPublic || isProtected || isPrivate);

    if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
        return false;
    else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
        return false;
    else if ((showAccess == 0) && (isPrivate))
        return false;
    else
        return true;
}
 
Example 14
Source Project: openjdk-jdk8u   Source File: CompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 15
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    in.close();
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 16
Source Project: jdk8u-jdk   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 17
Source Project: jdk8u-jdk   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 18
Source Project: jdk8u_jdk   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 19
Source Project: openjdk-8-source   Source File: ClassReader.java    License: 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 20
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
    String name = entry.getName();
    if (name.startsWith("META-INF") || !name.endsWith(".class"))
        return false;
    //String className = name.substring(0, name.length() - 6).replace("/", ".");
    //System.err.println("check " + className);
    InputStream in = jar.getInputStream(entry);
    ClassFile cf = ClassFile.read(in);
    in.close();
    for (int i = 0; i < cf.methods.length; i++) {
        Method m = cf.methods[i];
        if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
            // System.err.println(className);
            return true;
        }
    }
    return false;
}
 
Example 21
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 22
Source Project: jdk8u_jdk   Source File: ClassReader.java    License: 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 23
Source Project: openjdk-jdk9   Source File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String flagString(AccessFlags af, String kind) {
    Set<String> mods = null;
    switch (kind) {
        case "Class":
            mods = af.getClassFlags();
            break;
        case "InnerClass":
            mods = af.getInnerClassFlags();
            break;
        case "Field":
            mods = af.getFieldFlags();
            break;
        case "Method":
            mods = af.getMethodFlags();
            break;
        default:
            throw new RuntimeException("should not reach here");
    }
    StringBuilder sb = new StringBuilder();
    for (String x : mods) {
        sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
    }
    return sb.toString().trim();
}
 
Example 24
Source Project: dragonwell8_jdk   Source 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 25
Source Project: TencentKona-8   Source File: JdepsTask.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if the given class matches the pattern given in the -include option
 * or if it's a public class if -apionly option is specified
 */
private boolean matches(String classname, AccessFlags flags) {
    if (options.apiOnly && !flags.is(AccessFlags.ACC_PUBLIC)) {
        return false;
    } else if (options.includePattern != null) {
        return options.includePattern.matcher(classname.replace('/', '.')).matches();
    } else {
        return true;
    }
}
 
Example 26
Source Project: jdk8u_jdk   Source 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 27
void checkClassFile(final Path cfilePath) throws Exception {
    ClassFile classFile = ClassFile.read(
            new BufferedInputStream(Files.newInputStream(cfilePath)));
    for (Method method : classFile.methods) {
        if (method.access_flags.is(AccessFlags.ACC_BRIDGE)) {
            checkForAttr(method.attributes,
                    "Annotations hasn't been copied to bridge method",
                    Attribute.RuntimeVisibleAnnotations,
                    Attribute.RuntimeVisibleParameterAnnotations);
        }
    }
}
 
Example 28
Source Project: hottub   Source File: ClassWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
String adjustVarargs(AccessFlags flags, String params) {
    if (flags.is(ACC_VARARGS)) {
        int i = params.lastIndexOf("[]");
        if (i > 0)
            return params.substring(0, i) + "..." + params.substring(i+2);
    }

    return params;
}
 
Example 29
Source Project: openjdk-jdk9   Source File: BridgeHarness.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that every bridge in the generated classfile has a matching bridge
 * annotation in the bridge map
 */
protected void checkBridges(JavaFileObject jfo) {
    try (InputStream is = jfo.openInputStream()) {
        ClassFile cf = ClassFile.read(is);
        System.err.println("checking: " + cf.getName());

        List<Bridge> bridgeList = bridgesMap.get(cf.getName());
        if (bridgeList == null) {
            //no bridges - nothing to check;
            bridgeList = List.nil();
        }

        for (Method m : cf.methods) {
            if (m.access_flags.is(AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_BRIDGE)) {
                //this is a bridge - see if there's a match in the bridge list
                Bridge match = null;
                for (Bridge b : bridgeList) {
                    if (b.value().equals(descriptor(m, cf.constant_pool))) {
                        match = b;
                        break;
                    }
                }
                if (match == null) {
                    error("No annotation for bridge method: " + descriptor(m, cf.constant_pool));
                } else {
                    bridgeList = drop(bridgeList, match);
                }
            }
        }
        if (bridgeList.nonEmpty()) {
            error("Redundant bridge annotation found: " + bridgeList.head.value());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + jfo.toUri() +": " + e);
    }
}
 
Example 30
void analyzeClassFile(File path) throws Exception {
    ClassFile classFile = ClassFile.read(path);
    InnerClasses_attribute innerClasses =
            (InnerClasses_attribute) classFile.attributes.get(Attribute.InnerClasses);
    for (Info classInfo : innerClasses.classes) {
        Assert.check(!classInfo.inner_class_access_flags.is(AccessFlags.ACC_STRICT),
                "Inner classes attribute must not have the ACC_STRICT flag set");
    }
}