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

僤鯓⒐⒋嵵緔 提交于 2019-11-27 22:54:45

问题


I use the Eclipse keyboard shortcut Ctrl + Shift + O all the time (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. 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?


回答1:


Sure: Window -> Preferences -> Java -> Code Style -> Organize Imports

Adjust the value for "Number of static imports needed for .*" to 1, and it will always use .*. 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. That will fix the problem you said in the response.



来源:https://stackoverflow.com/questions/9831047/can-eclipse-the-organize-import-ctrlshifto-commands-handling-of-static-impo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!