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 those to import the package and just use the class name?
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.
Disable wildcard importsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With