IntelliJ Organize Imports

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

    That plugin will automatically do the "organize import" action on file save: https://github.com/dubreuia/intellij-plugin-save-actions.

    To install: "File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'". Then activate the "organize import" save action.

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

    In addition to Optimize Imports and Auto Import, which were pointed out by @dave-newton and @ryan-stewart in earlier answers, go to:

    • IDEA <= 13: File menu > Settings > Code Style > Java > Imports
    • IDEA >= 14: File menu > Settings > Editor > Code Style > Java > Imports (thanks to @mathias-bader for the hint!)

    There you can fine tune the grouping and order or imports, "Class count to use import with '*'", etc.

    Note:
    since IDEA 13 you can configure the project default settings from the IDEA "start page": Configure > Project defaults > Settings > .... Then every new project will have those default settings:

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