Project: JDT
Bug 89432 [quick assist] Transform enhanced for-loop to iterator
Reported: 2005-03-29 18:22:18 | Status: verified fixed

I've often written iteration code using the enhanced for-loop initially, then later discovered I needed access to the Iterator to remove an object. It would be nice if Eclipse could do this simple (but verbose) transformation for me. For example: for (final Member member : list) { //... } becomes: for (final Iterator<Member> memberIter = list.iterator(); memberIter.hasNext(); ) { final Member member = memberIter.next(); // ... // if (foo) memberIter.remove(); } Similarly, the transformation could support arrays: for (final Member member : array) { // ... } becomes: for (int memberIndex = 0; memberIndex < array.length; ++memberIndex) { final Member member = array[memberIndex]; // ... // if (foo) member[memberIndex] = null; } Another variation would be creating a ListIterator for lists, to allow adding elements, or doing reverse iteration.

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalModel.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalPositionGroup.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/LinkedCorrectionProposal.java