Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

java - 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).

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...