Program: 12187
Project: 12187
Buggy source:
private void modifyClient(){
  AST clientAST=sourceTypeDeclaration.getAST();
  Block typeCheckCodeFragmentParentBlock=(Block)typeCheckElimination.getTypeCheckCodeFragment().getParent();
  ListRewrite typeCheckCodeFragmentParentBlockStatementsRewrite=sourceRewriter.getListRewrite(typeCheckCodeFragmentParentBlock,Block.STATEMENTS_PROPERTY);
  if (returnedVariable == null && !typeCheckElimination.typeCheckCodeFragmentContainsReturnStatement()) {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable().getName();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      if (!abstractMethodParameter.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
      }
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    ExpressionStatement expressionStatement=clientAST.newExpressionStatement(abstractMethodInvocation);
    typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
  }
 else {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable().getName();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    if (returnedVariable != null) {
      if (returnedVariable instanceof SingleVariableDeclaration) {
        SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariable;
        methodInvocationArgumentsRewrite.insertLast(singleVariableDeclaration.getName(),null);
      }
 else       if (returnedVariable instanceof VariableDeclarationFragment) {
        VariableDeclarationFragment variableDeclarationFragment=(VariableDeclarationFragment)returnedVariable;
        methodInvocationArgumentsRewrite.insertLast(variableDeclarationFragment.getName(),null);
      }
    }
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      if (!abstractMethodParameter.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
      }
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    if (returnedVariable != null) {
      Assignment assignment=clientAST.newAssignment();
      sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
      sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariable.getName(),null);
      sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,abstractMethodInvocation,null);
      ExpressionStatement expressionStatement=clientAST.newExpressionStatement(assignment);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
    }
 else {
      ReturnStatement returnStatement=clientAST.newReturnStatement();
      sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,abstractMethodInvocation,null);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),returnStatement,null);
    }
  }
  generateGettersForAccessedFields();
  generateSettersForAssignedFields();
  setPublicModifierToAccessedMethods();
  ITextFileBufferManager bufferManager=FileBuffers.getTextFileBufferManager();
  ITextFileBuffer sourceTextFileBuffer=bufferManager.getTextFileBuffer(sourceFile.getFullPath(),LocationKind.IFILE);
  IDocument sourceDocument=sourceTextFileBuffer.getDocument();
  TextEdit sourceEdit=sourceRewriter.rewriteAST(sourceDocument,null);
  try {
    UndoEdit sourceUndoEdit=sourceEdit.apply(sourceDocument,UndoEdit.CREATE_UNDO);
    undoRefactoring.put(sourceFile,sourceDocument,sourceUndoEdit);
  }
 catch (  MalformedTreeException e) {
    e.printStackTrace();
  }
catch (  BadLocationException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void modifyClient(){
  AST clientAST=sourceTypeDeclaration.getAST();
  Block typeCheckCodeFragmentParentBlock=(Block)typeCheckElimination.getTypeCheckCodeFragment().getParent();
  ListRewrite typeCheckCodeFragmentParentBlockStatementsRewrite=sourceRewriter.getListRewrite(typeCheckCodeFragmentParentBlock,Block.STATEMENTS_PROPERTY);
  if (returnedVariable == null && !typeCheckElimination.typeCheckCodeFragmentContainsReturnStatement()) {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariable.getName(),null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      if (!abstractMethodParameter.equals(returnedVariable) && !abstractMethodParameter.equals(typeVariable)) {
        methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
      }
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable) && !fragment.equals(typeVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    ExpressionStatement expressionStatement=clientAST.newExpressionStatement(abstractMethodInvocation);
    typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
  }
 else {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariable.getName(),null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    if (returnedVariable != null) {
      if (returnedVariable instanceof SingleVariableDeclaration) {
        SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariable;
        methodInvocationArgumentsRewrite.insertLast(singleVariableDeclaration.getName(),null);
      }
 else       if (returnedVariable instanceof VariableDeclarationFragment) {
        VariableDeclarationFragment variableDeclarationFragment=(VariableDeclarationFragment)returnedVariable;
        methodInvocationArgumentsRewrite.insertLast(variableDeclarationFragment.getName(),null);
      }
    }
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      if (!abstractMethodParameter.equals(returnedVariable) && !abstractMethodParameter.equals(typeVariable)) {
        methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
      }
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable) && !fragment.equals(typeVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    if (returnedVariable != null) {
      Assignment assignment=clientAST.newAssignment();
      sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
      sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariable.getName(),null);
      sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,abstractMethodInvocation,null);
      ExpressionStatement expressionStatement=clientAST.newExpressionStatement(assignment);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
    }
 else {
      ReturnStatement returnStatement=clientAST.newReturnStatement();
      sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,abstractMethodInvocation,null);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),returnStatement,null);
    }
  }
  generateGettersForAccessedFields();
  generateSettersForAssignedFields();
  setPublicModifierToAccessedMethods();
  ITextFileBufferManager bufferManager=FileBuffers.getTextFileBufferManager();
  ITextFileBuffer sourceTextFileBuffer=bufferManager.getTextFileBuffer(sourceFile.getFullPath(),LocationKind.IFILE);
  IDocument sourceDocument=sourceTextFileBuffer.getDocument();
  TextEdit sourceEdit=sourceRewriter.rewriteAST(sourceDocument,null);
  try {
    UndoEdit sourceUndoEdit=sourceEdit.apply(sourceDocument,UndoEdit.CREATE_UNDO);
    undoRefactoring.put(sourceFile,sourceDocument,sourceUndoEdit);
  }
 catch (  MalformedTreeException e) {
    e.printStackTrace();
  }
catch (  BadLocationException e) {
    e.printStackTrace();
  }
}