com.sun.tools.classfile.AccessFlags Java Examples
The following examples show how to use
com.sun.tools.classfile.AccessFlags.
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 jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 File: ClassReader.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: Options.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 #4
Source File: ClassReader.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: ClassReader.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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: ClassReader.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: FindNativeFiles.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: ClassReader.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #9
Source File: CompareTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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 #10
Source File: CompareTest.java From hottub with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: ClassReader.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: ClassReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #13
Source File: ClassReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #14
Source File: ClassReader.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #15
Source File: Options.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * 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 #16
Source File: Options.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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 #17
Source File: FindNativeFiles.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #18
Source File: Options.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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 #19
Source File: ClassReader.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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
Source File: FindNativeFiles.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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
Source File: CompareTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #22
Source File: Options.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 #23
Source File: ClassReader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 File: JdepsTask.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 #25
Source File: BridgeHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 #26
Source File: AttributeWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { boolean first = true; for (Info info : attr.classes) { //access AccessFlags access_flags = info.inner_class_access_flags; if (options.checkAccess(access_flags)) { if (first) { writeInnerClassHeader(); first = false; } for (String name: access_flags.getInnerClassModifiers()) print(name + " "); if (info.inner_name_index != 0) { print("#" + info.inner_name_index + "= "); } print("#" + info.inner_class_info_index); if (info.outer_class_info_index != 0) { print(" of #" + info.outer_class_info_index); } print(";"); tab(); print("// "); if (info.inner_name_index != 0) { print(getInnerName(constant_pool, info) + "="); } constantWriter.write(info.inner_class_info_index); if (info.outer_class_info_index != 0) { print(" of "); constantWriter.write(info.outer_class_info_index); } println(); } } if (!first) indent(-1); return null; }
Example #27
Source File: ClassReader.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #28
Source File: ClassFileReader.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); } }
Example #29
Source File: InnerClassAttrMustNotHaveStrictFPFlagTest.java From hottub with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #30
Source File: BridgeHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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); } }