Project: JDT
Bug 68504 Refactor -> Change Method Signature removes import [refactoring]
Reported: 2004-06-24 13:27:51 | Status: verified fixed

I'm using 3.0RC2 on Windows XP Professional, JDK is Sun 1.4.2_04 Create a new class, Bug.java as below: import java.util.regex.Matcher; public class Bug { public static boolean textContains(CharSequence text, Matcher matcher) { return matcher.reset(text).find(); } } In the same package, create BugCaller.java Create a new class, Bug.java as below: import java.util.regex.Matcher; import java.util.regex.Pattern; public class BugCaller { public static void main(String args[]) { Matcher m = Pattern.compile(args[0]); Bug.textContains(args[1], m); } } Select the textContains method, then select Refactor -> Change Method Signature... In the signature, select the Matcher matcher parameter and select the Up button move it up so that it is the first parameter, then select OK from the refactor window. When performing the refactoring, JDT removes the import java.util.regex.Matcher; statement. When you save, you get a compile error in Bug.java and in all callers (BugCaller.java) because of a signature mismatch. (the callers are updated correctly, but then do not compile because of the unknown type Matcher in Bug.java.) Quick-fix or Organize Imports on Bug.java resolves the problem.

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ChangeSignature/canModify/A_testImport08_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ChangeSignature/canModify/A_testImport08_out.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeSignatureTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeSignatureRefactoring.java