Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA: how to enable imports for inner classes

When I paste a code snippet with inner entity's(class or enum) name in it in IDEA 12 I get a dialog offering to import that entity's package. If class I'm working on and entity are in same package, IDEA just writes outer class name and a dot before entity's name. That bloats source much worse than if entity was imported in the import section at the file start. How to disable this kind of behaviour and force IDEA to import everything exclusively in import section?

like image 401
Aleksandr Kravets Avatar asked Jan 23 '13 10:01

Aleksandr Kravets


People also ask

How do I enable auto import in IntelliJ?

You can configure the IDE to automatically add import statements if there are no options to choose from. In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. Select the Add unambiguous imports on the fly checkbox, and apply the changes.

How do I change import settings in IntelliJ?

Call File | Manage IDE Settings | Import Settings from the main menu. Select the ZIP archive that contains your settings in the dialog that opens. Select the settings you want to apply in the Select Components to Import dialog that opens and click OK.

Where is import option in IntelliJ?

Launch IntelliJ IDEA. If the Welcome screen opens, press Ctrl+Shift+A , type project from existing sources , and click the Import project from existing sources action in the popup. Otherwise, from the main menu, select File | New | Project from Existing Sources.


1 Answers

Honestly, when using inner classes outside its parent it JUST makes sense to reference the outer class instead of importing the inner class at the top level, otherwise, why is that class an inner class instead of a top level one? From my point of view, if you are consuming a inner class outside its parent at lot (you say 100 times) then, don't you think you should review your design?

Anyway, you can control the Auto-Import feature in IntelliJ at Settings > Editor > General > Auto Import.

In the other hand, if you want to have imports for your inner classes then go to Settings > Editor > Code Style > Java > Imports and mark the Insert imports for inner classes checkbox.

like image 64
Alonso Dominguez Avatar answered Oct 04 '22 05:10

Alonso Dominguez