1 Replies Last post: Sep 26, 2012 10:24 PM by Mark Vedder  
Tom Williamson Newbie 21 posts since
Aug 8, 2012
Currently Being Moderated

Sep 26, 2012 9:27 PM

Refactor out "import static"?

Can Intellij's "Refactor" capability be used to convert "import static" statements to regular "import" statements?   We have some code which is somewhat indecipherable due to everything being statically imported and I'd like to make it a little more readable.  Simply removing the "static" modifier results in about 10,000 "cannot resolve method XXXX()" errors, so I was hoping that there would be a way to fix this using refactor.  

Mark Vedder Apprentice 1,006 posts since
Dec 10, 2003
Currently Being Moderated
Sep 26, 2012 10:55 PM in response to: Tom Williamson
Re: Refactor out "import static"?

In the code, find a use of the statically imported value. With your cursor on the item, type Alt+Enter. Select "Expand static import to SomeClass.VALUE". Then select the "Replace all and delete the import".

 

It does not look like you will be able to do this on a bulk basis. While you can use the Imports > Static import inspection to find all static imports in your project, and then use the referenced "Replace with non-static import" quick fix, that does not alter the code so VALUE becomes SomeClass.VALUE.

 

<EDIT>

I created a feature request asking that the "Expand static import" fix be offered as a solution to the "Static Import" inspection. http://youtrack.jetbrains.com/issue/IDEA-92147

</EDIT>

 

Message was edited by: Mark Vedder: add link to feature request

More Like This

  • Retrieving data ...