How to make IDEA refactor a MyClass.staticMethod to import static line?

Hi there,

Would anyone knows what's the equavalent of Eclipse's "Ctrl+Shift+M" in IntelliJ IDEA?

Basically in Eclipse, I can press "Ctrl+Shift+M" on a line like "MyClass.staticMethod" after highlighting "staticMethod", and it will auto insert the "import static MyClass.assertThat" to the top of the source, and then remove the "MyClass." prefix from the line.

Thanks,
Zemian

4 comments
Comment actions Permalink

just press ALT+ENTER while on method and choose "Static import" (dunno exact wording, could also be "replace with static import")

0
Comment actions Permalink

Thanks MJ.

I tried ALT+ENTER, and it prompts for  "Add static import for ...". However it only works if the method has parameter! It won't prompt if the method has zero parameter? Is this a bug?

I can reproduce this by using "org.hamcrest.Matchers.notNullValue()" with IDEA CE 12.

0
Comment actions Permalink

Hi Denis.

I got it working now. I must have selected the text before pressin ALT+ENTER, which didn't prompt. But if I just place the caret on the method name, it works fine now. I must have got confused and not able to see it earlier. Thanks for verifying it (with video!).

Zemian

0

Please sign in to leave a comment.