Project: JDT
Bug 44834 Extract interface refactoring operation does not create necessary import statement [refactoring]
Reported: 2003-10-14 13:36:35 | Status: resolved fixed

In 3.0 M3 "Extract interface" refactoring does not create appropriate import statement for the newly created interface thus resulting in broken builds. In the refactoring dialog of Extract interface "Change references to the class X into the references to the interfaces" option has to be turned on in order to re-create this bug. To recreate: 1. Create a new java project. 2. Create two top packages a and b 3. Create A.java in package a and B.java in package b (see below). 4. Go to file B.java highlight "B" in the class declaration and invoke Refactor->Extract Interface 5. In the Refactoring dialog, type the "Interface name", for example - Test. Select "Change references to the class B into the references to the interfaces" option as well as interfaceMethod. Click Ok. This refactoring operation will change the reference of class B in A class to interface Test but will not import Test thus breaking the build. A.java ------------- package a; import b.B; public class A { private B b; public A(){} } B.java -------------------- package b; public class B { public B(){super();} public void interfaceMethod(){} }

Files changed in fix:
org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceRefactoring.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractInterfaceUtil.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/UseSupertypeWherePossibleRefactoring.java