Program: 12277
Project: 12277
Buggy source:
private void modifySourceMemberAccessesInTargetClass(MethodDeclaration newMethodDeclaration){
  ExpressionExtractor extractor=new ExpressionExtractor();
  List<Expression> sourceMethodInvocations=extractor.getMethodInvocations(sourceMethod.getBody());
  List<Expression> newMethodInvocations=extractor.getMethodInvocations(newMethodDeclaration.getBody());
  List<Expression> expressionsToBeRemoved=new ArrayList<Expression>();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      ITypeBinding methodInvocationDeclaringClassTypeBinding=methodInvocation.resolveMethodBinding().getDeclaringClass();
      if (methodInvocationDeclaringClassTypeBinding.getQualifiedName().equals(sourceTypeDeclaration.resolveBinding().getQualifiedName())) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
            MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
            if (delegation != null) {
              ITypeBinding delegationDeclaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
              if (delegationDeclaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
                if (delegation.getExpression() != null) {
                  MethodInvocation newMethodInvocation=(MethodInvocation)ASTNode.copySubtree(newMethodDeclaration.getAST(),delegation);
                  targetRewriter.remove(newMethodInvocation.getExpression(),null);
                  targetRewriter.replace(newMethodInvocations.get(k),newMethodInvocation,null);
                }
                expressionsToBeRemoved.add(methodInvocation);
              }
            }
          }
        }
      }
 else       if (methodInvocationDeclaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName()) && methodInvocation.getExpression() != null) {
        Expression methodInvocationExpression=methodInvocation.getExpression();
        if (methodInvocationExpression instanceof MethodInvocation) {
          MethodInvocation invoker=(MethodInvocation)methodInvocationExpression;
          MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
          for (          MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
            if (identicalSignature(sourceMethodDeclaration,invoker)) {
              SimpleName fieldInstruction=isGetter(sourceMethodDeclaration);
              if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
                int index=sourceMethodInvocations.indexOf(invoker);
                targetRewriter.remove(newMethodInvocations.get(index),null);
                expressionsToBeRemoved.add(invoker);
                expressionsToBeRemoved.add(methodInvocation);
              }
            }
          }
        }
      }
    }
    k++;
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  List<Expression> sourceFieldInstructions=extractor.getVariableInstructions(sourceMethod.getBody());
  List<Expression> newFieldInstructions=extractor.getVariableInstructions(newMethodDeclaration.getBody());
  int i=0;
  for (  Expression expression : sourceFieldInstructions) {
    SimpleName simpleName=(SimpleName)expression;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      if (variableBinding.isField() && variableBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding()) && (variableBinding.getModifiers() & Modifier.STATIC) == 0) {
        SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
        if (expressionName.getParent() instanceof FieldAccess) {
          if (expressionName.getIdentifier().equals(targetClassVariableName))           targetRewriter.remove(expressionName.getParent(),null);
 else           targetRewriter.replace(expressionName.getParent(),expressionName,null);
        }
 else {
          if (expressionName.getIdentifier().equals(targetClassVariableName))           targetRewriter.remove(expressionName,null);
        }
        if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))         addParameterToMovedMethod(newMethodDeclaration,expressionName);
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  int j=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
      if (methodBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding())) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
            SimpleName fieldName=isGetter(sourceMethodDeclaration);
            MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(j);
            if (fieldName != null) {
              AST ast=newMethodDeclaration.getAST();
              targetRewriter.replace(newMethodInvocation,ast.newSimpleName(fieldName.getIdentifier()),null);
              if (!fieldName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(fieldName.getIdentifier()))               addParameterToMovedMethod(newMethodDeclaration,fieldName);
            }
 else {
              if (!additionalArgumentsAddedToMovedMethod.contains("String_Node_Str")) {
                parameterName=addSourceClassParameterToMovedMethod(newMethodDeclaration);
              }
              targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
              setPublicModifierToSourceMethod(methodInvocation);
            }
          }
        }
      }
    }
    j++;
  }
}

Fixed version (ground truth):
private void modifySourceMemberAccessesInTargetClass(MethodDeclaration newMethodDeclaration){
  ExpressionExtractor extractor=new ExpressionExtractor();
  List<Expression> sourceMethodInvocations=extractor.getMethodInvocations(sourceMethod.getBody());
  List<Expression> newMethodInvocations=extractor.getMethodInvocations(newMethodDeclaration.getBody());
  List<Expression> expressionsToBeRemoved=new ArrayList<Expression>();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      ITypeBinding methodInvocationDeclaringClassTypeBinding=methodInvocation.resolveMethodBinding().getDeclaringClass();
      if (methodInvocationDeclaringClassTypeBinding.getQualifiedName().equals(sourceTypeDeclaration.resolveBinding().getQualifiedName())) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
            MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
            if (delegation != null) {
              ITypeBinding delegationDeclaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
              if (delegationDeclaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
                if (delegation.getExpression() != null) {
                  MethodInvocation newMethodInvocation=(MethodInvocation)ASTNode.copySubtree(newMethodDeclaration.getAST(),delegation);
                  targetRewriter.remove(newMethodInvocation.getExpression(),null);
                  targetRewriter.replace(newMethodInvocations.get(k),newMethodInvocation,null);
                }
                expressionsToBeRemoved.add(methodInvocation);
              }
            }
          }
        }
      }
 else       if (methodInvocationDeclaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName()) && methodInvocation.getExpression() != null) {
        Expression methodInvocationExpression=methodInvocation.getExpression();
        if (methodInvocationExpression instanceof MethodInvocation) {
          MethodInvocation invoker=(MethodInvocation)methodInvocationExpression;
          MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
          for (          MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
            if (identicalSignature(sourceMethodDeclaration,invoker)) {
              SimpleName fieldInstruction=isGetter(sourceMethodDeclaration);
              if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
                int index=sourceMethodInvocations.indexOf(invoker);
                targetRewriter.remove(newMethodInvocations.get(index),null);
                expressionsToBeRemoved.add(invoker);
                expressionsToBeRemoved.add(methodInvocation);
              }
            }
          }
        }
      }
    }
    k++;
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  List<Expression> sourceFieldInstructions=extractor.getVariableInstructions(sourceMethod.getBody());
  List<Expression> newFieldInstructions=extractor.getVariableInstructions(newMethodDeclaration.getBody());
  int i=0;
  for (  Expression expression : sourceFieldInstructions) {
    SimpleName simpleName=(SimpleName)expression;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      if (variableBinding.isField() && variableBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding()) && (variableBinding.getModifiers() & Modifier.STATIC) == 0) {
        SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
        if (expressionName.getParent() instanceof FieldAccess && !expressionName.getIdentifier().equals(targetClassVariableName)) {
          targetRewriter.replace(expressionName.getParent(),expressionName,null);
        }
        if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))         addParameterToMovedMethod(newMethodDeclaration,expressionName);
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  int j=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
      if (methodBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding())) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
            SimpleName fieldName=isGetter(sourceMethodDeclaration);
            MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(j);
            if (fieldName != null) {
              AST ast=newMethodDeclaration.getAST();
              targetRewriter.replace(newMethodInvocation,ast.newSimpleName(fieldName.getIdentifier()),null);
              if (!fieldName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(fieldName.getIdentifier()))               addParameterToMovedMethod(newMethodDeclaration,fieldName);
            }
 else {
              if (!additionalArgumentsAddedToMovedMethod.contains("String_Node_Str")) {
                parameterName=addSourceClassParameterToMovedMethod(newMethodDeclaration);
              }
              targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
              setPublicModifierToSourceMethod(methodInvocation);
            }
          }
        }
      }
    }
    j++;
  }
}