private void writeConstructor() { org.objectweb.asm.commons.Method initMethod = new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {targetType}); GeneratorAdapter init = new GeneratorAdapter(ACC_PUBLIC, initMethod, null, null, this); init.loadThis(); init.invokeConstructor(OBJECT_TYPE, OBJECT_INIT); init.loadThis(); init.loadArg(0); init.putField(reflectorType, TARGET_FIELD, targetType); init.returnValue(); init.endMethod(); }
proxyConstructorGenerator.invokeConstructor(TYPE_OBJECT, METHOD_DEFAULT_CONSTRUCTOR); } else { Collection<Object> existingArguments = constructorArgumentTypes.values(); proxyConstructorGenerator.invokeConstructor(getTypeReference(targetClassFullName), new Method(CONSTRUCTOR_NAME, superConstructorDescriptor)); proxyConstructorGenerator.newInstance(TYPE_READ_WRITE_LOCK); proxyConstructorGenerator.dup(); proxyConstructorGenerator.invokeConstructor(TYPE_READ_WRITE_LOCK, METHOD_DEFAULT_CONSTRUCTOR); proxyConstructorGenerator.putField(proxyType, FIELD_READ_WRITE_LOCK, TYPE_READ_WRITE_LOCK); proxyConstructorGenerator.dup(); proxyConstructorGenerator.loadThis(); proxyConstructorGenerator.invokeConstructor(methodType, new Method(CONSTRUCTOR_NAME, getConstructorDescriptor(proxyFullName))); proxyConstructorGenerator.visitInsn(AASTORE); pushResolveInterceptorsCall(proxyConstructorGenerator, i);
overriddenMethodGenerator.invokeConstructor(TYPE_METHOD_INTERCEPTOR_CHAIN, Method.getMethod(CONSTRUCTOR_METHOD_INTERCEPTOR_CHAIN)); int chainVar = overriddenMethodGenerator.newLocal(TYPE_METHOD_INTERCEPTOR_CHAIN); overriddenMethodGenerator.storeLocal(chainVar);
/** See {@link GeneratorAdapter#invokeConstructor(Type, Method)} */ public void invokeConstructor(Type type, Method method) { adapter.invokeConstructor(type, method); }
/** See {@link GeneratorAdapter#invokeConstructor(Type, Method)} */ public void invokeConstructor(Type type, Method method) { adapter.invokeConstructor(type, method); }
@RequiresNonNull("type") private void overrideAndWeaveInheritedMethod(AnalyzedMethod inheritedMethod) { String superName = analyzedClass.superName(); // superName is null only for java.lang.Object which doesn't inherit anything // so safe to assume superName not null here checkNotNull(superName); String[] exceptions = new String[inheritedMethod.exceptions().size()]; for (int i = 0; i < inheritedMethod.exceptions().size(); i++) { exceptions[i] = ClassNames.toInternalName(inheritedMethod.exceptions().get(i)); } List<Advice> advisors = removeSuperseded(inheritedMethod.advisors()); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, inheritedMethod.name(), inheritedMethod.getDesc(), inheritedMethod.signature(), exceptions); mv = visitMethodWithAdvice(mv, ACC_PUBLIC, inheritedMethod.name(), inheritedMethod.getDesc(), advisors); checkNotNull(mv); GeneratorAdapter mg = new GeneratorAdapter(mv, ACC_PUBLIC, inheritedMethod.name(), inheritedMethod.getDesc()); mg.visitCode(); mg.loadThis(); mg.loadArgs(); Type superType = Type.getObjectType(ClassNames.toInternalName(superName)); // method is called invokeConstructor, but should really be called invokeSpecial Method method = new Method(inheritedMethod.name(), inheritedMethod.getDesc()); mg.invokeConstructor(superType, method); mg.returnValue(); mg.endMethod(); }
/** * The stub constructor does nothing * * @param mg * @param m */ private void createConstructor(GeneratorAdapter mg, Method m) { mg.loadThis(); mg.invokeConstructor(Type.getType(Object.class), m); mg.returnValue(); mg.endMethod(); }
private void addConstructor(ClassWriter cw, Constructor constructor) { org.objectweb.asm.commons.Method m = org.objectweb.asm.commons.Method.getMethod(constructor); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw); mg.loadThis(); mg.loadArgs(); mg.invokeConstructor(Type.getType(constructor.getDeclaringClass()), m); mg.returnValue(); mg.endMethod(); }
private static void generateConstructor(ClassWriter cw) { Method m = Method.getMethod("void <init> ()"); GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC, m, null, null, cw); gen.loadThis(); gen.invokeConstructor(Type.getType(Object.class), m); //return the value from constructor gen.returnValue(); gen.endMethod(); } }
/** * Generates the instructions to create and throw an exception. The exception class must have a * constructor with a single String argument. * * @param type the class of the exception to be thrown. * @param message the detailed message of the exception. */ public void throwException(final Type type, final String message) { newInstance(type); dup(); push(message); invokeConstructor(type, Method.getMethod("void <init> (String)")); throwException(); }
/** * Generates the instructions to create and throw an exception. The exception class must have a * constructor with a single String argument. * * @param type the class of the exception to be thrown. * @param message the detailed message of the exception. */ public void throwException(final Type type, final String message) { newInstance(type); dup(); push(message); invokeConstructor(type, Method.getMethod("void <init> (String)")); throwException(); }
/** * Generates the instructions to create and throw an exception. The exception class must have a * constructor with a single String argument. * * @param type the class of the exception to be thrown. * @param message the detailed message of the exception. */ public void throwException(final Type type, final String message) { newInstance(type); dup(); push(message); invokeConstructor(type, Method.getMethod("void <init> (String)")); throwException(); }
/** * Generates the constructor. The constructor generated has signature {@code (DelegatorContext, MetricsContext)}. */ private void generateConstructor(TypeToken<?> delegateType, ClassWriter classWriter) { Method constructor = Methods.getMethod(void.class, "<init>", DelegatorContext.class, MetricsContext.class); String signature = Signatures.getMethodSignature(constructor, TypeToken.of(void.class), getContextType(delegateType), TypeToken.of(MetricsContext.class)); // Constructor(DelegatorContext, MetricsContext) GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, constructor, signature, null, classWriter); // super(context, metricsContext); mg.loadThis(); mg.loadArg(0); mg.loadArg(1); mg.invokeConstructor(Type.getType(AbstractHttpHandlerDelegator.class), Methods.getMethod(void.class, "<init>", DelegatorContext.class, MetricsContext.class)); mg.returnValue(); mg.endMethod(); }
/** * Generates the instructions to create and throw an exception. The * exception class must have a constructor with a single String argument. * * @param type * the class of the exception to be thrown. * @param msg * the detailed message of the exception. */ public void throwException(final Type type, final String msg) { newInstance(type); dup(); push(msg); invokeConstructor(type, Method.getMethod("void <init> (String)")); throwException(); }
private static void generateConstructor(ClassVisitor cv) { GeneratorAdapter mv = new GeneratorAdapter(ACC_PUBLIC, EMPTY_CONSTRUCTOR, null, null, cv); mv.visitCode(); mv.loadThis(); mv.invokeConstructor(TEST_THREAD_EXECUTION_TYPE, TEST_THREAD_EXECUTION_CONSTRUCTOR); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
private void generateConstructor(Field field) { if (isPrivate) { classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "field", Type.getDescriptor(Field.class), null, null) .visitEnd(); } // Constructor(Type classType) Method constructor = getMethod(void.class, "<init>", java.lang.reflect.Type.class); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, constructor, null, new Type[0], classWriter); mg.loadThis(); mg.loadArg(0); mg.invokeConstructor(Type.getType(AbstractFieldAccessor.class), constructor); if (isPrivate) { initializeReflectionField(mg, field); } mg.returnValue(); mg.endMethod(); }
private void generateConstructor(Field field) { if (isPrivate) { classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "field", Type.getDescriptor(Field.class), null, null) .visitEnd(); } // Constructor(Type classType) Method constructor = getMethod(void.class, "<init>", java.lang.reflect.Type.class); GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, constructor, null, new Type[0], classWriter); mg.loadThis(); mg.loadArg(0); mg.invokeConstructor(Type.getType(AbstractFieldAccessor.class), constructor); if (isPrivate) { initializeReflectionField(mg, field); } mg.returnValue(); mg.endMethod(); }
private void generateConstructor(Field field) { if (isPrivate) { classWriter.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "field", Type.getDescriptor(Field.class), null, null) .visitEnd(); } // Constructor(TypeToken<?> classType) GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, getMethod(void.class, "<init>", TypeToken.class), null, new Type[0], classWriter); mg.loadThis(); mg.loadArg(0); mg.invokeConstructor(Type.getType(AbstractFieldAccessor.class), getMethod(void.class, "<init>", TypeToken.class)); if (isPrivate) { initializeReflectionField(mg, field); } mg.returnValue(); mg.endMethod(); }
private void writeConstructor() { org.objectweb.asm.commons.Method initMethod = new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {targetType}); GeneratorAdapter init = new GeneratorAdapter(ACC_PUBLIC, initMethod, null, null, this); init.loadThis(); init.invokeConstructor(OBJECT_TYPE, OBJECT_INIT); init.loadThis(); init.loadArg(0); init.putField(reflectorType, TARGET_FIELD, targetType); init.returnValue(); init.endMethod(); }
private static void init(ClassWriter cw, Type proxyType, Type superType) { GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, new org.objectweb.asm.commons.Method("<init>", Type.VOID_TYPE, new Type[] {INVOKER_TYPE}), null, null, cw); // invoke super constructor: mg.loadThis(); mg.invokeConstructor(superType, org.objectweb.asm.commons.Method.getMethod("void <init> ()")); // assign handler: mg.loadThis(); mg.loadArg(0); mg.putField(proxyType, HANDLER_NAME, INVOKER_TYPE); mg.returnValue(); mg.endMethod(); }