Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij auto import for inner classes

I'm using Intellij 10.5 and I'd like to be able to use the automatic generation of import lines to allow for inner classes, but I don't see it as a settings preference. Is this possible?

Example's worth a thousand words:

public class Foo {
  public static class Bar {
  }
}

I'm writing some code that needs to use an instance of Bar:

Bar bar = new Bar();

Intellij correctly brings up Bar as one of the suggestions for importing, but when I select it, it does the following:

import package.Foo;

Foo.Bar bar = new Foo.Bar();

whereas what I'd like is:

import package.Foo.Bar;

Bar bar = new Bar();

Thanks!

like image 468
Andrew Flynn Avatar asked Nov 10 '11 19:11

Andrew Flynn


People also ask

How do I automatically import in IntelliJ?

Automatically add import statements 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 import all classes in IntelliJ?

The auto import for classes is working if you enable it under "Settings > Editor > General > Auto Import".

How do I stop auto import in IntelliJ?

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.

How do you add wildcard imports to a class?

The solution is to go to Preferences ( ⌘ + , on macOS / Ctrl + Alt + S on Windows and Linux) > Editor > Code Style > Java > Imports tab set Class count to use import with '*' and Names count to use static import with '*' to a higher value. Any value over 99 seems to work fine.


1 Answers

Check the checkbox under Settings > Editor > Code Style > Java > Imports > Insert imports for inner classes:

enter image description here

like image 176
Oleg Mikheev Avatar answered Oct 11 '22 06:10

Oleg Mikheev