anotherChange.addTextEditGroup(inlineReplacementEdit);
anotherChange.addTextEditGroup(additionalInlineReplacementEdit);
AST ast = fProgram.getAST();
MethodDeclaration method = ast.newMethodDeclaration();
Block extractedMethodBody = ast.newBlock();
FunctionDeclaration functionDec = ast.newFunctionDeclaration(ast.newIdentifier(fMethodName), computeArguments(ast), extractedMethodBody, false);
method.setModifier(fModifierAccessFlag);
method.setFunction(functionDec);
ASTRewrite rewriter = ASTRewrite.create(ast);
ListRewrite classListRewrite = rewriter.getListRewrite( fCoveringDeclarationFinder.getCoveringClassDeclaration().getBody(), Block.STATEMENTS_PROPERTY);
VariableBase dispatcher = ast.newVariable(THIS_VARIABLE_NAME);
FunctionInvocation calledExtractedMethod = ast.newFunctionInvocation(ast.newFunctionName(ast.newIdentifier(fMethodName)), computeParameters(ast));
MethodInvocation inlineMethodCall = ast.newMethodInvocation(dispatcher, calledExtractedMethod);
List<List<ASTNode>> Occurences = new ArrayList<List<ASTNode>>();
if(fReplaceDuplicates) {
for(Match replace : fDuplicates) {
Occurences.add(Arrays.asList(replace.getNodes()));
}
} else {
Occurences.add(fSelectedNodesFinder.getNodes());
}
boolean createdMethodBody = false;
TextEditGroup inlineReplacementEditGroup = inlineReplacementEdit;
for(List<ASTNode> selectedNodeOccurence : Occurences) {
// this is also an indicator, whether this loop was already gone through
if(createdMethodBody) {
inlineReplacementEditGroup = additionalInlineReplacementEdit;
}
ASTNode parent = selectedNodeOccurence.get(0).getParent();
inlineMethodCall = ASTNode.copySubtree(ast, inlineMethodCall);
ListRewrite lrw;
if(parent instanceof Block) {
if(!createdMethodBody) {
extractedMethodBody.statements().addAll(ASTNode.copySubtrees(ast, selectedNodeOccurence));
addReturnStatement(ast, extractedMethodBody, fReturnStatement);
createdMethodBody = true;
}
lrw = rewriter.getListRewrite(parent, Block.STATEMENTS_PROPERTY);