Program: 12280
Project: 12280
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.getQualifiedName().equals(sourceTypeDeclaration.resolveBinding().getQualifiedName()) && (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression)) {
        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;
          if (invoker.getExpression() == null || invoker.getExpression() instanceof ThisExpression) {
            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) {
          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);
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  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().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>();
  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.getQualifiedName().equals(sourceTypeDeclaration.resolveBinding().getQualifiedName()) && (methodInvocation.getExpression() == null || methodInvocation.getExpression() instanceof ThisExpression)) {
        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;
          if (invoker.getExpression() == null || invoker.getExpression() instanceof ThisExpression) {
            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() && sourceTypeDeclaration.resolveBinding().equals(variableBinding.getDeclaringClass()) && (variableBinding.getModifiers() & Modifier.STATIC) == 0) {
        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);
      }
    }
    i++;
  }
  SimpleName parameterName=null;
  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().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++;
  }
}