Reputation: 140041
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;
.
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.
Upvotes: 30
Views: 16638
Reputation: 40176
I think you can:-
File -> Settings -> Code Style -> Java -> Imports. Then, add your import statements under Packages to Use Import with '*' table.
Upvotes: 23
Reputation: 2136
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.
Upvotes: 29