List of usage examples for org.objectweb.asm Opcodes ACC_SUPER
int ACC_SUPER
To view the source code for org.objectweb.asm Opcodes ACC_SUPER.
Click Source Link
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testTwoInner() { CollectClassData cd = collect(Two.TwoInner.class); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(Opcodes.ACC_PUBLIC, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Inner, cd.getClassType()); assertEquals("CollectClassDataTest.Two.TwoInner", cd.getNestedSourceName()); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testLocal() { CollectClassData cd = collect(Three.class.getName() + "$2Foo"); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(0, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Local, cd.getClassType()); assertEquals("methodWithLocal", cd.getEnclosingMethodName()); }
From source file:com.google.gwt.dev.javac.asm.CollectClassDataTest.java
License:Apache License
public void testLocalStatic() { CollectClassData cd = collect(Three.class.getName() + "$1Foo"); // Don't check for super bit, as it will depend on the JDK used to compile. assertEquals(0, cd.getAccess() & ~Opcodes.ACC_SUPER); assertEquals(ClassType.Local, cd.getClassType()); assertEquals("methodWithLocalStatic", cd.getEnclosingMethodName()); assertEquals(null, cd.getNestedSourceName()); }
From source file:com.google.template.soy.jbcsrc.AnnotationRefTest.java
License:Apache License
@SuppressWarnings("unchecked") private static <T extends Annotation> Class<?> createClassWithAnnotation(T ann) { TypeInfo generatedType = TypeInfo.create(AnnotationRefTest.class.getPackage().getName() + ".Tmp"); SoyClassWriter cw = SoyClassWriter.builder(generatedType) .setAccess(Opcodes.ACC_FINAL | Opcodes.ACC_SUPER | Opcodes.ACC_PUBLIC).build(); AnnotationRef.forType((Class<T>) ann.annotationType()).write(ann, cw); cw.visitEnd();/*from w ww . j a v a2s . com*/ ClassData cd = cw.toClassData(); try { return new MemoryClassLoader(ImmutableList.of(cd)).loadClass(cd.type().className()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); // this should be impossible } }
From source file:com.google.template.soy.jbcsrc.ExpressionTester.java
License:Apache License
private static ClassData createClass(Class<? extends Invoker> targetInterface, Expression expr) { java.lang.reflect.Method invokeMethod; try {/*ww w . ja v a2s. co m*/ invokeMethod = targetInterface.getMethod("invoke"); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); } Class<?> returnType = invokeMethod.getReturnType(); if (!Type.getType(returnType).equals(expr.resultType())) { if (!returnType.equals(Object.class) || expr.resultType().getSort() != Type.OBJECT) { throw new IllegalArgumentException(targetInterface + " is not appropriate for this expression"); } } TypeInfo generatedType = TypeInfo.create( ExpressionTester.class.getPackage().getName() + "." + targetInterface.getSimpleName() + "Impl"); SoyClassWriter cw = SoyClassWriter.builder(generatedType) .setAccess(Opcodes.ACC_FINAL | Opcodes.ACC_SUPER | Opcodes.ACC_PUBLIC) .implementing(TypeInfo.create(targetInterface)).build(); BytecodeUtils.defineDefaultConstructor(cw, generatedType); Method invoke = Method.getMethod(invokeMethod); Statement.returnExpression(expr).writeMethod(Opcodes.ACC_PUBLIC, invoke, cw); Method voidInvoke; try { voidInvoke = Method.getMethod(Invoker.class.getMethod("voidInvoke")); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); // this method definitely exists } Statement.concat(LocalVariable.createThisVar(generatedType, new Label(), new Label()) .invoke(MethodRef.create(invokeMethod)).toStatement(), new Statement() { @Override void doGen(CodeBuilder adapter) { adapter.visitInsn(Opcodes.RETURN); } }).writeMethod(Opcodes.ACC_PUBLIC, voidInvoke, cw); ClassData data = cw.toClassData(); checkClassData(data); return data; }
From source file:com.google.template.soy.jbcsrc.restricted.testing.ExpressionEvaluator.java
License:Apache License
public static ClassData createClass(Class<? extends Invoker> targetInterface, Expression expr) { java.lang.reflect.Method invokeMethod; try {//from w ww .jav a 2s.c o m invokeMethod = targetInterface.getMethod("invoke"); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); } Class<?> returnType = invokeMethod.getReturnType(); if (!Type.getType(returnType).equals(expr.resultType())) { if (!returnType.equals(Object.class) || expr.resultType().getSort() != Type.OBJECT) { throw new IllegalArgumentException(targetInterface + " is not appropriate for this expression"); } } TypeInfo generatedType = TypeInfo.create(Names.CLASS_PREFIX + targetInterface.getSimpleName() + "Impl"); SoyClassWriter cw = SoyClassWriter.builder(generatedType) .setAccess(Opcodes.ACC_FINAL | Opcodes.ACC_SUPER | Opcodes.ACC_PUBLIC) .implementing(TypeInfo.create(targetInterface)).build(); BytecodeUtils.defineDefaultConstructor(cw, generatedType); Method invoke = Method.getMethod(invokeMethod); Statement.returnExpression(expr).writeMethod(Opcodes.ACC_PUBLIC, invoke, cw); Method voidInvoke; try { voidInvoke = Method.getMethod(Invoker.class.getMethod("voidInvoke")); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); // this method definitely exists } Statement.concat(LocalVariable.createThisVar(generatedType, new Label(), new Label()) .invoke(MethodRef.create(invokeMethod)).toStatement(), new Statement() { @Override protected void doGen(CodeBuilder adapter) { adapter.visitInsn(Opcodes.RETURN); } }).writeMethod(Opcodes.ACC_PUBLIC, voidInvoke, cw); ClassData data = cw.toClassData(); checkClassData(data); return data; }
From source file:com.google.template.soy.jbcsrc.TemplateCompiler.java
License:Apache License
/** * Returns the list of classes needed to implement this template. * * <p>For each template, we generate: * <ul>// www. j av a2 s . c o m * <li>A {@link com.google.template.soy.jbcsrc.shared.CompiledTemplate.Factory} * <li>A {@link CompiledTemplate} * <li>A SoyAbstractCachingProvider subclass for each {@link LetValueNode} and * {@link CallParamValueNode} * <li>A RenderableThunk subclass for each {@link LetContentNode} and * {@link CallParamContentNode} * </li> * * <p>Note: This will <em>not</em> generate classes for other templates, only the template * configured in the constructor. But it will generate classes that <em>reference</em> the * classes that are generated for other templates. It is the callers responsibility to ensure * that all referenced templates are generated and available in the classloader that ultimately * loads the returned classes. */ Iterable<ClassData> compile() { List<ClassData> classes = new ArrayList<>(); // first generate the factory // TODO(lukes): don't generate factory if the template is private? The factories are only // useful to instantiate templates for calls from java. Soy->Soy calls should invoke // constructors directly. new TemplateFactoryCompiler(template, innerClasses).compile(); writer = SoyClassWriter.builder(template.typeInfo()) .setAccess(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_FINAL).implementing(TEMPLATE_TYPE) .sourceFileName(template.node().getSourceLocation().getFileName()).build(); generateTemplateMetadata(); stateField.defineField(writer); paramsField.defineField(writer); ijField.defineField(writer); for (FieldRef field : paramFields.values()) { field.defineField(writer); } Statement fieldInitializers = generateRenderMethod(); generateConstructor(fieldInitializers); innerClasses.registerAllInnerClasses(writer); writer.visitEnd(); classes.add(writer.toClassData()); classes.addAll(innerClasses.getInnerClassData()); writer = null; return classes; }
From source file:com.googlecode.dex2jar.tools.JarAccessCmd.java
License:Apache License
static int str2acc(String s) { if (s == null) { return 0; }/* www . jav a 2 s. c o m*/ int result = 0; s = s.toLowerCase(); if (s.contains("public")) { result |= Opcodes.ACC_PUBLIC; } if (s.contains("private")) { result |= Opcodes.ACC_PRIVATE; } if (s.contains("protected")) { result |= Opcodes.ACC_PROTECTED; } if (s.contains("final")) { result |= Opcodes.ACC_FINAL; } if (s.contains("static")) { result |= Opcodes.ACC_STATIC; } if (s.contains("super")) { result |= Opcodes.ACC_SUPER; } if (s.contains("synchronized")) { result |= Opcodes.ACC_SYNCHRONIZED; } if (s.contains("volatile")) { result |= Opcodes.ACC_VOLATILE; } if (s.contains("bridge")) { result |= Opcodes.ACC_BRIDGE; } if (s.contains("transient")) { result |= Opcodes.ACC_TRANSIENT; } if (s.contains("varargs")) { result |= Opcodes.ACC_VARARGS; } if (s.contains("native")) { result |= Opcodes.ACC_NATIVE; } if (s.contains("strict")) { result |= Opcodes.ACC_STRICT; } if (s.contains("interface")) { result |= Opcodes.ACC_INTERFACE; } if (s.contains("abstract")) { result |= Opcodes.ACC_ABSTRACT; } if (s.contains("synthetic")) { result |= Opcodes.ACC_SYNTHETIC; } if (s.contains("annotation")) { result |= Opcodes.ACC_ANNOTATION; } if (s.contains("enum")) { result |= Opcodes.ACC_ENUM; } if (s.contains("deprecated")) { result |= Opcodes.ACC_DEPRECATED; } return result; }
From source file:com.googlecode.dex2jar.v3.V3ClassAdapter.java
License:Apache License
private int clearClassAccess(boolean isInner, int access) { if ((access & Opcodes.ACC_INTERFACE) == 0) { // issue 55 access |= Opcodes.ACC_SUPER;// ?classdx???? }/*from ww w .jav a 2s. c o m*/ // access in class has no acc_static or acc_private access &= ~(Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE); if (isInner && (access & Opcodes.ACC_PROTECTED) != 0) {// protected inner class are public access &= ~Opcodes.ACC_PROTECTED; access |= Opcodes.ACC_PUBLIC; } return access; }
From source file:com.googlecode.dex2jar.v3.V3ClassAdapter.java
License:Apache License
private int clearInnerAccess(int access) { access &= (~Opcodes.ACC_SUPER);// inner class attr has no acc_super if (0 != (access & Opcodes.ACC_PRIVATE)) {// clear public/protected if it is private access &= ~(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED); } else if (0 != (access & Opcodes.ACC_PROTECTED)) {// clear public if it is protected access &= ~(Opcodes.ACC_PUBLIC); }/* w w w. j a v a2 s. c o m*/ return access; }