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.   

1 comment
Comment actions Permalink

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.

I created a feature request asking that the "Expand static import" fix be offered as a solution to the "Static Import" inspection.

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


Please sign in to leave a comment.