简体   繁体   English

Eclipse-在不明确的导入上自动导入java.util类

[英]Eclipse - auto import java.util classes on ambiguous imports

Is there a way Eclipse will auto import classes from java package as java.util.List without the need to choose it explicitly in every class? Eclipse是否有一种方法可以自动从java包中将类作为java.util.List 导入 ,而无需在每个类中明确选择它?

(even without Ctrl + Shift + O ) (即使没有Ctrl + Shift + O

When I write List and eclipse auto import java.util.List instead of suggesting irrelevant List as org.apache.xmlbeans.impl.xb.xsdschema.ListDocument.List 当我写List和eclipse时,自动导入java.util.List而不是建议无关列表作为org.apache.xmlbeans.impl.xb.xsdschema.ListDocument.List

I know I can exclude by Type Filters , but I just want specific objects as List to be automatically imported. 我知道我可以按类型过滤器排除 ,但我只希望将特定对象(如List)自动导入。

Automatically organise import statements whenever you save 保存时自动组织导入语句

  • Go to Window > Preferences > Java > Editor > Save Actions. 转到窗口>首选项> Java>编辑器>保存操作。
  • Select Perform the selected actions on save (off by default). 选择保存时执行选定的操作(默认情况下为关闭)。
  • Ensure that Organize imports is selected (on by default). 确保选中“组织导入”(默认情况下处于启用状态)。

Let Eclipse collapse imports in the same package a wildcard (.*) or always expand them 让Eclipse将通配符(。*)导入到同一包中,或者始终对其进行扩展

  • Go to Window > Preferences > Java > Code Style > Organize Imports. 转到窗口>首选项> Java>代码样式>组织导入。
  • Change the value of Number of imports need for .* to 0. 将“。*的需要进口数量”的值更改为0。
  • (Optional) Change the value of Number of static imports needed for .* to 0. (可选)将。*所需的静态导入数的值更改为0。

Exclude unwanted packages using Type Filters 使用类型过滤器排除不需要的软件包

  • Go to Window > Preferences > Java > Appearance > Type Filters. 转到窗口>首选项> Java>外观>类型过滤器。
  • Click Add… to add a package/class. 单击添加…以添加包/类。
  • Enter java.awt.List (or java.awt.* if you don't intend using any AWT classes). 输入java.awt.List(如果不想使用任何AWT类,则输入java.awt。*)。

some these other features 其他一些功能

  • Folding : By default, Eclipse folds all import statements into one line so your class takes up less space on the screen. 折叠 :默认情况下,Eclipse将所有import语句折叠为一行,因此您的类占用的屏幕空间更少。 You can change this by going to Window > Preferences > Java > Editor > Folding and deselecting Imports. 您可以通过以下方法更改此设置:转到窗口>首选项> Java>编辑器>折叠并取消选择导入。

  • Sorting : If you're really particular about the order of packages, you can go to Window > Preferences > Java > Code Style > Organize Imports and define the order of the packages as you want Eclipse to order them. 排序 :如果您真的很确定软件包的顺序,那么可以转到Window> Preferences> Java> Code Style> Organize Imports,然后按照您希望Eclipse对其进行排序的方式定义软件包的顺序。 It's not really worth the effort though so I'd skip it. 不过,这确实不值得付出努力,所以我跳过了。

  • Compress/abbreviate package names in the Package Explorer (not in your class but in the view): You can display packages compressed (eg. o~.e~.swt) or abbreviated (eg. org.eclipse.swt.custom becomes {SWT}.custom). 在Package Explorer (不是在您的类中,而是在视图中) 压缩/缩写软件包名称 :您可以显示压缩的(例如o〜.e〜.swt)或缩写的软件包(例如org.eclipse.swt.custom变为{ SWT} .custom)。 Go to Window > Preferences > Java > Appearance and define the settings there. 转到窗口>首选项> Java>外观,然后在其中定义设置。 The dialog has decent examples of how to do this. 该对话框包含如何执行此操作的示例。

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

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