简体   繁体   English

Eclipse组织导入:如何更喜欢JRE类?

[英]Eclipse organize imports: how to prefer JRE classes?

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. 我大量使用Eclipse组织导入功能,但对我来说一个主要的烦恼是它倾向于从与JRE中的类同名的依赖项中添加一些令人难以置信的小众类型。

For example, when I declare Map map; 例如,当我声明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. 并运行“组织导入”,Eclipse可能会添加import net.some.dependency.of.my.dependency.i.never.use.Map而不是import java.util.Map ,然后因为我弄清楚为什么map.entrySet()会丢失宝贵的时间map.entrySet()不再起作用了。

Is there some way of imposing a priority system on imports? 是否有某种方式对进口实施优先权制度? For example: 例如:

  1. JRE classes JRE课程
  2. My own classes 我自己的课
  3. my dependencies 我的依赖
  4. dependencies of my dependencies (and so on for 5.,6., ...) 我的依赖关系的依赖关系(依此类推5.,6 ..,...)

I use Eclipse Neon 4.6.0M7. 我使用Eclipse Neon 4.6.0M7。

PS: My dependencies are managed with Maven 3.3.9, in case that makes a difference. PS:我的依赖关系是用Maven 3.3.9管理的,以防万一。

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 . 我不知道对优先级的支持,但您可以简单地说您对首选项页面Java / Appearance / Type filters中的某些类型或包不感兴趣。 Types here are not shown in content assist. 此处的类型未在内容辅助中显示。

Eg I never develop in AWT or Swing, so I turn them off for the content assist as can be seen in the screenshot 例如,我从未在AWT或Swing中进行开发,因此我可以将其关闭以获取内容辅助,如屏幕截图所示 从内容辅助过滤出AWT和Swing

I would take a close look at the Eclipse .classpath file in the project folder. 我将仔细查看项目文件夹中的Eclipse .classpath文件。 If classpath entries are ordered in some way, maybe this ordering is also controllable in the IDE option dialogs. 如果以某种方式对类路径条目进行排序,则可以在IDE选项对话框中控制此顺序。

See What's in an Eclipse .classpath/.project file? 请参阅Eclipse .classpath / .project文件中的内容?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM