7

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.

Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118
  • When there are multiple choices for a particular class Eclipse will ask you which one to use, Eclipse doesn't just choose one at random. – Gimby Jun 08 '16 at 09:30

2 Answers2

3

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

Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37
1

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?

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378