Bug 305205 - Disable inner class imports with preference
Summary: Disable inner class imports with preference
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2010-03-09 12:58 EST by Carsten Reckord CLA
Modified: 2018-05-16 01:30 EDT (History)
3 users (show)

See Also:


Attachments
A Similar feature in a competing IDE (23.56 KB, image/png)
2015-08-05 23:01 EDT, Priyal Samaratunga CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Reckord CLA 2010-03-09 12:58:38 EST
The Organize Imports function and other quickfixes and refactorings that automatically add imports for types referenced by them are pretty great. 
But when it comes to inner classes, the result often is less than helpful. Oftentimes inner classes use names that only make sense when qualified by their outer class: 

- Entry is much less helpful than Map.Entry
- EMF has inner classes called Internal or similar all over the place (Adapter.Internal, Resource.Internal ...)

Therefore it would make sense to only import their outer class and have the inner classes qualified by them. 

Currently, after an "Organize Imports", what you get is something like

import java.util.Map.Entry;
...
Entry foo = something();

I'd propose to add a preference "Import inner classes" to the "Organize Imports" section, which when enabled (the default?) yields the old result and when disabled yields something like this instead:

import java.util.Map;
...
Map.Entry foo = something();
Comment 1 Priyal Samaratunga CLA 2015-08-05 23:01:15 EDT
Created attachment 255656 [details]
A Similar feature in a competing IDE

This is a image of similar feature in IntelliJ Idea IDE
Comment 2 Priyal Samaratunga CLA 2015-08-05 23:01:40 EDT
Yes, this has been really troublesome and the code become less readable once the static inner classes are directly imported to the client class. Having the semi qualified name as 'OuterClass.InnerClass' within the code is much more readable. I've notice this happening when we use the "Add Unimplemented methods" when implementing interfaces. Even if the interface it self has Semi qualified names of inner classes as the parameter types of its methods, still the automatically added method implementations will have only the direct unqualified names of the inner classes in the method parameter list and, we can see the import statement for Inner classes rather than the outer class at the top. The preference to select the option "Insert imports for inner classes" is available in other competing IDEs as well(e.g IntelliJ Idea). Any updates on this change request?
Comment 3 Jay Arthanareeswaran CLA 2015-08-14 00:55:09 EDT
Will keep this in the radar, but no promise yet. Meanwhile, if anyone is willing to contribute a patch, that will speed up things!
Comment 4 Manoj N Palat CLA 2018-05-16 01:30:46 EDT
Bulk move out of 4.8