Program: 12257
Project: 12257
Buggy source:
private void createMovedMethod(){
  AST ast=targetTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=(MethodDeclaration)ASTNode.copySubtree(ast,sourceMethod);
  ListRewrite modifierRewrite=targetRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier publicModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  boolean modifierFound=false;
  List<Modifier> modifiers=newMethodDeclaration.modifiers();
  for (  Modifier modifier : modifiers) {
    if (modifier.getKeyword().equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD)) {
      modifierFound=true;
    }
 else     if (modifier.getKeyword().equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD) || modifier.getKeyword().equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD)) {
      modifierFound=true;
      modifierRewrite.replace(modifier,publicModifier,null);
    }
  }
  if (!modifierFound) {
    modifierRewrite.insertFirst(publicModifier,null);
  }
  ListRewrite parametersRewrite=targetRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  List<SingleVariableDeclaration> sourceMethodParameters=sourceMethod.parameters();
  List<SingleVariableDeclaration> newMethodParameters=newMethodDeclaration.parameters();
  int i=0;
  for (  SingleVariableDeclaration parameter : sourceMethodParameters) {
    ITypeBinding parameterTypeBinding=parameter.getType().resolveBinding();
    if (parameterTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
      targetClassVariableName=parameter.getName().getIdentifier();
      parametersRewrite.remove(newMethodParameters.get(i),null);
      break;
    }
    i++;
  }
  if (targetClassVariableName == null) {
    FieldDeclaration[] fieldDeclarations=sourceTypeDeclaration.getFields();
    for (    FieldDeclaration fieldDeclaration : fieldDeclarations) {
      List<VariableDeclarationFragment> fragments=fieldDeclaration.fragments();
      for (      VariableDeclarationFragment fragment : fragments) {
        if (fieldDeclaration.getType().resolveBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
          targetClassVariableName=fragment.getName().getIdentifier();
          break;
        }
      }
    }
  }
  modifySourceMemberAccessesInTargetClass(newMethodDeclaration);
  if (targetClassVariableName != null) {
    modifyTargetMethodInvocations(newMethodDeclaration);
    modifyTargetPublicFieldInstructions(newMethodDeclaration);
  }
  modifySourceStaticFieldInstructionsInTargetClass(newMethodDeclaration);
  modifySourceStaticMethodInvocationsInTargetClass(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInMethodInvocationArguments(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInVariableDeclarationInitializers(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInInfixExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInCastExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInInstanceofExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInAssignments(newMethodDeclaration);
  replaceThisExpressionWithSourceClassParameterInMethodInvocationArguments(newMethodDeclaration);
  replaceThisExpressionWithSourceClassParameterInVariableDeclarationInitializers(newMethodDeclaration);
  ListRewrite targetClassBodyRewrite=targetRewriter.getListRewrite(targetTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  targetClassBodyRewrite.insertLast(newMethodDeclaration,null);
}

Fixed version (ground truth):
private void createMovedMethod(){
  AST ast=targetTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=(MethodDeclaration)ASTNode.copySubtree(ast,sourceMethod);
  ListRewrite modifierRewrite=targetRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier publicModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  boolean modifierFound=false;
  List<Modifier> modifiers=newMethodDeclaration.modifiers();
  for (  Modifier modifier : modifiers) {
    if (modifier.getKeyword().equals(Modifier.ModifierKeyword.PUBLIC_KEYWORD)) {
      modifierFound=true;
    }
 else     if (modifier.getKeyword().equals(Modifier.ModifierKeyword.PRIVATE_KEYWORD) || modifier.getKeyword().equals(Modifier.ModifierKeyword.PROTECTED_KEYWORD)) {
      modifierFound=true;
      modifierRewrite.replace(modifier,publicModifier,null);
    }
  }
  if (!modifierFound) {
    modifierRewrite.insertFirst(publicModifier,null);
  }
  ListRewrite parametersRewrite=targetRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  List<SingleVariableDeclaration> sourceMethodParameters=sourceMethod.parameters();
  List<SingleVariableDeclaration> newMethodParameters=newMethodDeclaration.parameters();
  int i=0;
  for (  SingleVariableDeclaration parameter : sourceMethodParameters) {
    ITypeBinding parameterTypeBinding=parameter.getType().resolveBinding();
    if (parameterTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
      targetClassVariableName=parameter.getName().getIdentifier();
      parametersRewrite.remove(newMethodParameters.get(i),null);
      break;
    }
    i++;
  }
  if (targetClassVariableName == null) {
    ExpressionExtractor expressionExtractor=new ExpressionExtractor();
    List<Expression> newVariableInstructions=expressionExtractor.getVariableInstructions(newMethodDeclaration.getBody());
    FieldDeclaration[] fieldDeclarations=sourceTypeDeclaration.getFields();
    for (    FieldDeclaration fieldDeclaration : fieldDeclarations) {
      List<VariableDeclarationFragment> fragments=fieldDeclaration.fragments();
      for (      VariableDeclarationFragment fragment : fragments) {
        if (fieldDeclaration.getType().resolveBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
          for (          Expression expression : newVariableInstructions) {
            SimpleName simpleName=(SimpleName)expression;
            if (fragment.getName().getIdentifier().equals(simpleName.getIdentifier())) {
              targetClassVariableName=fragment.getName().getIdentifier();
              break;
            }
          }
          if (targetClassVariableName != null)           break;
        }
      }
      if (targetClassVariableName != null)       break;
    }
  }
  modifySourceMemberAccessesInTargetClass(newMethodDeclaration);
  if (targetClassVariableName != null) {
    modifyTargetMethodInvocations(newMethodDeclaration);
    modifyTargetPublicFieldInstructions(newMethodDeclaration);
  }
  modifySourceStaticFieldInstructionsInTargetClass(newMethodDeclaration);
  modifySourceStaticMethodInvocationsInTargetClass(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInMethodInvocationArguments(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInVariableDeclarationInitializers(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInInfixExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInCastExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInInstanceofExpressions(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInAssignments(newMethodDeclaration);
  replaceThisExpressionWithSourceClassParameterInMethodInvocationArguments(newMethodDeclaration);
  replaceThisExpressionWithSourceClassParameterInVariableDeclarationInitializers(newMethodDeclaration);
  ListRewrite targetClassBodyRewrite=targetRewriter.getListRewrite(targetTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  targetClassBodyRewrite.insertLast(newMethodDeclaration,null);
}