Program: 12218
Project: 12218
Buggy source:
private void addRequiredTargetImportDeclarations(){
  List<ITypeBinding> typeBindings=new ArrayList<ITypeBinding>();
  Type returnType=sourceMethod.getReturnType2();
  ITypeBinding returnTypeBinding=returnType.resolveBinding();
  if (!typeBindings.contains(returnTypeBinding))   typeBindings.add(returnTypeBinding);
  List<SingleVariableDeclaration> parameters=sourceMethod.parameters();
  for (  SingleVariableDeclaration parameter : parameters) {
    Type parameterType=parameter.getType();
    ITypeBinding parameterTypeBinding=parameterType.resolveBinding();
    if (!typeBindings.contains(parameterTypeBinding))     typeBindings.add(parameterTypeBinding);
  }
  List<Name> thrownExceptions=sourceMethod.thrownExceptions();
  for (  Name name : thrownExceptions) {
    IBinding binding=name.resolveBinding();
    if (binding.getKind() == IBinding.TYPE) {
      ITypeBinding typeBinding=(ITypeBinding)binding;
      if (!typeBindings.contains(typeBinding))       typeBindings.add(typeBinding);
    }
  }
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> variableInstructions=expressionExtractor.getVariableInstructions(sourceMethod.getBody());
  for (  Expression variableInstruction : variableInstructions) {
    SimpleName simpleName=(SimpleName)variableInstruction;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      ITypeBinding variableTypeBinding=variableBinding.getType();
      if (!typeBindings.contains(variableTypeBinding))       typeBindings.add(variableTypeBinding);
      ITypeBinding declaringClassTypeBinding=variableBinding.getDeclaringClass();
      if (declaringClassTypeBinding != null && !typeBindings.contains(declaringClassTypeBinding))       typeBindings.add(declaringClassTypeBinding);
    }
  }
  List<Expression> methodInvocations=expressionExtractor.getMethodInvocations(sourceMethod.getBody());
  for (  Expression expression : methodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      if (!additionalMethodsToBeMoved.keySet().contains(methodInvocation)) {
        IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
        ITypeBinding declaringClassTypeBinding=methodBinding.getDeclaringClass();
        if (declaringClassTypeBinding != null && !typeBindings.contains(declaringClassTypeBinding))         typeBindings.add(declaringClassTypeBinding);
      }
    }
  }
  List<Expression> classInstanceCreations=expressionExtractor.getClassInstanceCreations(sourceMethod.getBody());
  for (  Expression expression : classInstanceCreations) {
    ClassInstanceCreation classInstanceCreation=(ClassInstanceCreation)expression;
    Type classInstanceCreationType=classInstanceCreation.getType();
    ITypeBinding classInstanceCreationTypeBinding=classInstanceCreationType.resolveBinding();
    if (!typeBindings.contains(classInstanceCreationTypeBinding))     typeBindings.add(classInstanceCreationTypeBinding);
  }
  List<Expression> typeLiterals=expressionExtractor.getTypeLiterals(sourceMethod.getBody());
  for (  Expression expression : typeLiterals) {
    TypeLiteral typeLiteral=(TypeLiteral)expression;
    Type typeLiteralType=typeLiteral.getType();
    ITypeBinding typeLiteralTypeBinding=typeLiteralType.resolveBinding();
    if (!typeBindings.contains(typeLiteralTypeBinding))     typeBindings.add(typeLiteralTypeBinding);
  }
  List<Expression> castExpressions=expressionExtractor.getCastExpressions(sourceMethod.getBody());
  for (  Expression expression : castExpressions) {
    CastExpression castExpression=(CastExpression)expression;
    Type castExpressionType=castExpression.getType();
    ITypeBinding typeLiteralTypeBinding=castExpressionType.resolveBinding();
    if (!typeBindings.contains(typeLiteralTypeBinding))     typeBindings.add(typeLiteralTypeBinding);
  }
  getSimpleTypeBindings(typeBindings);
  for (  ITypeBinding typeBinding : requiredTargetImportDeclarationSet)   addImportDeclaration(typeBinding);
}

Fixed version (ground truth):
private void addRequiredTargetImportDeclarations(){
  List<ITypeBinding> typeBindings=new ArrayList<ITypeBinding>();
  Type returnType=sourceMethod.getReturnType2();
  ITypeBinding returnTypeBinding=returnType.resolveBinding();
  if (!typeBindings.contains(returnTypeBinding))   typeBindings.add(returnTypeBinding);
  List<SingleVariableDeclaration> parameters=sourceMethod.parameters();
  for (  SingleVariableDeclaration parameter : parameters) {
    Type parameterType=parameter.getType();
    ITypeBinding parameterTypeBinding=parameterType.resolveBinding();
    if (!typeBindings.contains(parameterTypeBinding))     typeBindings.add(parameterTypeBinding);
  }
  List<Name> thrownExceptions=sourceMethod.thrownExceptions();
  for (  Name name : thrownExceptions) {
    IBinding binding=name.resolveBinding();
    if (binding.getKind() == IBinding.TYPE) {
      ITypeBinding typeBinding=(ITypeBinding)binding;
      if (!typeBindings.contains(typeBinding))       typeBindings.add(typeBinding);
    }
  }
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  List<Expression> variableInstructions=expressionExtractor.getVariableInstructions(sourceMethod.getBody());
  for (  Expression variableInstruction : variableInstructions) {
    SimpleName simpleName=(SimpleName)variableInstruction;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      ITypeBinding variableTypeBinding=variableBinding.getType();
      if (!typeBindings.contains(variableTypeBinding))       typeBindings.add(variableTypeBinding);
      ITypeBinding declaringClassTypeBinding=variableBinding.getDeclaringClass();
      if (declaringClassTypeBinding != null && !typeBindings.contains(declaringClassTypeBinding))       typeBindings.add(declaringClassTypeBinding);
    }
  }
  List<Expression> methodInvocations=expressionExtractor.getMethodInvocations(sourceMethod.getBody());
  for (  Expression expression : methodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      if (!additionalMethodsToBeMoved.keySet().contains(methodInvocation)) {
        IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
        ITypeBinding declaringClassTypeBinding=methodBinding.getDeclaringClass();
        if (declaringClassTypeBinding != null && !typeBindings.contains(declaringClassTypeBinding))         typeBindings.add(declaringClassTypeBinding);
        ITypeBinding superclassTypeBinding=sourceTypeDeclaration.resolveBinding().getSuperclass();
        while (superclassTypeBinding != null && !superclassTypeBinding.isEqualTo(methodBinding.getDeclaringClass())) {
          superclassTypeBinding=superclassTypeBinding.getSuperclass();
        }
        if (methodBinding.getDeclaringClass().isEqualTo(superclassTypeBinding) && !typeBindings.contains(sourceTypeDeclaration.resolveBinding()))         typeBindings.add(sourceTypeDeclaration.resolveBinding());
      }
    }
  }
  List<Expression> classInstanceCreations=expressionExtractor.getClassInstanceCreations(sourceMethod.getBody());
  for (  Expression expression : classInstanceCreations) {
    ClassInstanceCreation classInstanceCreation=(ClassInstanceCreation)expression;
    Type classInstanceCreationType=classInstanceCreation.getType();
    ITypeBinding classInstanceCreationTypeBinding=classInstanceCreationType.resolveBinding();
    if (!typeBindings.contains(classInstanceCreationTypeBinding))     typeBindings.add(classInstanceCreationTypeBinding);
  }
  List<Expression> typeLiterals=expressionExtractor.getTypeLiterals(sourceMethod.getBody());
  for (  Expression expression : typeLiterals) {
    TypeLiteral typeLiteral=(TypeLiteral)expression;
    Type typeLiteralType=typeLiteral.getType();
    ITypeBinding typeLiteralTypeBinding=typeLiteralType.resolveBinding();
    if (!typeBindings.contains(typeLiteralTypeBinding))     typeBindings.add(typeLiteralTypeBinding);
  }
  List<Expression> castExpressions=expressionExtractor.getCastExpressions(sourceMethod.getBody());
  for (  Expression expression : castExpressions) {
    CastExpression castExpression=(CastExpression)expression;
    Type castExpressionType=castExpression.getType();
    ITypeBinding typeLiteralTypeBinding=castExpressionType.resolveBinding();
    if (!typeBindings.contains(typeLiteralTypeBinding))     typeBindings.add(typeLiteralTypeBinding);
  }
  getSimpleTypeBindings(typeBindings);
  for (  ITypeBinding typeBinding : requiredTargetImportDeclarationSet)   addImportDeclaration(typeBinding);
}