Organize Imports

Organize Imports cleans up the import statements in the current file. It does however not remove any unused imports nor imports that are needed for the program to compile. The refactoring does the following to the imports:

  • Sorts the statements alphabetically by their full name.
  • Collapses multiple distinct imports from the same package into a single statement.
  • Simplifies the imports: when a wildcard imports the whole package content, individual import from that package are removed, unless they contain renames.

The following screenshot shows the changes Organize Imports proposes:


The current implementation has some limitations compared to its Java counterpart. The refactoring does not do any dependency analysis, imports that are missing are not added, and unneeded imports are not being removed by Organize Imports.

Comments Off