Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij idea auto import across files

I have auto import enabled in idea, but it requires me to open the file in the editor (like it should). Now, i have done some regex magic, which means across 100+ classes i am using new classes that need to be imported. Since its all done with find/replace, those files have never been opened in the editor, and therefore the new classes havent been auto imported. Is there any way to run auto import unambiguous references across all files? cause currently, i have to compile, and then open all the files from the errors window? Optimize imports aparently doesnt do new imports.

like image 842
topisani Avatar asked Mar 20 '16 11:03

topisani


People also ask

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 I enable auto import?

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

How do I disable wildcard imports in IntelliJ?

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.

What is a wildcard import?

Wildcard imports refer to importing a package instead of declaring specific class names being used from a package.


1 Answers

I am not sure in which version of IntelliJ this feature became available (I am currently using 2017.1.1) but you can select a package from the project browser and in the context menu optimise imports for that package or use the keyboard shortcut Ctrl+Alt+o.

I just used this to update the imports of all my classes after changing my import settings and it worked like charm.

like image 177
Trevor Gowing Avatar answered Oct 04 '22 05:10

Trevor Gowing