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
for (Iterator iter= occurences.iterator(); iter.hasNext();) {
			ASTNode variableRef= (ASTNode)iter.next();
			addLinkedPosition(rewrite.track(variableRef), false, ELEMENT_KEY_REFERENCE);
		}
	}
	private void replaceMultipleOccurences(ASTRewrite rewrite, List occurences) {
		for (Iterator iter= occurences.iterator(); iter.hasNext();) {
			ASTNode element= (ASTNode)iter.next();
			ArrayAccess arrayAccess= element instanceof ArrayAccess ? (ArrayAccess)element : (ArrayAccess)ASTNodes.getParent(
				element, ArrayAccess.class);
			if (arrayAccess != null) {
				SimpleName elementReference= fAst.newSimpleName(fParameterDeclaration.getName().getIdentifier());
				rewrite.replace(arrayAccess, elementReference, null);
				addLinkedPosition(rewrite.track(elementReference), false, ELEMENT_KEY_REFERENCE);
			}
		}
	}
	private void doInferElement() {
		if (fCollectionName == null) {
			createDefaultParameter();
		} else {
			if (fOldCollectionTypeBinding.isArray()) {
				ITypeBinding elementType= fOldCollectionTypeBinding.getElementType();
				fParameterDeclaration= fAst.newSingleVariableDeclaration();
				SimpleName name= fAst.newSimpleName(ELEMENT_KEY_REFERENCE);
				fParameterDeclaration.setName(name);
				Type theType= null;
				theType= ASTNodeFactory.newType(getAst(), elementType, false);
				if (fOldCollectionTypeBinding.getDimensions() != 1) {
					theType= fAst.newArrayType(theType, fOldCollectionTypeBinding.getDimensions() - 1);