IntelliJ Organize Imports

后端 未结 14 996
孤街浪徒
孤街浪徒 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:17

    Shortcut for the Mac: (ctrl + opt + o)

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

    If you are missing just one import (the class name has red underline), click and hover the mouse over it, and a blue suggested import statement will appear. If you hit, Alt + Enter at this point, the import will be included in the file and the red underline should disappear.

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

    Just move your mouse over the missing view and hit keys on windows ALT + ENTER

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

    navigate to the file where you want to organize imports or just click on the whole package or even click on the project than press CTRL + ALT + O

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

    ALT+ENTER was far from eclipse habit ,in IDEA for me mouse over did not work , so in setting>IDESetting>Keymap>Show intention actions and quick-fixes I changed it to mouse left click , It did not support mouse over! but mouse left click was OK and closest to my intention.

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

    I finally created a workaround around this frustrating issue. I'm not completely happy with the workaround, but it's better than nothing.

    Basically, after you paste the source code and unambigous imports are fixed, just press F2 to highlight the next compiler error. If the current error is an import-missing error, press Alt+Enter, then Enter to select the Import option, then pick the correct import. Then, press F2 again.

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