javaintellij-ideastatic-import

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.


Solution

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

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

    Then select: