List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:com.facebook.buck.jvm.java.abi.AccessFlags.java
License:Apache License
/** * Gets the class access flags (see JVMS8 4.1) for the given type element as they should appear in * the ClassNode of a class file. Inner-class specific flags are not allowed in that node, * presumably for compatibility reasons. *//*from w w w.ja v a 2 s . co m*/ public int getAccessFlagsForClassNode(TypeElement e) { // Static never makes it into the file for classes int accessFlags = getAccessFlags(e) & ~Opcodes.ACC_STATIC; if (e.getNestingKind() != NestingKind.TOP_LEVEL) { if (e.getModifiers().contains(Modifier.PROTECTED)) { // It looks like inner classes with protected visibility get marked as public, and then // their InnerClasses attributes override that more specifically accessFlags = (accessFlags & ~Opcodes.ACC_PROTECTED) | Opcodes.ACC_PUBLIC; } else if (e.getModifiers().contains(Modifier.PRIVATE)) { // It looks like inner classes with private visibility get marked as package, and then // their InnerClasses attributes override that more specifically accessFlags = (accessFlags & ~Opcodes.ACC_PRIVATE); } } return accessFlags; }
From source file:com.facebook.buck.jvm.java.abi.AccessFlags.java
License:Apache License
/** Gets the access flag (see JVMS8 4.1, 4.5, 4.6) corresponding to the given modifier. */ private static int modifierToAccessFlag(Modifier modifier) { switch (modifier) { case PUBLIC:/*from w w w. j a v a2 s.co m*/ return Opcodes.ACC_PUBLIC; case PROTECTED: return Opcodes.ACC_PROTECTED; case PRIVATE: return Opcodes.ACC_PRIVATE; case ABSTRACT: return Opcodes.ACC_ABSTRACT; case DEFAULT: return 0; case STATIC: return Opcodes.ACC_STATIC; case FINAL: return Opcodes.ACC_FINAL; case TRANSIENT: return Opcodes.ACC_TRANSIENT; case VOLATILE: return Opcodes.ACC_VOLATILE; case SYNCHRONIZED: return Opcodes.ACC_SYNCHRONIZED; case NATIVE: return Opcodes.ACC_NATIVE; case STRICTFP: return Opcodes.ACC_STRICT; default: throw new IllegalArgumentException(String.format("Unexpected modifier: %s", modifier)); } }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testStaticFlagOnField() throws IOException { testFieldFlags("static", Opcodes.ACC_STATIC); }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testStaticFlagOnMethod() throws IOException { testMethodFlags("static", Opcodes.ACC_STATIC); }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testStaticFlagOnClass() throws IOException { testTypeFlags(Joiner.on('\n').join("class Foo {", " static class Inner { }", "}"), "Foo.Inner", Opcodes.ACC_STATIC | Opcodes.ACC_SUPER); }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testMultipleFlagsOnMethod() throws IOException { testMethodFlags("public static", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC); }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testMultipleFlagsOnField() throws IOException { testFieldFlags("public static", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC); }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testEnumVarFlags() throws IOException { compile("enum Foo { Item }"); assertEquals(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_ENUM, accessFlags.getAccessFlags(findField("Item", elements.getTypeElement("Foo")))); }
From source file:com.facebook.buck.tools.dxanalysis.MutabilityAnalyzer.java
License:Apache License
private boolean classIsDefinitelyMutable(ClassNode klass) { if (superClassIsDefinitelyMutable(klass.superName)) { log.add("Mutable parent: " + klass.name + " < " + klass.superName); return true; }/* w w w.j av a 2 s. co m*/ for (FieldNode field : klass.fields) { if ((field.access & Opcodes.ACC_STATIC) != 0) { continue; } if ((field.access & Opcodes.ACC_FINAL) == 0) { log.add("Non-final field: " + klass.name + "#" + field.name + ":" + field.desc); return true; } if (field.name.contains("$")) { // Generated fields are assumed to be effectively immutable. // This could, in principle, miss an issue like a static reference to a // seemingly-immutable inner class object that maintains a hidden reference // to its mutable outer object, but that seems unlikely. continue; } Type type = Type.getType(field.desc); if (IMMUTABLE_TYPE_SORTS.contains(type.getSort())) { continue; } if (type.getSort() != Type.OBJECT) { log.add("Odd sort: " + klass.name + "#" + field.name + ":" + field.desc); return true; } if (allClasses.keySet().contains(type.getInternalName())) { if (classesWithMutableDescendents.contains(type.getInternalName())) { log.add("Internal mutable field: " + klass.name + "#" + field.name + ":" + field.desc); return true; } } else { if (!EXTERNAL_IMMUTABLE_CLASSES.contains(type.getInternalName())) { log.add("External mutable field: " + klass.name + "#" + field.name + ":" + field.desc); return true; } } } return false; }
From source file:com.facebook.buck.tools.dxanalysis.StaticStateAnalyzer.java
License:Apache License
private boolean isClassSafe(ClassNode klass) { boolean isSafe = true; // Look for mutable static fields. for (FieldNode field : klass.fields) { if ((field.access & Opcodes.ACC_STATIC) == 0) { continue; }//from w w w . j ava 2 s. co m if ((field.access & Opcodes.ACC_FINAL) == 0) { log.add("Non-final static field: " + describe(klass, field)); isSafe = false; continue; } if (!mutabilityAnalyzer.isTypeImmutable(field.desc)) { log.add("Mut-final static field: " + describe(klass, field)); isSafe = false; continue; } } // Look for static synchronized methods. for (MethodNode method : klass.methods) { if ((method.access & Opcodes.ACC_STATIC) == 0) { continue; } if ((method.access & Opcodes.ACC_SYNCHRONIZED) != 0) { log.add("Synchronized static method: " + describe(klass, method)); isSafe = false; continue; } } return isSafe; }