Program: 12225
Project: 12225
Buggy source:
private void createMovedMethod(){
  AST ast=targetTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=(MethodDeclaration)ASTNode.copySubtree(ast,sourceMethod);
  targetRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(movedMethodName),null);
  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();
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> newVariableInstructions=expressionExtractor.getVariableInstructions(newMethodDeclaration.getBody());
  int i=0;
  for (  SingleVariableDeclaration parameter : sourceMethodParameters) {
    ITypeBinding parameterTypeBinding=parameter.getType().resolveBinding();
    if (parameterTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
      for (      Expression expression : newVariableInstructions) {
        SimpleName simpleName=(SimpleName)expression;
        if (parameter.getName().getIdentifier().equals(simpleName.getIdentifier())) {
          targetClassVariableName=parameter.getName().getIdentifier();
          parametersRewrite.remove(newMethodParameters.get(i),null);
          isTargetClassVariableParameter=true;
          break;
        }
      }
      if (targetClassVariableName != null)       break;
    }
    i++;
  }
  FieldDeclaration[] fieldDeclarations=sourceTypeDeclaration.getFields();
  if (targetClassVariableName == null) {
    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;
    }
  }
  List<Expression> oldMethodInvocations=expressionExtractor.getMethodInvocations(sourceMethod.getBody());
  MethodDeclaration[] methodDeclarations=sourceTypeDeclaration.getMethods();
  if (targetClassVariableName == null) {
    for (    Expression oldMethodInvocation : oldMethodInvocations) {
      if (oldMethodInvocation instanceof MethodInvocation) {
        MethodInvocation methodInvocation=(MethodInvocation)oldMethodInvocation;
        if (methodInvocation.resolveMethodBinding().getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          for (          MethodDeclaration methodDeclaration : methodDeclarations) {
            if (methodInvocation.resolveMethodBinding().isEqualTo(methodDeclaration.resolveBinding())) {
              SimpleName fieldInstruction=MethodDeclarationUtility.isGetter(methodDeclaration);
              if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                targetClassVariableName=fieldInstruction.getIdentifier();
                break;
              }
            }
          }
          if (targetClassVariableName != null)           break;
        }
      }
    }
  }
  if (targetClassVariableName == null) {
    for (    Expression oldMethodInvocation : oldMethodInvocations) {
      if (oldMethodInvocation instanceof MethodInvocation) {
        MethodInvocation methodInvocation=(MethodInvocation)oldMethodInvocation;
        if (methodInvocation.resolveMethodBinding().getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          for (          MethodDeclaration methodDeclaration : methodDeclarations) {
            if (methodInvocation.resolveMethodBinding().isEqualTo(methodDeclaration.resolveBinding())) {
              MethodInvocation delegation=MethodDeclarationUtility.isDelegate(methodDeclaration);
              if (delegation != null && delegation.resolveMethodBinding().getDeclaringClass().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                List<Expression> delegateMethodVariableInstructions=expressionExtractor.getVariableInstructions(methodDeclaration.getBody());
                for (                Expression expression : delegateMethodVariableInstructions) {
                  SimpleName fieldInstruction=(SimpleName)expression;
                  IBinding fieldInstructionBinding=fieldInstruction.resolveBinding();
                  if (fieldInstructionBinding.getKind() == IBinding.VARIABLE) {
                    IVariableBinding fieldInstructionVariableBinding=(IVariableBinding)fieldInstructionBinding;
                    if (fieldInstructionVariableBinding.isField() && fieldInstructionVariableBinding.getType().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                      targetClassVariableName=fieldInstruction.getIdentifier();
                      break;
                    }
                  }
                }
                if (targetClassVariableName != null)                 break;
              }
            }
          }
          if (targetClassVariableName != null)           break;
        }
      }
    }
  }
  if (targetClassVariableName == null) {
    for (    FieldDeclaration fieldDeclaration : fieldDeclarations) {
      List<VariableDeclarationFragment> fragments=fieldDeclaration.fragments();
      for (      VariableDeclarationFragment fragment : fragments) {
        if (targetTypeDeclaration.resolveBinding().isEqualTo(fieldDeclaration.getType().resolveBinding().getSuperclass())) {
          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);
  replaceTargetClassVariableNameWithThisExpressionInClassInstanceCreationArguments(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);
  targetRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(movedMethodName),null);
  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();
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> newVariableInstructions=expressionExtractor.getVariableInstructions(newMethodDeclaration.getBody());
  int i=0;
  for (  SingleVariableDeclaration parameter : sourceMethodParameters) {
    ITypeBinding parameterTypeBinding=parameter.getType().resolveBinding();
    if (parameterTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
      for (      Expression expression : newVariableInstructions) {
        SimpleName simpleName=(SimpleName)expression;
        if (parameter.getName().getIdentifier().equals(simpleName.getIdentifier())) {
          targetClassVariableName=parameter.getName().getIdentifier();
          parametersRewrite.remove(newMethodParameters.get(i),null);
          isTargetClassVariableParameter=true;
          break;
        }
      }
      if (targetClassVariableName != null)       break;
    }
    i++;
  }
  FieldDeclaration[] fieldDeclarations=sourceTypeDeclaration.getFields();
  if (targetClassVariableName == null) {
    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;
    }
  }
  List<Expression> oldMethodInvocations=expressionExtractor.getMethodInvocations(sourceMethod.getBody());
  MethodDeclaration[] methodDeclarations=sourceTypeDeclaration.getMethods();
  if (targetClassVariableName == null) {
    for (    Expression oldMethodInvocation : oldMethodInvocations) {
      if (oldMethodInvocation instanceof MethodInvocation) {
        MethodInvocation methodInvocation=(MethodInvocation)oldMethodInvocation;
        if (methodInvocation.resolveMethodBinding().getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          for (          MethodDeclaration methodDeclaration : methodDeclarations) {
            if (methodInvocation.resolveMethodBinding().isEqualTo(methodDeclaration.resolveBinding())) {
              SimpleName fieldInstruction=MethodDeclarationUtility.isGetter(methodDeclaration);
              if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                targetClassVariableName=fieldInstruction.getIdentifier();
                break;
              }
            }
          }
          if (targetClassVariableName != null)           break;
        }
      }
    }
  }
  if (targetClassVariableName == null) {
    for (    Expression oldMethodInvocation : oldMethodInvocations) {
      if (oldMethodInvocation instanceof MethodInvocation) {
        MethodInvocation methodInvocation=(MethodInvocation)oldMethodInvocation;
        if (methodInvocation.resolveMethodBinding().getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          for (          MethodDeclaration methodDeclaration : methodDeclarations) {
            if (methodInvocation.resolveMethodBinding().isEqualTo(methodDeclaration.resolveBinding())) {
              MethodInvocation delegation=MethodDeclarationUtility.isDelegate(methodDeclaration);
              if (delegation != null && delegation.resolveMethodBinding().getDeclaringClass().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                List<Expression> delegateMethodVariableInstructions=expressionExtractor.getVariableInstructions(methodDeclaration.getBody());
                for (                Expression expression : delegateMethodVariableInstructions) {
                  SimpleName fieldInstruction=(SimpleName)expression;
                  IBinding fieldInstructionBinding=fieldInstruction.resolveBinding();
                  if (fieldInstructionBinding.getKind() == IBinding.VARIABLE) {
                    IVariableBinding fieldInstructionVariableBinding=(IVariableBinding)fieldInstructionBinding;
                    if (fieldInstructionVariableBinding.isField() && fieldInstructionVariableBinding.getType().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                      targetClassVariableName=fieldInstruction.getIdentifier();
                      break;
                    }
                  }
                }
                if (targetClassVariableName != null)                 break;
              }
            }
          }
          if (targetClassVariableName != null)           break;
        }
      }
    }
  }
  if (targetClassVariableName == null) {
    for (    FieldDeclaration fieldDeclaration : fieldDeclarations) {
      List<VariableDeclarationFragment> fragments=fieldDeclaration.fragments();
      for (      VariableDeclarationFragment fragment : fragments) {
        if (targetTypeDeclaration.resolveBinding().isEqualTo(fieldDeclaration.getType().resolveBinding().getSuperclass())) {
          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);
  modifyRecursiveMethodInvocationsOfTheMovedMethod(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInMethodInvocationArguments(newMethodDeclaration);
  replaceTargetClassVariableNameWithThisExpressionInClassInstanceCreationArguments(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);
}