Bug 73890 [1.5] Convert to enhanced for loop quick assist should not be available if counter is used in loop
I20040907 Have the following: for (int i= 0, length= numbers.length; i < length; i++) { int number= numbers[i]; System.out.println("Number " + i + ": " + new Integer(numbers[i])); } The quick assist allows me to convert this into code which causes a compile error: for (int element : numbers) { System.out.println("Number " + i + ": " + new Integer(numbers[i])); } Note: if I first assign int number= numbers[i]; and use number instead of numbers[i] in the println then the quick assist is not offered (correct).
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ConvertForLoopProposal.java
}
		return proposals;
	}
	private String[] getUsedVariableNames() {
		CompilationUnit root= (CompilationUnit)fOldForStatement.getRoot();
		IBinding[] varsBefore= (new ScopeAnalyzer(root)).getDeclarationsInScope(fOldForStatement.getStartPosition(),
			ScopeAnalyzer.VARIABLES);
		IBinding[] varsAfter= (new ScopeAnalyzer(root)).getDeclarationsAfter(fOldForStatement.getStartPosition()
			+ fOldForStatement.getLength(), ScopeAnalyzer.VARIABLES);
		String[] names= new String[varsBefore.length + varsAfter.length];
		for (int i= 0; i < varsBefore.length; i++) {
			names[i]= varsBefore[i].getName();
		}
		for (int i= 0; i < varsAfter.length; i++) {
			names[i + varsBefore.length]= varsAfter[i].getName();
		}
		return names;
	}
	
	private void doFindAndReplaceInBody(ASTRewrite rewrite) {
		LocalOccurencesFinder finder= new LocalOccurencesFinder(fCollectionName, fOldCollectionBinding,
			fOldCollectionTypeBinding, fOldForStatement.getBody());
		finder.perform();
		List occurences= finder.getOccurences();
		
		if (occurences.size() == 1) {
			ASTNode soleOccurence= (ASTNode)occurences.get(0);
			ArrayAccess arrayAccess= soleOccurence instanceof ArrayAccess 
				? (ArrayAccess)soleOccurence 
				: (ArrayAccess)ASTNodes.getParent(soleOccurence, ArrayAccess.class);