List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write * instance trampoline dispatchers for mangled method names to the * implementing method./* ww w. j a v a 2 s . com*/ */ private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in * WriteJsoImpl, however there are enough small differences between the * semantics of the dispatches that would make a common implementation far * more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the * same, but they're kept distinct to aid in clarity should the * dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor(), false); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }
From source file:com.google.gwt.dev.shell.rewrite.WriteJsoImpl.java
License:Apache License
/** * Records the original name and resets access opcodes. */// w ww . ja v a 2 s . co m @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { originalName = name; super.visit(version, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, name + '$', signature, superName, interfaces); }
From source file:com.google.singletondetector.visitors.SingletonClassVisitor.java
License:Apache License
@Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) { if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) { sd.visitStaticField(name, desc); }// w ww. j ava 2s. c om if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE && (access & Opcodes.ACC_FINAL) != Opcodes.ACC_FINAL) { sd.addStaticField(name, desc); } } return null; }
From source file:com.google.singletondetector.visitors.SingletonClassVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC && (access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC)) { sd.visitStaticMethod(name, desc); }// w w w . j av a2 s .c om return super.visitMethod(access, name, desc, signature, exceptions); }
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 w w . j a va2 s. c o m 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.BytecodeProducerTest.java
License:Apache License
public void testGenDoesntOverlapWithCompile() { BytecodeProducer producer = new BytecodeProducer() { @Override/* ww w. ja v a 2 s . c o m*/ void doGen(CodeBuilder adapter) { BytecodeUtils.constant('c').gen(adapter); } }; try { CodeBuilder adaterAdapter = new CodeBuilder(Opcodes.ACC_PUBLIC, BytecodeUtils.NULLARY_INIT, new MethodNode()); producer.gen(adaterAdapter); fail(); } catch (IllegalStateException e) { assertThat(e) .hasMessage("All bytecode producers should be created prior to code generation beginning."); } }
From source file:com.google.template.soy.jbcsrc.BytecodeUtils.java
License:Apache License
/** * Generates a default nullary public constructor for the given type on the {@link ClassVisitor}. * //from w ww . j a v a2s. c o m * <p>For java classes this is normally generated by the compiler and looks like: <pre>{@code * public Foo() { * super(); * }}</pre> */ static void defineDefaultConstructor(ClassVisitor cv, TypeInfo ownerType) { CodeBuilder mg = new CodeBuilder(Opcodes.ACC_PUBLIC, NULLARY_INIT, null, cv); mg.visitCode(); Label start = mg.mark(); Label end = mg.newLabel(); LocalVariable thisVar = LocalVariable.createThisVar(ownerType, start, end); thisVar.gen(mg); mg.invokeConstructor(OBJECT.type(), NULLARY_INIT); mg.returnValue(); mg.mark(end); thisVar.tableEntry(mg); mg.endMethod(); }
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 {/*from w ww.j a v a2s. 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( 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.BytecodeProducerTest.java
License:Apache License
@Test public void testGenDoesntOverlapWithCompile() { BytecodeProducer producer = new BytecodeProducer() { @Override//from www . j a v a2s .c o m protected void doGen(CodeBuilder adapter) { BytecodeUtils.constant('c').gen(adapter); } }; try { CodeBuilder adaterAdapter = new CodeBuilder(Opcodes.ACC_PUBLIC, BytecodeUtils.NULLARY_INIT, new MethodNode()); producer.gen(adaterAdapter); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessageThat() .contains("All bytecode producers should be constructed prior to code generation"); } }
From source file:com.google.template.soy.jbcsrc.restricted.BytecodeUtils.java
License:Apache License
/** * Generates a default nullary public constructor for the given type on the {@link ClassVisitor}. * * <p>For java classes this is normally generated by the compiler and looks like: * * <pre>{@code//w w w . j a v a 2s . c om * public Foo() { * super(); * } * }</pre> */ public static void defineDefaultConstructor(ClassVisitor cv, TypeInfo ownerType) { CodeBuilder mg = new CodeBuilder(Opcodes.ACC_PUBLIC, NULLARY_INIT, null, cv); mg.visitCode(); Label start = mg.mark(); Label end = mg.newLabel(); LocalVariable thisVar = LocalVariable.createThisVar(ownerType, start, end); thisVar.gen(mg); mg.invokeConstructor(OBJECT.type(), NULLARY_INIT); mg.returnValue(); mg.mark(end); thisVar.tableEntry(mg); mg.endMethod(); }