Alex Rivera | Logout

Add favorite methods to static import in IntelliJ?

Asked 2011-02-24T15:53:53.933
30

In Eclipse 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;.

IntelliJ editor

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.

Edit
Report

1 Answer

29

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.

enter image description here

answered 2011-02-25T15:11:52.207

Your Answer