简体   繁体   English

可以修改Eclipse的Organize Import(ctrl + shift + o)命令对静态导入的处理吗?

[英]Can Eclipse the Organize Import (ctrl+shift+o) command's handling of static imports be modified?

I use the Eclipse keyboard shortcut Ctrl + Shift + O all the time (Organize Imports). 我一直使用Eclipse键盘快捷键Ctrl + Shift + O (Organize Imports)。

However, it has one particularly annoying behavior: 但是,它有一个特别烦人的行为:

If I have any static imports like: 如果我有任何静态导入,如:

import static java.lang.Math.*;

Organize Imports will "helpfully" replace it with static imports of only the fields and methods I am actually using. Organize Imports将“帮助”用仅我实际使用的字段和方法的静态导入替换它。 For example: 例如:

import static java.lang.Math.PI;
import static java.lang.Math.cos;

Is there any way to remove just this behavior from Organize Imports? 有没有办法从Organize Imports中删除这种行为?

Sure: Window -> Preferences -> Java -> Code Style -> Organize Imports 当然:窗口 - >首选项 - > Java - >代码样式 - >组织导入

Adjust the value for "Number of static imports needed for .*" to 1, and it will always use .*. "Number of static imports needed for .*"的值调整为1,并始终使用。*。 Of course, that's not quite the same as saying, "Just leave static imports alone" but hopefully it's what you want. 当然,这并不完全等于说,“见好就收静态导入独”,但希望这是你想要的。

Basically, this number says "Use all of the methods or fields of this import if I'm importing this many items" So if the number is 2, it will add the asterisk only if you use two or more imports. 基本上,这个数字表示“如果我导入这么多项目,请使用此导入的所有方法或字段”因此,如果数字为2,则仅当您使用两个或更多导入时才会添加星号。 That will fix the problem you said in the response. 这将解决您在回复中说的问题。

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

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