简体   繁体   English

如何在Eclipse中组织导入,但不组织* change *星级导入

[英]How to organize import in Eclipse but not *change* star imports

I'd like to configure the organize import in Eclipse with one caveat: I do NOT want Eclipse to CHANGE the imports related to star imports (like import javax.xml.parsers.*). 我想在Eclipse中配置Organize导入有一个警告:我不希望Eclipse更改与星号导入相关的导入(例如import javax.xml.parsers。*)。

I would like Eclipse not to expand (replace the star import with each specific ones) if there is already a star import, but also not automatically add the star when there is not. 我希望Eclipse不要扩展(用每个特定的星导入),如果已经有星导入,但也不要在没有星导入时自动添加星。

In fact, I would like the organize import to just organize the imports (ie reorder), not change them. 实际上,我希望组织导入只是组织导入(即重新订购),而不更改它们。 Any idea ? 任何的想法 ?

I like it when IDE do not mess with developer's will. 当IDE不干扰开发人员的意愿时,我会喜欢它。

The Organize Imports command can only be executed as a whole (see source code ) and the Sort Members command ignores import statements. 组织导入”命令只能整体执行 (请参阅源代码 ),而“ 排序成员”命令将忽略导入语句。

As workaround to reorder/sort the import statements alphabetical use the AnyEdit Tools plug-in: 解决方法是按字母顺序对导入语句进行重新排序/排序,请使用AnyEdit Tools插件:

  1. Select the lines of import statements to reorder/sort 选择导入语句的行以重新排序/排序
  2. Right-click selection and choose Sort > Case-Insensitive AZ 右键单击选择,然后选择“ 排序”>“不区分大小写的AZ”

For .* import statements only , set the number of imports needed for .* to 0 (see Eclipse help - Organize Imports Preferences ): 对于.*只有import语句 ,设置所需的进口数量.* 0(见Eclipse帮助- 组织导入首选项 ):

  1. Open Window > Preferences: Java > Organize Imports 打开窗口>首选项:Java>组织导入
  2. Set Number of imports needed for .* (eg 'org.eclipse.*') to 0 (instead of 99) 。*(例如'org.eclipse。*')所需的导入数量设置为0 (而不是99)
  3. Click Apply and Save 单击应用并保存

For adding import statements manually or via content assist only , disable Organize Imports on save (see Eclipse help - Clean Up Preferences ): 要手动添加或仅通过内容辅助添加导入语句 ,请在保存时禁用组织导入 (请参阅Eclipse帮助- 清理首选项 ):

  1. Open Window > Preferences: Java > Code Style > Clean Up (or for project specific settings: right-click project, choose Properties: Code Style > Clean Up ) 打开窗口>首选项:Java>代码样式>清理 (或对于项目特定设置:右键单击项目,选择属性:代码样式>清理
  2. Click Edit... 点击编辑...
  3. In the Code Organize tab uncheck the Organize imports checkbox 在“ 代码组织”选项卡中,取消选中“ 组织导入”复选框
  4. In the Unnecessary Code tab uncheck the Remove unused imports checkbox 在“ 不必要的代码”选项卡中,取消选中“ 删除未使用的导入”复选框
  5. Click OK and Apply and Save to close both dialogs 单击确定然后单击应用并保存以关闭两个对话框

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

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