JimpleClassBuilder invokerClass = context.getJimpleOutput().newClass();
invokerClass.setClassName(invokerName);
invokerClass.addInterface(getInterfaceName(method));
JimpleMethodBuilder applyMethod = invokerClass.newMethod();
applyMethod.setModifiers(JimpleModifiers.PUBLIC);
applyMethod.setName("apply");
applyMethod.setReturnType(method.getReturnType());
int paramIndex = 0;
for (JimpleType type : method.getParameterTypes()) {
applyMethod.addParameter(type, "p" + paramIndex);
paramIndex++;
}
StringBuilder call = new StringBuilder();
call.append("staticinvoke ").append(method.signature()).append("(");
for (paramIndex = 0; paramIndex != method.getParameterTypes().size(); ++paramIndex) {
if (paramIndex > 0) {
call.append(", ");
}
call.append("p").append(paramIndex);
}
call.append(")");
if (method.getReturnType().toString().equals("void")) {
applyMethod.addStatement(call.toString());
applyMethod.addStatement("return");
} else {
applyMethod.addVarDecl(method.getReturnType(), "_retval");
applyMethod.addStatement("_retval = " + call.toString());
applyMethod.addStatement("return _retval");
}
}
return invokerName;
}