IntelliJ Organize Imports

后端 未结 14 997
孤街浪徒
孤街浪徒 2020-12-02 04:48

Does IntelliJ have an Organize Imports feature similar to that in Eclipse? What I have is a Java file with multiple classes missing their imports. Example:

p         


        
相关标签:
14条回答
  • 2020-12-02 05:28

    Under "Settings -> Editor -> General -> Auto Import" there are several options regarding automatic imports. Only unambiguous imports may be added automatically; this is one of the options.

    0 讨论(0)
  • 2020-12-02 05:29

    Simple & short solution worked for me.

    Go to File -> Settings -> Editor -> Auto Import -> Java (left panel) and make the below things: Select check box for "Add unambigious imports on the fly" and "Optimize imports on the fly"

    Refer this.

    0 讨论(0)
  • 2020-12-02 05:30

    Ctrl + Alt + O (Code → Optimize Imports...) is what you're looking for, both on Windows/Linux and macOS keymaps.

    It says "Optimize", but, if configured to do so, it will also:

    • organize existing imports
    • remove unneeded imports
    • add new required imports
    • add unambiguous imports on the fly

    You can tune the auto-import settings under "Settings → Editor → General → Auto Import" as described by Dave.

    You can also modify how the imports are auto-ordered under "Settings → Editor → Code Style → Java → Imports"

    0 讨论(0)
  • 2020-12-02 05:34

    Goto Help -> Find Action (Short Cut for this is Cntl + Shift + A) and type Optimize imports (Short cut for this is Cntl + Alt + O)

    0 讨论(0)
  • 2020-12-02 05:36

    In IntelliJ 14, the path to the settings for Auto Import has changed. The path is

    IntelliJ IDEA->Preferences->Editor->General->Auto Import

    then follow the instructions above, clicking Add unambiguous imports on the fly

    I can't imagine why this wouldn't be set by default.

    0 讨论(0)
  • 2020-12-02 05:39

    July 2015 - I have concluded that IntelliJ does not support automatically resolving imports with a single function. "Organize imports" simply removes unused imports, it does not resolve unimported types. Control-Space resolves a single unimported type. There does not exist a single action to resolve all types' imports.

    0 讨论(0)
提交回复
热议问题