Program: 12255
Project: 12255
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>();
  for (  MethodInvocation methodInvocation : additionalMethodsToBeMoved.keySet()) {
    for (    Expression expression : sourceMethodInvocations) {
      if (expression instanceof MethodInvocation) {
        MethodInvocation sourceMethodInvocation=(MethodInvocation)expression;
        if (methodInvocation.equals(sourceMethodInvocation)) {
          expressionsToBeRemoved.add(methodInvocation);
        }
      }
    }
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  expressionsToBeRemoved.clear();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      ITypeBinding methodInvocationDeclaringClassTypeBinding=methodInvocation.resolveMethodBinding().getDeclaringClass();
      if (methodInvocationDeclaringClassTypeBinding.isEqualTo(sourceTypeDeclaration.resolveBinding()) && (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression)) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (sourceMethodDeclaration.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding())) {
            MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
            if (delegation != null) {
              ITypeBinding delegationDeclaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
              if (delegationDeclaringClassTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
                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.isEqualTo(targetTypeDeclaration.resolveBinding()) && methodInvocation.getExpression() != null) {
        Expression methodInvocationExpression=methodInvocation.getExpression();
        if (methodInvocationExpression instanceof MethodInvocation) {
          MethodInvocation invoker=(MethodInvocation)methodInvocationExpression;
          if (invoker.getExpression() == null || invoker.getExpression() instanceof ThisExpression) {
            MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
            for (            MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
              if (sourceMethodDeclaration.resolveBinding().isEqualTo(invoker.resolveMethodBinding())) {
                SimpleName fieldInstruction=isGetter(sourceMethodDeclaration);
                if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                  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.getModifiers() & Modifier.STATIC) == 0) {
        if (sourceTypeDeclaration.resolveBinding().isEqualTo(variableBinding.getDeclaringClass())) {
          SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
          if (expressionName.getParent() instanceof FieldAccess) {
            FieldAccess fieldAccess=(FieldAccess)expressionName.getParent();
            if (fieldAccess.getExpression() instanceof ThisExpression && !expressionName.getIdentifier().equals(targetClassVariableName)) {
              targetRewriter.replace(expressionName.getParent(),expressionName,null);
              if (!additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))               addParameterToMovedMethod(newMethodDeclaration,expressionName);
            }
          }
 else           if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))           addParameterToMovedMethod(newMethodDeclaration,expressionName);
        }
 else {
          Type superclassType=sourceTypeDeclaration.getSuperclassType();
          ITypeBinding superclassTypeBinding=null;
          if (superclassType != null)           superclassTypeBinding=superclassType.resolveBinding();
          while (superclassTypeBinding != null && !variableBinding.getDeclaringClass().isEqualTo(superclassTypeBinding)) {
            superclassTypeBinding=superclassTypeBinding.getSuperclass();
          }
          if (superclassTypeBinding != null) {
            IVariableBinding[] superclassFieldBindings=superclassTypeBinding.getDeclaredFields();
            for (            IVariableBinding superclassFieldBinding : superclassFieldBindings) {
              if (superclassFieldBinding.isEqualTo(variableBinding)) {
                SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
                if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))                 addParameterToMovedMethod(newMethodDeclaration,variableBinding);
              }
            }
          }
        }
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  Set<String> sourceMethodsWithPublicModifier=new LinkedHashSet<String>();
  int j=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      if (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression) {
        IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
        if (methodBinding.getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
          for (          MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
            if (sourceMethodDeclaration.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding()) && !sourceMethod.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding())) {
              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);
                if (!sourceMethodsWithPublicModifier.contains(methodInvocation.resolveMethodBinding().toString())) {
                  setPublicModifierToSourceMethod(methodInvocation);
                  sourceMethodsWithPublicModifier.add(methodInvocation.resolveMethodBinding().toString());
                }
              }
            }
          }
        }
 else {
          Type superclassType=sourceTypeDeclaration.getSuperclassType();
          ITypeBinding superclassTypeBinding=null;
          if (superclassType != null)           superclassTypeBinding=superclassType.resolveBinding();
          while (superclassTypeBinding != null && !methodBinding.getDeclaringClass().isEqualTo(superclassTypeBinding)) {
            superclassTypeBinding=superclassTypeBinding.getSuperclass();
          }
          if (superclassTypeBinding != null) {
            IMethodBinding[] superclassMethodBindings=superclassTypeBinding.getDeclaredMethods();
            for (            IMethodBinding superclassMethodBinding : superclassMethodBindings) {
              if (superclassMethodBinding.isEqualTo(methodBinding)) {
                MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(j);
                if (!additionalArgumentsAddedToMovedMethod.contains("String_Node_Str")) {
                  parameterName=addSourceClassParameterToMovedMethod(newMethodDeclaration);
                }
                targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
              }
            }
          }
        }
      }
    }
    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>();
  for (  MethodInvocation methodInvocation : additionalMethodsToBeMoved.keySet()) {
    for (    Expression expression : sourceMethodInvocations) {
      if (expression instanceof MethodInvocation) {
        MethodInvocation sourceMethodInvocation=(MethodInvocation)expression;
        if (methodInvocation.equals(sourceMethodInvocation)) {
          expressionsToBeRemoved.add(methodInvocation);
        }
      }
    }
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  expressionsToBeRemoved.clear();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      ITypeBinding methodInvocationDeclaringClassTypeBinding=methodInvocation.resolveMethodBinding().getDeclaringClass();
      if (methodInvocationDeclaringClassTypeBinding.isEqualTo(sourceTypeDeclaration.resolveBinding()) && (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression)) {
        MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
        for (        MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
          if (sourceMethodDeclaration.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding())) {
            MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
            if (delegation != null) {
              ITypeBinding delegationDeclaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
              if (delegationDeclaringClassTypeBinding.isEqualTo(targetTypeDeclaration.resolveBinding())) {
                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.isEqualTo(targetTypeDeclaration.resolveBinding()) && methodInvocation.getExpression() != null) {
        Expression methodInvocationExpression=methodInvocation.getExpression();
        if (methodInvocationExpression instanceof MethodInvocation) {
          MethodInvocation invoker=(MethodInvocation)methodInvocationExpression;
          if (invoker.getExpression() == null || invoker.getExpression() instanceof ThisExpression) {
            MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
            for (            MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
              if (sourceMethodDeclaration.resolveBinding().isEqualTo(invoker.resolveMethodBinding())) {
                SimpleName fieldInstruction=isGetter(sourceMethodDeclaration);
                if (fieldInstruction != null && fieldInstruction.resolveTypeBinding().isEqualTo(targetTypeDeclaration.resolveBinding())) {
                  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.getModifiers() & Modifier.STATIC) == 0) {
        if (sourceTypeDeclaration.resolveBinding().isEqualTo(variableBinding.getDeclaringClass())) {
          SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
          if (expressionName.getParent() instanceof FieldAccess) {
            FieldAccess fieldAccess=(FieldAccess)expressionName.getParent();
            if (fieldAccess.getExpression() instanceof ThisExpression && !expressionName.getIdentifier().equals(targetClassVariableName)) {
              targetRewriter.replace(expressionName.getParent(),expressionName,null);
              if (!additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))               addParameterToMovedMethod(newMethodDeclaration,expressionName);
            }
          }
 else           if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))           addParameterToMovedMethod(newMethodDeclaration,expressionName);
        }
 else {
          Type superclassType=sourceTypeDeclaration.getSuperclassType();
          ITypeBinding superclassTypeBinding=null;
          if (superclassType != null)           superclassTypeBinding=superclassType.resolveBinding();
          while (superclassTypeBinding != null && !superclassTypeBinding.isEqualTo(variableBinding.getDeclaringClass())) {
            superclassTypeBinding=superclassTypeBinding.getSuperclass();
          }
          if (superclassTypeBinding != null) {
            IVariableBinding[] superclassFieldBindings=superclassTypeBinding.getDeclaredFields();
            for (            IVariableBinding superclassFieldBinding : superclassFieldBindings) {
              if (superclassFieldBinding.isEqualTo(variableBinding)) {
                SimpleName expressionName=(SimpleName)newFieldInstructions.get(i);
                if (!expressionName.getIdentifier().equals(targetClassVariableName) && !additionalArgumentsAddedToMovedMethod.contains(expressionName.getIdentifier()))                 addParameterToMovedMethod(newMethodDeclaration,variableBinding);
              }
            }
          }
        }
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  Set<String> sourceMethodsWithPublicModifier=new LinkedHashSet<String>();
  int j=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      if (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression) {
        IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
        if (methodBinding.getDeclaringClass().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
          MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
          for (          MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
            if (sourceMethodDeclaration.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding()) && !sourceMethod.resolveBinding().isEqualTo(methodInvocation.resolveMethodBinding())) {
              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);
                if (!sourceMethodsWithPublicModifier.contains(methodInvocation.resolveMethodBinding().toString())) {
                  setPublicModifierToSourceMethod(methodInvocation);
                  sourceMethodsWithPublicModifier.add(methodInvocation.resolveMethodBinding().toString());
                }
              }
            }
          }
        }
 else {
          Type superclassType=sourceTypeDeclaration.getSuperclassType();
          ITypeBinding superclassTypeBinding=null;
          if (superclassType != null)           superclassTypeBinding=superclassType.resolveBinding();
          while (superclassTypeBinding != null && !methodBinding.getDeclaringClass().isEqualTo(superclassTypeBinding)) {
            superclassTypeBinding=superclassTypeBinding.getSuperclass();
          }
          if (superclassTypeBinding != null) {
            IMethodBinding[] superclassMethodBindings=superclassTypeBinding.getDeclaredMethods();
            for (            IMethodBinding superclassMethodBinding : superclassMethodBindings) {
              if (superclassMethodBinding.isEqualTo(methodBinding)) {
                MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(j);
                if (!additionalArgumentsAddedToMovedMethod.contains("String_Node_Str")) {
                  parameterName=addSourceClassParameterToMovedMethod(newMethodDeclaration);
                }
                targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
              }
            }
          }
        }
      }
    }
    j++;
  }
}