Intellij automatically converting FQN to imports

前端 未结 2 1098
无人及你
无人及你 2020-12-11 00:11

If I have code that has a bunch of fully qualified names in it (java.util.List, javax.swing.JLabel, etc.) is there a command in intellij that will automatically convert thos

相关标签:
2条回答
  • 2020-12-11 00:54

    This can be achieved by first turning on inspection for this.

    Open up the Settings dialog and go down to Inspections and then search for qualified keyword and then turn on Unnecessary fully qualified name inspection:

    enter image description here

    That will make all occurrences of FQN in the code being color marked:

    enter image description here

    Now place the cursor on one of the highlighted areas and press Alt+Enter and a popup will give you the choice to Fix all 'Unnecessary fully qualified name' problems:

    enter image description here

    And then all FQN's will have been replaced with imports at the top instead:

    enter image description here

    If you want to run this inspection on the whole project (instead of just the current file) then you can choose the Run inspection on... alternative in the context menu:

    enter image description here

    Then choose Whole project:

    enter image description here

    And then finally in the Inspection Results window choose to Apply Fix on the selection:

    enter image description here

    0 讨论(0)
  • 2020-12-11 00:56

    In case, for new code entries if you are seeing the FQNs, just make sure that,

    Preferences -> Editor -> Code Style -> Java ->Use fully qualified class names is un-checked.
    

    0 讨论(0)
提交回复
热议问题