Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 483987

Summary: [organize imports] organize imports does not remove unnecessary imports from the same package
Product: [Eclipse Project] JDT Reporter: Nanda Firdausi <nanda.firdausi>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, nanda.firdausi, noopur_gupta
Version: 4.5.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Nanda Firdausi CLA 2015-12-09 04:19:10 EST
This is often the case when you refactor classes to a different package. Normally this will be done in several steps, which causing some unnecessary imports to the classes in the same package to be left in the class (think of java classes and their test classes).
Comment 1 Jay Arthanareeswaran CLA 2015-12-14 08:25:40 EST
I can't reproduce this. Can you help me with a test case or steps to reproduce?
Comment 2 Nanda Firdausi CLA 2015-12-14 11:03:04 EST
Create two source folders, e.g. javatests and java:

In java, create a class A in package Z, e.g:

package Z;

public class A {

}


In javatests, create class ATest in package Z, add a field a with type A, e.g:

package Z;

public class ATest {
  A a;
}

Now refactor -> Move class A to package Y. A is now:

package Y;

public class A {

}

ATest is now:

package Z;

import Y.A;

public class ATest {
  A a;
}

Now Reafctor -> Move class ATest to package Y. A is now:

package Y;

public class A {

}

ATest:

package Y;

import Y.A; <--- This import is unnecessary

public class ATest {
  A a;
}

Even after I run organize import, that import statement is not being removed automatically.
Comment 3 Jay Arthanareeswaran CLA 2015-12-15 01:07:45 EST
Thanks, I see it now. After the refactor, the Organize Import does remove the import, though. Moving to UI for investigation.
Comment 4 Noopur Gupta CLA 2015-12-15 09:54:26 EST
(In reply to Nanda Firdausi from comment #2)
Which source folder contains package "Y"?

With Eclipse Neon M4 build and steps in comment #2 (I tried keeping package Y in different source folders each time), I see that move refactoring updates the imports correctly i.e. there is no import in ATest after moving it to Y.

Can you please check with Neon M4 and see if you can reproduce it with the given steps:
http://download.eclipse.org/eclipse/downloads/drops4/S-4.6M4-201512092300/

Make sure that in the "Move" dialog, "Update references to 'ATest.java'" is checked (which is checked by default).
Comment 5 Eclipse Genie CLA 2020-04-25 18:27:19 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.