开发者

Add favorite methods to static import in IntelliJ?

In Eclips开发者_如何学JAVAe it is possible to configure certain "favorite" classes which will be looked up when code completetion is invoked to see if a static import can be added for a method (this is under Preferences > Java > Editor > Content Assist > Favorites).

For example, I can begin to type assertT, and Eclipse will ask if I want to add a static import of org.junit.Assert.assertTrue;.

Add favorite methods to static import in IntelliJ?

Is it possible to do the same thing in IntelliJ?

The method detailed in this question will add a * import for the type (static import org.junit.Assert.*), but I do not want to add star-imports. I'd prefer to import just the methods I am using.


Strictly speaking, this does not answer your original question.

However, IDEA 10 supports Ctrl-Alt-Space completion for static methods. For example, in a JUnit 4 test that does not import anything, type "assEq" and invoke Ctrl-Alt-space. The resulting dialog will also allow you to import this method statically.

Once you're imported a single method (like assertEquals), other static methods from the same class will be included in the regular code completion suggestions (although you can still use the Ctrl-Alt-Space shortcut, of course).

I find this feature, combined with the "automatic import blacklist", to work very well.

Add favorite methods to static import in IntelliJ?


I think you can:-

File -> Settings -> Code Style -> Java -> Imports. Then, add your import statements under Packages to Use Import with '*' table.

Add favorite methods to static import in IntelliJ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜