private BaseAdapter( Method method, org.objectweb.asm.commons.Method asmMethod, MethodVisitor methodVisitor) { super( Opcodes.ASM6, methodVisitor, Opcodes.ACC_PUBLIC, asmMethod.getName(), asmMethod.getDescriptor()); this.iMethod = method; }
private BaseAdapter( org.objectweb.asm.commons.Method asmMethod, Method method) { this( method, asmMethod, ReflectorClassWriter.this.visitMethod( Opcodes.ACC_PUBLIC, asmMethod.getName(), asmMethod.getDescriptor(), null, ReflectorClassWriter.getInternalNames(method.getExceptionTypes()))); }
private Method writeResolveTargetMethod(ClassWriter proxyClassWriter, Type targetType) { Method resolveTargetMethodDesc = Method.getMethod(targetClassFullName + " " + METHOD_RESOLVE_TARGET + "()"); GeneratorAdapter resolveTargetMethod = new GeneratorAdapter(proxyClassWriter.visitMethod( ACC_PRIVATE, resolveTargetMethodDesc.getName(), resolveTargetMethodDesc.getDescriptor(), null, null ), ACC_PRIVATE, METHOD_RESOLVE_TARGET, resolveTargetMethodDesc.getDescriptor()); // add the logic to create to the bean instance resolveTargetMethod.loadThis(); // load the bean context resolveTargetMethod.getField(proxyType, FIELD_BEAN_LOCATOR, TYPE_BEAN_LOCATOR); // 1st argument: the type resolveTargetMethod.push(targetType); // 2nd argument: null qualifier resolveTargetMethod.loadThis(); // the bean qualifier resolveTargetMethod.getField(proxyType, FIELD_BEAN_QUALIFIER, Type.getType(Qualifier.class)); resolveTargetMethod.invokeInterface( TYPE_BEAN_LOCATOR, METHOD_GET_PROXY_TARGET_BEAN ); pushCastToType(resolveTargetMethod, targetClassFullName); resolveTargetMethod.returnValue(); resolveTargetMethod.visitMaxs(1, 1); return resolveTargetMethodDesc; }
ClassVisitor pcw = proxyBeanDefinitionWriter.getClassWriter(); targetDefinitionGenerator = new GeneratorAdapter(pcw.visitMethod(ACC_PUBLIC, METHOD_PROXY_TARGET_TYPE.getName(), METHOD_PROXY_TARGET_TYPE.getDescriptor(), null, null ), ACC_PUBLIC, METHOD_PROXY_TARGET_TYPE.getName(), METHOD_PROXY_TARGET_TYPE.getDescriptor()); targetDefinitionGenerator.loadThis(); targetDefinitionGenerator.push(getTypeReference(parentWriter.getBeanDefinitionName())); METHOD_PROXY_TARGET_CLASS.getName(), METHOD_PROXY_TARGET_CLASS.getDescriptor(), null, null ), ACC_PUBLIC, METHOD_PROXY_TARGET_CLASS.getName(), METHOD_PROXY_TARGET_CLASS.getDescriptor()); targetTypeGenerator.loadThis(); targetTypeGenerator.push(getTypeReference(parentWriter.getBeanTypeName()));
private static String print(Method method) { StringBuilder sb = new StringBuilder(); sb.append(print(method.getReturnType())).append(" ").append(method.getName()).append("("); for (Type t : method.getArgumentTypes()) { sb.append(print(t)).append(" "); } sb.append(")"); return sb.toString(); }
private @Nullable Method hack(@Nullable Method method) { if (method == null) { return null; } Type[] argumentTypes = method.getArgumentTypes(); Type[] hackedArgumentTypes = new Type[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) { hackedArgumentTypes[i] = hack(argumentTypes[i]); } return new Method(method.getName(), hack(method.getReturnType()), hackedArgumentTypes); }
@RequiresNonNull("type") private void addShim(ShimType shimType) { for (java.lang.reflect.Method reflectMethod : shimType.shimMethods()) { Method method = Method.getMethod(reflectMethod); Shim shim = reflectMethod.getAnnotation(Shim.class); checkNotNull(shim); if (shim.value().length != 1) { throw new IllegalStateException( "@Shim annotation must have exactly one value when used on methods"); } Method targetMethod = Method.getMethod(shim.value()[0]); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, method.getName(), method.getDescriptor(), null, null); mv.visitCode(); int i = 0; mv.visitVarInsn(ALOAD, i++); for (Type argumentType : method.getArgumentTypes()) { mv.visitVarInsn(argumentType.getOpcode(ILOAD), i++); } mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), targetMethod.getName(), targetMethod.getDescriptor(), false); mv.visitInsn(method.getReturnType().getOpcode(IRETURN)); mv.visitMaxs(0, 0); mv.visitEnd(); } }
for (java.lang.reflect.Method shimMethod : shimType.shimMethods()) { Method method = Method.getMethod(shimMethod); shimMethods.add(method.getName() + method.getDescriptor());
IsEnabled.class, false, null, nestingGroup, suppressionKey); visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), isEnabledAdvice.getName(), isEnabledAdvice.getDescriptor(), false); if (otherEnabledFactorsDisabledEnd == null) {
String descriptor = "(Z" + onBeforeAdvice.getDescriptor().substring(1); visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onBeforeAdvice.getName(), descriptor, false); } else { visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onBeforeAdvice.getName(), onBeforeAdvice.getDescriptor(), false);
onThrowAdvice.getName(), onThrowAdvice.getDescriptor(), false); if (onThrowBlockEnd != null) { visitLabel(onThrowBlockEnd);
private void visitOnAfterAdvice(Advice advice, boolean insideCatchHandler) { Method onAfterAdvice = advice.onAfterAdvice(); if (onAfterAdvice == null) { return; } Integer enabledLocal = enabledLocals.get(advice); Label onAfterBlockEnd = null; if (enabledLocal != null) { onAfterBlockEnd = new Label(); loadLocal(enabledLocal); visitJumpInsn(IFEQ, onAfterBlockEnd); } loadMethodParameters(advice.onAfterParameters(), 0, travelerLocals.get(advice), advice.adviceType(), OnAfter.class, true, null, advice.pointcut().nestingGroup(), advice.pointcut().suppressionKey()); visitMethodInsn(INVOKESTATIC, advice.adviceType().getInternalName(), onAfterAdvice.getName(), onAfterAdvice.getDescriptor(), false); if (onAfterBlockEnd != null) { visitLabel(onAfterBlockEnd); // either inside catch handler or inside on return block if (insideCatchHandler) { visitImplicitFrame("java/lang/Throwable"); } else if (returnType.getSort() == Type.VOID) { visitImplicitFrame(); } else { visitImplicitFrame(convert(returnType)); } } }
/** * Generates an invoke method instruction. * * @param opcode the instruction's opcode. * @param type the class in which the method is defined. * @param method the method to be invoked. * @param isInterface whether the 'type' class is an interface or not. */ private void invokeInsn( final int opcode, final Type type, final Method method, final boolean isInterface) { String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName(); mv.visitMethodInsn(opcode, owner, method.getName(), method.getDescriptor(), isInterface); }
public CodeBuilder(int access, Method method, @Nullable Type[] exceptions, ClassVisitor cv) { this( access, method, cv.visitMethod( access, method.getName(), method.getDescriptor(), null /* generic signature */, getInternalNames(exceptions))); }
public CodeBuilder(int access, Method method, @Nullable Type[] exceptions, ClassVisitor cv) { this( access, method, cv.visitMethod( access, method.getName(), method.getDescriptor(), null /* generic signature */, getInternalNames(exceptions))); }
private static String print(Method method) { StringBuilder sb = new StringBuilder(); sb.append(print(method.getReturnType())).append(" ").append(method.getName()).append("("); for (Type t : method.getArgumentTypes()) { sb.append(print(t)).append(" "); } sb.append(")"); return sb.toString(); }
private BaseAdapter( org.objectweb.asm.commons.Method asmMethod, Method method) { this( method, asmMethod, ReflectorClassWriter.this.visitMethod( Opcodes.ACC_PUBLIC, asmMethod.getName(), asmMethod.getDescriptor(), null, ReflectorClassWriter.getInternalNames(method.getExceptionTypes()))); }
onReturnAdvice.getName(), onReturnAdvice.getDescriptor(), false); if (onReturnAdvice.getReturnType().getSort() != Type.VOID && opcode == RETURN) { pop();
/** * Returns a new {@link ConstructorRef} that refers to a constructor on the given type with the * given parameter types. */ public static ConstructorRef create(TypeInfo type, Method init) { checkArgument( init.getName().equals("<init>") && init.getReturnType().equals(Type.VOID_TYPE), "'%s' is not a valid constructor", init); return new AutoValue_ConstructorRef(type, init, ImmutableList.copyOf(init.getArgumentTypes())); }
/** * Returns a new {@link ConstructorRef} that refers to a constructor on the given type with the * given parameter types. */ public static ConstructorRef create(TypeInfo type, Method init) { checkArgument( init.getName().equals("<init>") && init.getReturnType().equals(Type.VOID_TYPE), "'%s' is not a valid constructor", init); return new AutoValue_ConstructorRef(type, init, ImmutableList.copyOf(init.getArgumentTypes())); }