如果我的代码中有一堆完全限定的名称(java.util.List、javax.swing.JLabel 等),intellij 中是否有一个命令会自动将它们转换为导入包并只使用该类姓名?
2 回答
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:
That will make all occurrences of FQN in the code being color marked:
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
:
And then all FQN's will have been replaced with imports at the top instead:
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:
Then choose Whole project
:
And then finally in the Inspection Results
window choose to Apply Fix
on the selection: