// Move the body of the instance method to the static method
JAbstractMethodBody movedBody = x.getBody();
newMethod.setBody(movedBody);
JMethodBody newBody = new JMethodBody(sourceInfo);
x.setBody(newBody);
JMethodCall newCall = new JMethodCall(sourceInfo, null, newMethod);
newCall.addArg(new JThisRef(sourceInfo, enclosingType));
for (int i = 0; i < x.getParams().size(); ++i) {
JParameter param = x.getParams().get(i);
newCall.addArg(new JParameterRef(sourceInfo, param));
}
JStatement statement;
if (returnType == program.getTypeVoid()) {
statement = newCall.makeStatement();
} else {
statement = new JReturnStatement(sourceInfo, newCall);
}
newBody.getBlock().addStmt(statement);
/*
* Rewrite the method body. Update all thisRefs to paramRefs. Update
* paramRefs and localRefs to target the params/locals in the new method.
*/