JProgram program = x.getProgram();
JMethod newMethod = new JMethod(program, sourceInfo, newName,
enclosingType, returnType, false, true, true, x.isPrivate());
// Setup parameters; map from the old params to the new params
JParameter thisParam = program.createParameter(null,
"this$static".toCharArray(), enclosingType, true, true, newMethod);
Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
for (int i = 0; i < x.params.size(); ++i) {
JParameter oldVar = x.params.get(i);
JParameter newVar = program.createParameter(oldVar.getSourceInfo(),
oldVar.getName().toCharArray(), oldVar.getType(), oldVar.isFinal(),
false, newMethod);
varMap.put(oldVar, newVar);
}
// Set the new original param types based on the old original param types
List<JType> originalParamTypes = new ArrayList<JType>();
originalParamTypes.add(enclosingType);
originalParamTypes.addAll(x.getOriginalParamTypes());
newMethod.setOriginalParamTypes(originalParamTypes);
// Move the body of the instance method to the static method
JAbstractMethodBody movedBody = x.getBody();
newMethod.setBody(movedBody);
// Create a new body for the instance method that delegates to the static
JMethodBody newBody = new JMethodBody(program, sourceInfo);
x.setBody(newBody);
JMethodCall newCall = new JMethodCall(program, sourceInfo, null,
newMethod);
newCall.getArgs().add(program.getExprThisRef(sourceInfo, enclosingType));
for (int i = 0; i < x.params.size(); ++i) {
JParameter param = x.params.get(i);
newCall.getArgs().add(new JParameterRef(program, sourceInfo, param));
}
JStatement statement;
if (returnType == program.getTypeVoid()) {
statement = newCall.makeStatement();