Program: 12130
Project: 12130
Buggy source:
private void modifySourceMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceMethodDeclaration.getAST();
  MethodInvocation extractedMethodInvocation=ast.newMethodInvocation();
  sourceRewriter.set(extractedMethodInvocation,MethodInvocation.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  ListRewrite argumentRewrite=sourceRewriter.getListRewrite(extractedMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    if (!variableDeclaration.resolveBinding().isField())     argumentRewrite.insertLast(variableDeclaration.getName(),null);
  }
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion().getName();
  if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclarationFragment initializationFragment=ast.newVariableDeclarationFragment();
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
    VariableDeclarationStatement initializationVariableDeclarationStatement=ast.newVariableDeclarationStatement(initializationFragment);
    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(initializationVariableDeclarationStatement,VariableDeclarationStatement.TYPE_PROPERTY,returnedVariableType,null);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(initializationVariableDeclarationStatement,extractedMethodInvocationInsertionStatement,null);
  }
 else   if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && !slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment oldInitializationFragment=(VariableDeclarationFragment)returnedVariableDeclaration;
      VariableDeclarationFragment newInitializationFragment=ast.newVariableDeclarationFragment();
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
      if (oldInitializationFragment.getParent() instanceof VariableDeclarationStatement) {
        VariableDeclarationStatement oldVariableDeclarationStatement=(VariableDeclarationStatement)oldInitializationFragment.getParent();
        List<VariableDeclarationFragment> oldFragments=oldVariableDeclarationStatement.fragments();
        ListRewrite fragmentRewrite=sourceRewriter.getListRewrite(oldVariableDeclarationStatement,VariableDeclarationStatement.FRAGMENTS_PROPERTY);
        for (int i=0; i < oldFragments.size(); i++) {
          if (oldInitializationFragment.equals(oldFragments.get(i)))           fragmentRewrite.replace(oldFragments.get(i),newInitializationFragment,null);
        }
      }
 else       if (oldInitializationFragment.getParent() instanceof VariableDeclarationExpression) {
        VariableDeclarationExpression oldVariableDeclarationExpression=(VariableDeclarationExpression)oldInitializationFragment.getParent();
        List<VariableDeclarationFragment> oldFragments=oldVariableDeclarationExpression.fragments();
        ListRewrite fragmentRewrite=sourceRewriter.getListRewrite(oldVariableDeclarationExpression,VariableDeclarationExpression.FRAGMENTS_PROPERTY);
        for (int i=0; i < oldFragments.size(); i++) {
          if (oldInitializationFragment.equals(oldFragments.get(i)))           fragmentRewrite.replace(oldFragments.get(i),newInitializationFragment,null);
        }
      }
    }
  }
 else {
    Assignment assignment=ast.newAssignment();
    sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariableDeclaration.getName(),null);
    sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,extractedMethodInvocation,null);
    ExpressionStatement expressionStatement=ast.newExpressionStatement(assignment);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(expressionStatement,extractedMethodInvocationInsertionStatement,null);
  }
  for (  Statement removableStatement : slice.getRemovableStatements()) {
    sourceRewriter.remove(removableStatement,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 modifySourceMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceMethodDeclaration.getAST();
  MethodInvocation extractedMethodInvocation=ast.newMethodInvocation();
  sourceRewriter.set(extractedMethodInvocation,MethodInvocation.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  ListRewrite argumentRewrite=sourceRewriter.getListRewrite(extractedMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    if (!variableDeclaration.resolveBinding().isField())     argumentRewrite.insertLast(variableDeclaration.getName(),null);
  }
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion().getName();
  if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclarationFragment initializationFragment=ast.newVariableDeclarationFragment();
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
    VariableDeclarationStatement initializationVariableDeclarationStatement=ast.newVariableDeclarationStatement(initializationFragment);
    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(initializationVariableDeclarationStatement,VariableDeclarationStatement.TYPE_PROPERTY,returnedVariableType,null);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(initializationVariableDeclarationStatement,extractedMethodInvocationInsertionStatement,null);
  }
 else   if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && !slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment oldInitializationFragment=(VariableDeclarationFragment)returnedVariableDeclaration;
      VariableDeclarationFragment newInitializationFragment=ast.newVariableDeclarationFragment();
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
      if (oldInitializationFragment.getParent() instanceof VariableDeclarationStatement) {
        VariableDeclarationStatement oldVariableDeclarationStatement=(VariableDeclarationStatement)oldInitializationFragment.getParent();
        List<VariableDeclarationFragment> oldFragments=oldVariableDeclarationStatement.fragments();
        ListRewrite fragmentRewrite=sourceRewriter.getListRewrite(oldVariableDeclarationStatement,VariableDeclarationStatement.FRAGMENTS_PROPERTY);
        for (int i=0; i < oldFragments.size(); i++) {
          if (oldInitializationFragment.equals(oldFragments.get(i)))           fragmentRewrite.replace(oldFragments.get(i),newInitializationFragment,null);
        }
      }
 else       if (oldInitializationFragment.getParent() instanceof VariableDeclarationExpression) {
        VariableDeclarationExpression oldVariableDeclarationExpression=(VariableDeclarationExpression)oldInitializationFragment.getParent();
        List<VariableDeclarationFragment> oldFragments=oldVariableDeclarationExpression.fragments();
        ListRewrite fragmentRewrite=sourceRewriter.getListRewrite(oldVariableDeclarationExpression,VariableDeclarationExpression.FRAGMENTS_PROPERTY);
        for (int i=0; i < oldFragments.size(); i++) {
          if (oldInitializationFragment.equals(oldFragments.get(i)))           fragmentRewrite.replace(oldFragments.get(i),newInitializationFragment,null);
        }
      }
    }
  }
 else {
    if (!slice.isObjectSlice()) {
      Assignment assignment=ast.newAssignment();
      sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariableDeclaration.getName(),null);
      sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,extractedMethodInvocation,null);
      ExpressionStatement expressionStatement=ast.newExpressionStatement(assignment);
      Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
      Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
      ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
      blockRewrite.insertBefore(expressionStatement,extractedMethodInvocationInsertionStatement,null);
    }
 else {
      ExpressionStatement expressionStatement=ast.newExpressionStatement(extractedMethodInvocation);
      Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
      Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
      ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
      blockRewrite.insertBefore(expressionStatement,extractedMethodInvocationInsertionStatement,null);
    }
  }
  for (  Statement removableStatement : slice.getRemovableStatements()) {
    sourceRewriter.remove(removableStatement,null);
  }
  try {
    TextEdit sourceEdit=sourceRewriter.rewriteAST();
    root.addChild(sourceEdit);
    compilationUnitChange.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
}