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.google.devtools.depan.java.bytecode.impl.ClassDepLister.java
License:Apache License
@Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { TypeElement type = TypeNameUtil.fromDescriptor(desc); FieldElement field = new FieldElement(name, type, mainClass); // simple className builder.newDep(mainClass, type, JavaRelation.TYPE); // field// w ww . j av a2s. c o m JavaRelation r = null; if ((Opcodes.ACC_STATIC & access) != 0) { r = JavaRelation.STATIC_FIELD; } else { r = JavaRelation.MEMBER_FIELD; } builder.newDep(mainClass, field, r); // generic types in signature // TODO(ycoppel): how to get types in generics ? (signature) return asmFactory.getGenericFieldVisitor(); }
From source file:com.google.devtools.depan.java.bytecode.impl.ClassDepLister.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { // the method itself MethodElement m = new MethodElement(desc, name, mainClass); JavaRelation r = null;/*from w w w.ja v a 2 s. c o m*/ if ((Opcodes.ACC_STATIC & access) != 0) { r = JavaRelation.STATIC_METHOD; } else { r = JavaRelation.MEMBER_METHOD; } builder.newDep(mainClass, m, r); // arguments dependencies for (Type t : Type.getArgumentTypes(desc)) { builder.newDep(m, TypeNameUtil.fromDescriptor(t.getDescriptor()), JavaRelation.TYPE); } // return-type dependency TypeElement type = TypeNameUtil.fromDescriptor(Type.getReturnType(desc).getDescriptor()); builder.newDep(m, type, JavaRelation.READ); return asmFactory.buildMethodVisitor(builder, m); }
From source file:com.google.gwt.dev.javac.asm.CollectClassData.java
License:Apache License
/** * Called once for every inner class of this class. * * @param internalName internal name of inner class (ie, com/google/Foo$1) * @param enclosingInternalName internal name of enclosing class (null if not a member * class or anonymous)// www . j av a 2s . co m * @param innerName simple name of the inner class (null if anonymous) * @param access access flags (bitwise or of Opcodes.ACC_*) as declared in the * enclosing class */ @Override public void visitInnerClass(String internalName, String enclosingInternalName, String innerName, int access) { buildNestedSourceName(internalName, enclosingInternalName, innerName); // If this inner class is ourselves, take the access flags defined in the InnerClass attribute. if (this.internalName.equals(internalName)) { if (enclosingInternalName != null) { this.enclosingInternalName = enclosingInternalName; } this.access = access; boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; switch (classType) { case TopLevel: classType = isStatic ? ClassType.Nested : ClassType.Inner; break; case Anonymous: if (innerName != null) { classType = ClassType.Local; } break; case Inner: // Already marked as inner class by the synthetic this$1 field break; default: throw new IllegalStateException("Unexpected INNERCLASS with type of " + classType); } } }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testOne() { CollectClassData cd = collect(One.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Nested, cd.getClassType()); assertEquals(0, cd.getFields().size()); assertEquals(0, cd.getInterfaceInternalNames().length); assertEquals(0, cd.getAnnotations().size()); assertEquals("com/google/gwt/dev/javac/asmbridge/EmptyVisitor", cd.getSuperInternalName()); assertEquals("CollectClassDataTest.One", cd.getNestedSourceName()); List<CollectMethodData> methods = cd.getMethods(); assertEquals(2, methods.size());/*from www . j av a2s. c o m*/ // TODO(jat): Is it safe to assume the implicit constructor is always first? CollectMethodData method = methods.get(0); Type[] argTypes = method.getArgTypes(); String[] argNames = method.getArgNames(); assertEquals("<init>", method.getName()); assertEquals(0, argTypes.length); assertEquals(0, argNames.length); assertEquals(0, method.getArgAnnotations().length); assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); method = methods.get(1); argTypes = method.getArgTypes(); argNames = method.getArgNames(); assertEquals("visitAnnotation", method.getName()); assertEquals(2, argTypes.length); assertEquals("java.lang.String", argTypes[0].getClassName()); assertEquals("boolean", argTypes[1].getClassName()); assertEquals(2, argNames.length); assertEquals("desc", argNames[0]); assertEquals("visible", argNames[1]); assertEquals(2, method.getArgAnnotations().length); assertEquals(0, method.getArgAnnotations()[0].size()); assertEquals(0, method.getArgAnnotations()[1].size()); // Note that @Override is a source-only annotation assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testTwo() { CollectClassData cd = collect(Two.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Nested, cd.getClassType()); List<CollectFieldData> fields = cd.getFields(); assertEquals(2, fields.size());/*from ww w . j a v a2s . c o m*/ CollectFieldData field = fields.get(0); assertEquals("field", field.getName()); assertEquals("Ljava/lang/String;", field.getDesc()); List<CollectAnnotationData> annotations = field.getAnnotations(); assertEquals(0, annotations.size()); field = fields.get(1); assertEquals("annotatedField", field.getName()); assertEquals("Ljava/lang/String;", field.getDesc()); annotations = field.getAnnotations(); assertEquals(1, annotations.size()); AnnotationData annotation = annotations.get(0).getAnnotation(); assertEquals("Lcom/google/gwt/dev/javac/typemodel/test/TestAnnotation;", annotation.getDesc()); assertEquals("field", annotation.getValues().get("value")); assertEquals(0, cd.getInterfaceInternalNames().length); annotations = cd.getAnnotations(); assertEquals(1, annotations.size()); annotation = annotations.get(0).getAnnotation(); assertEquals("Lcom/google/gwt/dev/javac/typemodel/test/PrimitiveValuesAnnotation;", annotation.getDesc()); assertEquals(Byte.valueOf((byte) 42), annotation.getValues().get("b")); assertEquals(42, annotation.getValues().get("i")); assertEquals("java/lang/Object", cd.getSuperInternalName()); assertEquals("CollectClassDataTest.Two", cd.getNestedSourceName()); List<CollectMethodData> methods = cd.getMethods(); assertEquals(3, methods.size()); // TODO(jat): Is it safe to assume the order? CollectMethodData method = methods.get(0); Type[] argTypes = method.getArgTypes(); String[] argNames = method.getArgNames(); assertEquals("<init>", method.getName()); assertEquals(1, argTypes.length); assertEquals(1, argNames.length); assertEquals(1, method.getArgAnnotations().length); assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); method = methods.get(1); argTypes = method.getArgTypes(); argNames = method.getArgNames(); assertEquals("foo", method.getName()); assertEquals(1, argTypes.length); assertEquals("int", argTypes[0].getClassName()); assertEquals(1, argNames.length); assertEquals("a", argNames[0]); assertEquals(1, method.getArgAnnotations().length); assertEquals(0, method.getArgAnnotations()[0].size()); assertEquals(1, method.getAnnotations().size()); assertEquals(1, method.getExceptions().length); method = methods.get(2); argTypes = method.getArgTypes(); argNames = method.getArgNames(); assertEquals("<init>", method.getName()); assertEquals(2, argTypes.length); assertEquals("int", argTypes[0].getClassName()); assertEquals("java.lang.String", argTypes[1].getClassName()); assertEquals(2, argNames.length); assertEquals("a", argNames[0]); assertEquals("b", argNames[1]); assertEquals(2, method.getArgAnnotations().length); assertEquals(0, method.getArgAnnotations()[0].size()); assertEquals(0, method.getArgAnnotations()[1].size()); assertEquals(0, method.getAnnotations().size()); assertEquals(0, method.getExceptions().length); }
From source file:com.google.gwt.dev.javac.asm.CollectMethodData.java
License:Apache License
@Override public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { // The incoming index is based on counting long and double // arguments as taking up two slots. For example, a method 'm(int // a, long b, String c, double d, Object e)' will call this method // with indices 0, 1, 3, 4, 6 (ignoring 'this' for the sake of the // example). To compensate, we set a counter to 0 at the first // argument of each method and increment it for each long or // double argument we encounter. Then each incoming index is // adjusted down by the value of the counter to obtain a simple // index./* w ww . jav a 2s .c o m*/ if (index == 0) { longDoubleCounter = 0; } else { index -= longDoubleCounter; } if ((access & Opcodes.ACC_STATIC) == 0) { // adjust for "this" // TODO(jat): do we need to account for this$0 in inner classes? --index; } // TODO(jat): is it safe to assume parameter slots don't get reused? // Do we need to check if the name has already been assigned? if (index >= 0 && index < argNames.length) { actualArgNames = true; argNames[index] = name; } // Adjust the counter if ("J".equals(desc) || "D".equals(desc)) { longDoubleCounter++; } }
From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java
License:Apache License
/** * Returns true if this class is a non-static class inside a generic class. *///from w w w. jav a 2 s. c om // TODO(jat): do we need to consider the entire hierarchy? private static boolean nonStaticInsideGeneric(CollectClassData classData, CollectClassData enclosingClassData) { if (enclosingClassData == null || (classData.getAccess() & Opcodes.ACC_STATIC) != 0) { return false; } return getTypeParametersForClass(enclosingClassData) != null; }
From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java
License:Apache License
private boolean resolveEnclosingClass(TreeLogger logger, JRealClassType unresolvedType, TypeOracleBuildContext context) { assert unresolvedType != null; if (unresolvedType.getEnclosingType() != null) { return true; }// ww w . ja va2 s . c om // Find our enclosing class and set it CollectClassData classData = context.classDataByType.get(unresolvedType); assert classData != null; String enclosingClassInternalName = classData.getEnclosingInternalName(); JRealClassType enclosingType = null; if (enclosingClassInternalName != null) { enclosingType = findByInternalName(enclosingClassInternalName); // Ensure enclosing classes are resolved if (enclosingType != null) { if (!resolveEnclosingClass(logger, enclosingType, context)) { return false; } if (enclosingType.isGenericType() != null && (classData.getAccess() & (Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE)) != 0) { // If the inner class doesn't have access to it's enclosing type's // type variables, the enclosing type must be the raw type instead // of the generic type. JGenericType genericType = enclosingType.isGenericType(); setEnclosingType(unresolvedType, genericType.getRawType()); } else { setEnclosingType(unresolvedType, enclosingType); } } } return true; }
From source file:com.google.gwt.dev.javac.TypeOracleMediator.java
License:Open Source License
/** * Returns true if this class is a non-static class inside a generic class. * /*from www . j a v a 2 s. c o m*/ * TODO(jat): do we need to consider the entire hierarchy? * * @param classData * @param enclosingClassData * @return true if this class is a non-static class inside a generic class */ private static boolean nonStaticInsideGeneric(CollectClassData classData, CollectClassData enclosingClassData) { if (enclosingClassData == null || (classData.getAccess() & Opcodes.ACC_STATIC) != 0) { return false; } return getTypeParametersForClass(enclosingClassData) != null; }
From source file:com.google.gwt.dev.javac.TypeOracleMediator.java
License:Open Source License
private boolean resolveEnclosingClass(TreeLogger logger, JRealClassType type) { assert type != null; if (type.getEnclosingType() != null) { return true; }/* w ww . j a va 2 s .c om*/ // Find our enclosing class and set it CollectClassData classData = classMapType.get(type); assert classData != null; String outerClass = classData.getOuterClass(); JRealClassType enclosingType = null; if (outerClass != null) { enclosingType = binaryMapper.get(outerClass); // Ensure enclosing classes are resolved if (enclosingType != null) { if (!resolveEnclosingClass(logger, enclosingType)) { return false; } if (enclosingType.isGenericType() != null && (classData.getAccess() & (Opcodes.ACC_STATIC | Opcodes.ACC_INTERFACE)) != 0) { // If the inner class doesn't have access to it's enclosing type's // type variables, the enclosign type must be the raw type instead // of the generic type. JGenericType genericType = enclosingType.isGenericType(); setEnclosingType(type, genericType.getRawType()); } else { setEnclosingType(type, enclosingType); } } } return true; }