Program: 12131
Project: 12131
Buggy source:
private void extractMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion().getName();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  Type returnedVariableType=null;
  if (returnedVariableDeclaration instanceof SingleVariableDeclaration) {
    SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariableDeclaration;
    returnedVariableType=singleVariableDeclaration.getType();
  }
 else   if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment fragment=(VariableDeclarationFragment)returnedVariableDeclaration;
    if (fragment.getParent() instanceof VariableDeclarationStatement) {
      VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
      returnedVariableType=variableDeclarationStatement.getType();
    }
 else     if (fragment.getParent() instanceof VariableDeclarationExpression) {
      VariableDeclarationExpression variableDeclarationExpression=(VariableDeclarationExpression)fragment.getParent();
      returnedVariableType=variableDeclarationExpression.getType();
    }
 else     if (fragment.getParent() instanceof FieldDeclaration) {
      FieldDeclaration fieldDeclaration=(FieldDeclaration)fragment.getParent();
      returnedVariableType=fieldDeclaration.getType();
    }
  }
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier accessModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(accessModifier,null);
  if ((sourceMethodDeclaration.getModifiers() & Modifier.STATIC) != 0) {
    Modifier staticModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
    modifierRewrite.insertLast(staticModifier,null);
  }
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    Type variableType=null;
    if (variableDeclaration instanceof SingleVariableDeclaration) {
      SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)variableDeclaration;
      variableType=singleVariableDeclaration.getType();
    }
 else     if (variableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment fragment=(VariableDeclarationFragment)variableDeclaration;
      if (fragment.getParent() instanceof VariableDeclarationStatement) {
        VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
        variableType=variableDeclarationStatement.getType();
      }
 else       if (fragment.getParent() instanceof VariableDeclarationExpression) {
        VariableDeclarationExpression variableDeclarationExpression=(VariableDeclarationExpression)fragment.getParent();
        variableType=variableDeclarationExpression.getType();
      }
 else       if (fragment.getParent() instanceof FieldDeclaration) {
        FieldDeclaration fieldDeclaration=(FieldDeclaration)fragment.getParent();
        variableType=fieldDeclaration.getType();
      }
    }
    if (!variableDeclaration.resolveBinding().isField()) {
      SingleVariableDeclaration parameter=ast.newSingleVariableDeclaration();
      sourceRewriter.set(parameter,SingleVariableDeclaration.NAME_PROPERTY,variableDeclaration.getName(),null);
      sourceRewriter.set(parameter,SingleVariableDeclaration.TYPE_PROPERTY,variableType,null);
      parameterRewrite.insertLast(parameter,null);
    }
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite bodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  List<CFGBranchDoLoopNode> doLoopNodes=new ArrayList<CFGBranchDoLoopNode>();
  for (  PDGNode pdgNode : sliceNodes) {
    CFGNode cfgNode=pdgNode.getCFGNode();
    if (cfgNode instanceof CFGBranchDoLoopNode) {
      CFGBranchDoLoopNode cfgDoLoopNode=(CFGBranchDoLoopNode)cfgNode;
      doLoopNodes.add(cfgDoLoopNode);
    }
  }
  while (!sliceNodes.isEmpty()) {
    PDGNode node=sliceNodes.get(0);
    if (node instanceof PDGStatementNode) {
      boolean nodeIsInsideDoLoop=false;
      for (      CFGBranchDoLoopNode doLoopNode : doLoopNodes) {
        if (node.getId() >= doLoopNode.getJoinNode().getId() && node.getId() < doLoopNode.getId()) {
          nodeIsInsideDoLoop=true;
          PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)doLoopNode.getPDGNode();
          if (sliceNodes.contains(predicateNode)) {
            bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
            break;
          }
        }
      }
      if (!nodeIsInsideDoLoop) {
        bodyRewrite.insertLast(node.getASTStatement(),null);
        sliceNodes.remove(node);
      }
    }
 else     if (node instanceof PDGControlPredicateNode) {
      PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
      bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
    }
  }
  ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
  sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
  bodyRewrite.insertLast(returnStatement,null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.BODY_PROPERTY,newMethodBody,null);
  ListRewrite methodDeclarationRewrite=sourceRewriter.getListRewrite(sourceTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  methodDeclarationRewrite.insertAfter(newMethodDeclaration,sourceMethodDeclaration,null);
  try {
    TextEdit sourceEdit=sourceRewriter.rewriteAST();
    root.addChild(sourceEdit);
    compilationUnitChange.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void extractMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion().getName();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  Type returnedVariableType=null;
  if (returnedVariableDeclaration instanceof SingleVariableDeclaration) {
    SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariableDeclaration;
    returnedVariableType=singleVariableDeclaration.getType();
  }
 else   if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment fragment=(VariableDeclarationFragment)returnedVariableDeclaration;
    if (fragment.getParent() instanceof VariableDeclarationStatement) {
      VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
      returnedVariableType=variableDeclarationStatement.getType();
    }
 else     if (fragment.getParent() instanceof VariableDeclarationExpression) {
      VariableDeclarationExpression variableDeclarationExpression=(VariableDeclarationExpression)fragment.getParent();
      returnedVariableType=variableDeclarationExpression.getType();
    }
 else     if (fragment.getParent() instanceof FieldDeclaration) {
      FieldDeclaration fieldDeclaration=(FieldDeclaration)fragment.getParent();
      returnedVariableType=fieldDeclaration.getType();
    }
  }
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  IVariableBinding returnedVariableBinding=returnedVariableDeclaration.resolveBinding();
  if (slice.isObjectSlice() && (returnedVariableBinding.isField() || returnedVariableBinding.isParameter() || !slice.declarationOfVariableCriterionBelongsToSliceNodes()))   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,ast.newPrimitiveType(PrimitiveType.VOID),null);
 else   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier accessModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(accessModifier,null);
  if ((sourceMethodDeclaration.getModifiers() & Modifier.STATIC) != 0) {
    Modifier staticModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
    modifierRewrite.insertLast(staticModifier,null);
  }
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    Type variableType=null;
    if (variableDeclaration instanceof SingleVariableDeclaration) {
      SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)variableDeclaration;
      variableType=singleVariableDeclaration.getType();
    }
 else     if (variableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment fragment=(VariableDeclarationFragment)variableDeclaration;
      if (fragment.getParent() instanceof VariableDeclarationStatement) {
        VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
        variableType=variableDeclarationStatement.getType();
      }
 else       if (fragment.getParent() instanceof VariableDeclarationExpression) {
        VariableDeclarationExpression variableDeclarationExpression=(VariableDeclarationExpression)fragment.getParent();
        variableType=variableDeclarationExpression.getType();
      }
 else       if (fragment.getParent() instanceof FieldDeclaration) {
        FieldDeclaration fieldDeclaration=(FieldDeclaration)fragment.getParent();
        variableType=fieldDeclaration.getType();
      }
    }
    if (!variableDeclaration.resolveBinding().isField()) {
      SingleVariableDeclaration parameter=ast.newSingleVariableDeclaration();
      sourceRewriter.set(parameter,SingleVariableDeclaration.NAME_PROPERTY,variableDeclaration.getName(),null);
      sourceRewriter.set(parameter,SingleVariableDeclaration.TYPE_PROPERTY,variableType,null);
      parameterRewrite.insertLast(parameter,null);
    }
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite bodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  List<CFGBranchDoLoopNode> doLoopNodes=new ArrayList<CFGBranchDoLoopNode>();
  for (  PDGNode pdgNode : sliceNodes) {
    CFGNode cfgNode=pdgNode.getCFGNode();
    if (cfgNode instanceof CFGBranchDoLoopNode) {
      CFGBranchDoLoopNode cfgDoLoopNode=(CFGBranchDoLoopNode)cfgNode;
      doLoopNodes.add(cfgDoLoopNode);
    }
  }
  while (!sliceNodes.isEmpty()) {
    PDGNode node=sliceNodes.get(0);
    if (node instanceof PDGStatementNode) {
      boolean nodeIsInsideDoLoop=false;
      for (      CFGBranchDoLoopNode doLoopNode : doLoopNodes) {
        if (node.getId() >= doLoopNode.getJoinNode().getId() && node.getId() < doLoopNode.getId()) {
          nodeIsInsideDoLoop=true;
          PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)doLoopNode.getPDGNode();
          if (sliceNodes.contains(predicateNode)) {
            bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
            break;
          }
        }
      }
      if (!nodeIsInsideDoLoop) {
        bodyRewrite.insertLast(node.getASTStatement(),null);
        sliceNodes.remove(node);
      }
    }
 else     if (node instanceof PDGControlPredicateNode) {
      PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
      bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
    }
  }
  if (!slice.isObjectSlice() || (!returnedVariableBinding.isField() && !returnedVariableBinding.isParameter() && slice.declarationOfVariableCriterionBelongsToSliceNodes())) {
    ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
    sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
    bodyRewrite.insertLast(returnStatement,null);
  }
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.BODY_PROPERTY,newMethodBody,null);
  ListRewrite methodDeclarationRewrite=sourceRewriter.getListRewrite(sourceTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  methodDeclarationRewrite.insertAfter(newMethodDeclaration,sourceMethodDeclaration,null);
  try {
    TextEdit sourceEdit=sourceRewriter.rewriteAST();
    root.addChild(sourceEdit);
    compilationUnitChange.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
}