유틸 및 각종 자료/이클립스

intellij static methods

RBWSN 2016. 8. 27. 18:18
728x90

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

enter image description here

shareimprove this answer
1 
@matt: Even though you specify import static org.junit.Assert.* in the configuration dialog, it doesn't show up as "star import". It will do static import on the method you use. I just tried it, and it works for me (intellij 10.0.2). – limc Feb 24 '11 at 16:25
   
I'm curious - are you pressing ctrl + space in the middle of typing the method name and seeing IntelliJ complete it as "assertTrue" (for example)? Or are you typing the full statement and then pressing Alt + Enter? I think that IntelliJ may be smart enough to take a method call (with no import statements) and suggest a static import when you press Alt + Enter - something I just discovered which would make my initial question moot – matt b Feb 24 '11 at 16:28
2 
I have to type the whole assert statement first and then press ALT+ENTER to select the "static import". It doesn't work with CTRL+SPACE on partial method name like Eclipse does, which is kind of sucky. – limcFeb 24 '11 at 16:32
   
ALT+ENTER seems to suggest the static methods I want to add static imports for even without changing the Import settings as in the screenshot. Looks like IntelliJ is just way more intelligent than I would have guessed! – matt b Feb 24 '11 at 17:11
2 
The Path with IDEA 14 is File -> Settings -> Code Style -> Java -> Imports. Then, add your import statements under Packages to Use Import with '*' table. – Guillaume Vauvert Apr 30 '15 at 12:32


728x90