Project: JDT
Bug 176502 [quick assist] convert iterable for loop removes imports which are in use
Reported: 2007-03-06 10:51:20 | Status: resolved fixed

Build ID: I20070222-0951 Steps To Reproduce: Put the following code in a Java file (has dependencies on EMF): package com.castortech.iris; import java.util.Iterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.Diagnostician; public class BugTest { public static void main(String[] args) { Resource resource = null; for (Iterator j = resource.getContents().iterator(); j.hasNext();) { EObject eObject = (EObject)j.next(); Diagnostician.INSTANCE.validate(eObject); } } } Choose source->Clean Up, and make sure the profile has "Remove unused imports" selected. The refactoring will incorrectly try to remove the imports for EObject and Diagnostician. More information: Note that while trying to minimize the example reproducing the bug, I was unable to get rid of the dependency on EMF. Replacing resource.getContents() with a java.util.List, for example, makes the bug go away.

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertIterableLoopQuickFixTest.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/ConvertIterableLoopOperation.java