Bug 102846 [quick fix] Convert to enhanced for loop does not remove obsolete import
I20050627-1435 (3.1) The 'Convert to enhanced for loop' quick fix does not remove the obsolete import java.util.Iterator in this example: import java.util.Iterator; import java.util.List; public class Try { public static void print(List<String> names) { for (Iterator iter= names.iterator(); iter.hasNext();) { String name= (String) iter.next(); System.out.println(name); } } }
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ConvertIterableLoopProposal.java
final ITypeBinding binding= fIterator.getType();
		if (binding != null && binding.isParameterizedType())
			name= binding.getTypeArguments()[0].getName();
		final List excluded= getExcludedNames();
		final String[] suggestions= StubUtility.getLocalNameSuggestions(project, name, 0, (String[]) excluded.toArray(new String[excluded.size()]));
		for (int index= 0; index < suggestions.length; index++)
			names.add(suggestions[index]);
		return names;
	}
	private List getExcludedNames() {
		final CompilationUnit unit= (CompilationUnit) fStatement.getRoot();
		final IBinding[] before= (new ScopeAnalyzer(unit)).getDeclarationsInScope(fStatement.getStartPosition(), ScopeAnalyzer.VARIABLES);
		final IBinding[] after= (new ScopeAnalyzer(unit)).getDeclarationsAfter(fStatement.getStartPosition() + fStatement.getLength(), ScopeAnalyzer.VARIABLES);
		final List names= new ArrayList();
		for (int index= 0; index < before.length; index++)
			names.add(before[index].getName());
		for (int index= 0; index < after.length; index++)
			names.add(after[index].getName());
		return names;
	}
	/**
	 * Returns the expression for the enhanced for statement.
	 * 
	 * @param rewrite the ast rewrite to use
	 * @return the expression node
	 */
	private Expression getExpression(final ASTRewrite rewrite) {
		if (fExpression instanceof MethodInvocation)
			return (MethodInvocation) rewrite.createMoveTarget(fExpression);
		return (Expression) ASTNode.copySubtree(rewrite.getAST(), fExpression);