private void emit_invoke(int opcode, Type type, Signature sig) { if (sig.getName().equals(Constants.CONSTRUCTOR_NAME) && ((opcode == Constants.INVOKEVIRTUAL) || (opcode == Constants.INVOKESTATIC))) { // TODO: error } mv.visitMethodInsn(opcode, type.getInternalName(), sig.getName(), sig.getDescriptor()); }
private Signature rename(Signature sig, int index) { return new Signature("CGLIB$" + sig.getName() + "$" + index, sig.getDescriptor()); }
public boolean equals(Object o) { if (o == null) return false; if (!(o instanceof MethodInfo)) return false; return getSignature().equals(((MethodInfo)o).getSignature()); }
public AddInitTransformer(Method method) { info = ReflectUtils.getMethodInfo(method); Type[] types = info.getSignature().getArgumentTypes(); if (types.length != 1 || !types[0].equals(Constants.TYPE_OBJECT) || !info.getSignature().getReturnType().equals(Type.VOID_TYPE)) { throw new IllegalArgumentException(method + " illegal signature"); } }
throw new IllegalStateException("classInfo is null! " + this); MethodVisitor v = cv.visitMethod(access, sig.getName(), sig.getDescriptor(), null, TypeUtils.toInternalNames(exceptions)); if (sig.equals(Constants.SIG_STATIC) && !TypeUtils.isInterface(getAccess())) { rawStaticInit = v; MethodVisitor wrapped = new MethodAdapter(v) { } else if (sig.equals(staticHookSig)) { return new CodeEmitter(this, v, access, sig, exceptions) { public boolean isStaticHook() {
/** * Return the name of the synthetic method created by CGLIB which is * used by {@link #invokeSuper} to invoke the superclass * (non-intercepted) method implementation. The parameter types are * the same as the proxied method. */ public String getSuperName() { return sig2.getName(); }
MethodInfo write = ReflectUtils.getMethodInfo(setter.getWriteMethod()); if (useConverter) { Type setterType = write.getSignature().getArgumentTypes()[0]; e.load_local(targetLocal); e.load_arg(2); e.load_local(sourceLocal); e.invoke(read); e.box(read.getSignature().getReturnType()); EmitUtils.load_class(e, setterType); e.push(write.getSignature().getName()); e.invoke_interface(CONVERTER, CONVERT); e.unbox_or_zero(setterType);
private Signature loadMethod(int index) { return new Signature("CGLIB$LOAD_PRIVATE_" + index, Constants.TYPE_OBJECT, Constants.TYPES_EMPTY); }
String methodProxyField = getMethodProxyField(impl); sigMap.put(sig.toString(), methodProxyField); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, methodField, METHOD, null); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, methodProxyField, METHOD_PROXY, null); e.getfield(methodField); if (sig.getArgumentTypes().length == 0) { e.getfield(EMPTY_ARGS_NAME); } else { e.unbox_or_zero(sig.getReturnType()); e.return_value();
public static void load_method(CodeEmitter e, MethodInfo method) { load_class(e, method.getClassInfo().getType()); e.push(method.getSignature().getName()); push_object(e, method.getSignature().getArgumentTypes()); e.invoke_virtual(Constants.TYPE_CLASS, GET_DECLARED_METHOD); }
public void generate(ClassEmitter ce, Context context, List methods) { for (Iterator it = methods.iterator(); it.hasNext();) { MethodInfo method = (MethodInfo)it.next(); Signature impl = context.getImplSignature(method); ce.declare_field(Constants.PRIVATE_FINAL_STATIC, impl.getName(), METHOD, null); CodeEmitter e = context.beginMethod(ce, method); Block handler = e.begin_block(); context.emitCallback(e, context.getIndex(method)); e.load_this(); e.getfield(impl.getName()); e.create_arg_array(); e.invoke_interface(INVOCATION_HANDLER, INVOKE); e.unbox(method.getSignature().getReturnType()); e.return_value(); handler.end(); EmitUtils.wrap_undeclared_throwable(e, handler, method.getExceptionTypes(), UNDECLARED_THROWABLE_EXCEPTION); e.end_method(); } }
State(ClassInfo classInfo, int access, Signature sig, Type[] exceptionTypes) { this.classInfo = classInfo; this.access = access; this.sig = sig; this.exceptionTypes = exceptionTypes; localOffset = TypeUtils.isStatic(access) ? 0 : 1; argumentTypes = sig.getArgumentTypes(); }
public Type getReturnType() { return state.sig.getReturnType(); }
CodeEmitter(ClassEmitter ce, MethodVisitor mv, int access, Signature sig, Type[] exceptionTypes) { super(access, sig.getDescriptor(), mv); this.ce = ce; state = new State(ce.getClassInfo(), access, sig, exceptionTypes); }
public String toString() { // TODO: include modifiers, exceptions return getSignature().toString(); } }
public int hashCode() { return getSignature().hashCode(); }
public AddStaticInitTransformer(Method classInit) { info = ReflectUtils.getMethodInfo(classInit); if (!TypeUtils.isStatic(info.getModifiers())) { throw new IllegalArgumentException(classInit + " is not static"); } Type[] types = info.getSignature().getArgumentTypes(); if (types.length != 1 || !types[0].equals(Constants.TYPE_CLASS) || !info.getSignature().getReturnType().equals(Type.VOID_TYPE)) { throw new IllegalArgumentException(classInit + " illegal signature"); } }
throw new IllegalStateException("classInfo is null! " + this); MethodVisitor v = cv.visitMethod(access, sig.getName(), sig.getDescriptor(), null, TypeUtils.toInternalNames(exceptions)); if (sig.equals(Constants.SIG_STATIC) && !TypeUtils.isInterface(getAccess())) { rawStaticInit = v; MethodVisitor wrapped = new MethodAdapter(v) { } else if (sig.equals(staticHookSig)) { return new CodeEmitter(this, v, access, sig, exceptions) { public boolean isStaticHook() {
private String getMethodField(Signature impl) { return impl.getName() + "$Method"; } private String getMethodProxyField(Signature impl) {
MethodInfo write = ReflectUtils.getMethodInfo(setter.getWriteMethod()); if (useConverter) { Type setterType = write.getSignature().getArgumentTypes()[0]; e.load_local(targetLocal); e.load_arg(2); e.load_local(sourceLocal); e.invoke(read); e.box(read.getSignature().getReturnType()); EmitUtils.load_class(e, setterType); e.push(write.getSignature().getName()); e.invoke_interface(CONVERTER, CONVERT); e.unbox_or_zero(setterType);