Bug 409142 - [organize imports] Organize import doesn't find moved classes of static imports
Summary: [organize imports] Organize import doesn't find moved classes of static imports
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2013-05-27 08:50 EDT by Tobias Oberlies CLA
Modified: 2013-05-28 10:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Oberlies CLA 2013-05-27 08:50:55 EDT
Steps to reproduce:
1. Create a class original.A with a public, static method m().
2. Create a class user.B and add the following import statements:

import static original.A.m;
import original.A;

3. Use both A and m in the body of class B.
4. Move class A (without using a refactoring) to the package "moved".
5. Organize imports in B. The result is a single import statement

import moved.A;

and a compile error.


Expected two import statements (as before):

import static moved.A.m;
import moved.A;
Comment 1 Dani Megert CLA 2013-05-27 10:46:15 EDT
If you have

	void use() {
		abs(2.0);
	}

Organize Imports cannot insert the static import because it would be too expensive (see bug 94078 comment 2).


Bug 283287 offers an alternative solution. Also, using the move refactoring adjusts the import.

*** This bug has been marked as a duplicate of bug 94078 ***
Comment 2 Tobias Oberlies CLA 2013-05-28 03:42:06 EDT
I'm not asking to insert an arbitrary static import, but only to correct an existing static import. I can imaging that organize import doesn't work this way currently, but figuring out that I want to 

   import static moved.A.m;

if I have declared

   import static original.A.m;

and class A is only available in package "moved" should be doable.
Comment 3 Dani Megert CLA 2013-05-28 04:05:40 EDT
(In reply to comment #2)
> I'm not asking to insert an arbitrary static import, but only to correct an
> existing static import. I can imaging that organize import doesn't work this
> way currently, but figuring out that I want to 
> 
>    import static moved.A.m;
> 
> if I have declared
> 
>    import static original.A.m;
> 
> and class A is only available in package "moved" should be doable.

Yes, doable, but not something we will spend time on, given that the refactoring does the job. If you don't want to (or can't) use the refactoring, then you can use text search replace to fix the imports.

*** This bug has been marked as a duplicate of bug 94078 ***
Comment 4 Tobias Oberlies CLA 2013-05-28 04:23:34 EDT
So you don't consider this a bug that needs to be fixed. Fair enough - if you say that organize import doesn't do this, its not broken.

But wouldn't this be a reasonable improvement to the organize import feature?
Comment 5 Dani Megert CLA 2013-05-28 04:38:37 EDT
(In reply to comment #4)
> So you don't consider this a bug that needs to be fixed. Fair enough - if
> you say that organize import doesn't do this, its not broken.
> 
> But wouldn't this be a reasonable improvement to the organize import feature?

I never argued about that. This bug is a special case of bug 94078, which is an enhancement marked as WONTFIX. While this special case (we know the type name) is easier fixable than the general case, we still would not spend time to fix this. Since we try to be honest, we normally set such bugs to WONTIFIX. Anyway, I've now set it to assigned and P5. Maybe you're lucky and someone thinks, it is important enough to spend resources on it - maybe you? ;-)
Comment 6 Tobias Oberlies CLA 2013-05-28 10:10:25 EDT
(In reply to comment #5)
> maybe you? ;-)
The chances are definitely higher now than if you had closed this as WONTFIX again ;-)

(In reply to comment #0)
> 4. Move class A (without using a refactoring) to the package "moved".
This happens when I rebase a Git change onto a change that moved the class. But thinking about it, I could move the class back to the old location (using the refactoring and ignoring the "found potential matches" warning) and the move it to the new location again. Thats a reasonable workaround, but I'd still prefer to have this enhancement implemented :-)