if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Too many dispatch() methods found in " + superClass.getName());
}
for (int i = 0 ; i < superDispatches.length ; i++)
{
CtMethod wrapperMethod = ReflectToJavassist.methodToJavassist(cinfo.getWrappingMethod());
CtClass[] params = wrapperMethod.getParameterTypes();
StringBuffer parameters = new StringBuffer("(");
if (superDispatches[i].getParameterTypes().length == 0)
{
//This is the no params version called by invokeNext() for around advices
for (int j = 0 ; j < params.length ; j++)
{
if (j > 0)parameters.append(", ");
parameters.append("arg" + j);
}
}
else
{
//This is the no parameterized version called by invokeJoinPoint() when there are no around advices
int offset = (hasCallingObject()) ? 1 : 0;
for (int j = 0 ; j < params.length ; j++)
{
if (j > 0)parameters.append(", ");
parameters.append("$" + (j + offset + 1));
}
}
parameters.append(")");
String body =
"{ return " + cinfo.getConstructor().getDeclaringClass().getName() + "." + cinfo.getWrappingMethod().getName() + parameters + ";}";
try
{
CtMethod dispatch = CtNewMethod.make(
superDispatches[i].getReturnType(),
superDispatches[i].getName(),
superDispatches[i].getParameterTypes(),
superDispatches[i].getExceptionTypes(),
body,
clazz);
dispatch.setModifiers(superDispatches[i].getModifiers());
clazz.addMethod(dispatch);
}
catch (CannotCompileException e)
{
throw new RuntimeException("Could not compile code " + body + " for method " + getMethodString(clazz, superDispatches[i].getName(), superDispatches[i].getParameterTypes()), e);