package net.sourceforge.javautil.interceptor.type.cjc;
import net.sourceforge.javautil.bytecode.api.IBytecodeReferenceable;
import net.sourceforge.javautil.bytecode.api.IBytecodeResolvable;
import net.sourceforge.javautil.bytecode.api.LiteralValue;
import net.sourceforge.javautil.bytecode.api.TypeDescriptor;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeBlock;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeContextMethod;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeLocalVariableDeclaration;
import net.sourceforge.javautil.bytecode.api.type.method.instructions.ExceptionHandler;
import net.sourceforge.javautil.bytecode.api.type.method.instructions.TryCatchFinalBase;
import net.sourceforge.javautil.bytecode.api.type.method.invocation.MethodInvocation;
import net.sourceforge.javautil.common.CollectionUtil;
import net.sourceforge.javautil.interceptor.InterceptorCompiler;
import net.sourceforge.javautil.interceptor.asm.InterceptorHelper;
/**
* This is the generated method for use with concrete class proxies.
*
* @author elponderador
* @author $Author$
* @version $Id$
*
* @see InterceptorCompiler
*/
public class InterceptorProxyMethod extends TryCatchFinalBase {
public InterceptorProxyMethod () {
this.addExceptionHandler(new ProxyMethodExceptionHandler());
}
@Override protected void writeLogic(BytecodeContextMethod context) {
IBytecodeResolvable helper = context.resolve(InterceptorHelper.class);
context.returnValue( context.getThisField("interceptor").createInvocation(context, "invoke", context.resolve("this"),
context.createInvocation(helper, "findMethod",
context.createInvocation(context.resolve("this"), "getClass"),
new LiteralValue(context.getMethod().getName() + "$$"),
context.getThisField("cache"),
new LiteralValue(context.getMethod().getDescriptor().toDescriptorString())
),
context.initializeArray(context.resolve(Object.class), context.getMethodArguments())
));
}
/**
* The exception handler for {@link InterceptorProxyMethod}'s.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class ProxyMethodExceptionHandler extends ExceptionHandler {
public ProxyMethodExceptionHandler() {
super(TypeDescriptor.getFor(RuntimeException.class), "e");
}
@Override protected void writeHandler(BytecodeContextMethod context) {
context.throwException(
context.createNewInstanceInvocation(context.resolve(RuntimeException.class), context.resolve("e"))
);
}
}
}