Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse organize imports: how to prefer JRE classes?

Tags:

java

eclipse

I heavily use the Eclipse organize imports function but a major annoyance for me is its tendency to add some incredibly niche type from a dependency with the same name as a class from the JRE.

For example, when I declare Map map; and run "organize imports", Eclipse may add import net.some.dependency.of.my.dependency.i.never.use.Map instead of import java.util.Map and then valuable time is lost as I figure out why map.entrySet() does not work anymore.

Is there some way of imposing a priority system on imports? For example:

  1. JRE classes
  2. My own classes
  3. my dependencies
  4. dependencies of my dependencies (and so on for 5.,6., ...)

I use Eclipse Neon 4.6.0M7.

P.S.: My dependencies are managed with Maven 3.3.9, in case that makes a difference.

like image 905
Konrad Höffner Avatar asked Jun 08 '16 08:06

Konrad Höffner


2 Answers

I don't know about support for priorities, but you could simply say you are not interested in some types or packages in the preference page Java / Appearance / Type filters. Types here are not shown in content assist.

E.g. I never develop in AWT or Swing, so I turn them off for the content assist as can be seen in the screenshotFiltering out AWT and Swing from content assist

like image 198
Zoltán Ujhelyi Avatar answered Oct 12 '22 15:10

Zoltán Ujhelyi


I would take a close look at the Eclipse .classpath file in the project folder. If classpath entries are ordered in some way, maybe this ordering is also controllable in the IDE option dialogs.

See What's in an Eclipse .classpath/.project file?

like image 39
mjn Avatar answered Oct 12 '22 16:10

mjn