TransformMethod incrementer = transformation.getOrCreateMethod(new TransformMethodSignature(
Modifier.PUBLIC, "int", "incrementer", new String[]
{ "int" }, null));
final MethodAccess incrementerAccess = incrementer.getAccess();
TransformMethodSignature operateSig = new TransformMethodSignature(Modifier.PUBLIC, "int", "operate",
new String[]
{ "int" }, null);
TransformMethod operate = transformation.getOrCreateMethod(operateSig);
operate.addAdvice(new ComponentMethodAdvice()
{
public void advise(ComponentMethodInvocation invocation)
{
// This advice *replaces* the original do-nothing method, because
// it never calls invocation.proceed().
// This kind of advice always needs some special knowledge of
// the parameters to the original method, so that they can be mapped
// to some other method (including a MethodAccess).
Integer parameter = (Integer) invocation.getParameter(0);
MethodInvocationResult result = incrementerAccess.invoke(invocation.getInstance(), parameter);
invocation.overrideResult(result.getReturnValue());
}
});
}