Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace import of constant/method by static import in IntelliJ Idea

I have a code with some constants in format ClassName.CONSTANT_NAME. I want to quickly replace this by CONSTANT_NAME. But I have not found any efficient way of doing that.

Every time I want to static import something I have to remove class name manually then open static import tooltip which might contain several matches for constant name... It is inefficient.

Is there any quick way of converting an import to a static import? Ideally I would assign a shortcut for this.

like image 447
Sasha Shpota Avatar asked Jul 04 '17 10:07

Sasha Shpota


People also ask

How do I change imports in IntelliJ?

You can change the settings to import entire packages instead. In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Clear the Use single class import checkbox, and apply the changes.

How do I stop auto import in IntelliJ?

You can disable auto-import on completion and use quick-fixes instead: In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Auto Import. On the Auto Import page that opens, use the checkboxes in the TypeScript/JavaScript area to enable or disable import generation on code completion.


1 Answers

Put the cursor on the constant (ClassName.CONSTANT_NAME).

Then use the shortcut for the action Show the list of available intention actions.

  • On windows or Linux: alt + enter

  • On mac os: ⌥⏎

Then select:

  • Add on demand static import for ....
like image 195
Pau Avatar answered Sep 19 '22 20:09

Pau