Java – Replace constant imports with static imports in IntelliJ Idea

Replace constant imports with static imports in IntelliJ Idea… here is a solution to the problem.

Replace constant imports with static imports in IntelliJ Idea

I have a code that contains some constants of the format ClassName.CONSTANT_NAME. I want to quickly replace it with CONSTANT_NAME. But I haven’t found any effective way to do this yet.
Every time I want to import something statically, I have to:

alt + enter
Add on demand static import for ....

Each class. But there are about 1000 classes

Is there any quick way to convert the import of many classes to a static import?

Solution

It looks like structure search and replacement is a good way to do this.

Search template: ClassName.CONSTANT_NAME
Replace template: ClassName.CONSTANT_NAME

And make sure that you have checked the check box Use static import. This will add a static import for you.

Structural Replace dialog from IntelliJ IDEA 2018.3

Related Problems and Solutions