Child pages
  • Auto Import of Classes

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

You can write class name without import statements, when editor shows you that this reference is unresolved, you can just Scala plugin automatically inserts import statements for the class names you are using.

When you type a class name, the editor automatically suggests the fully qualified name and offers you to press Alt+Enter, and plugin insert essential to insert an appropriate import statement automatically.
Options for this feature: File -> Settings -> Code Style -> Scala -> Imports
Image Removed

Auto import settings can be adjusted in the Settings Dialog:

  1. Press Ctrl+Alt+S to open the Settings Dialog
  2. Expand Code Style and click Scala
  3. Select Imports tab.

Image Added

Scala language gives you flexible a number of ways to use import statements. You can import not full qualified name or use import statemnt in any code block. Also you can collect few imports in one import statemet without using placeholder. All of these Scala language features we tried to reflect in plugin:

...

Note
titleBe Careful

This can produce bugs in plugin. With using placeholder, you automatically import packages. So inserted import can be hided, it can be rare case, but must be fixed.

...

:

  • Import of not fully qualified class names
  • Declare an import statement in any code block
  • Use placeholders to import more than one class in a single statement

Scala plugin provides the support for all these language features:

  • Auto import feature inserts the shortest qualified name, if possible. Otherwise, the _root_ qualifier is added.
  • All import statements from one package are collapsed to a single statement. 
  • If a class name matches only a single valid package, it's imported on-the-fly, without requiring you to press Alt+Enter.
  • Import statements can be inserted anywhere in the file, not only the header.
  • If a number of classes imported from a package exceeds a specified threshold, the import is collapsed to a package level.
Note

Starting from compiler version 2.8, packages from parent packages are not implicitly imported, and you need to import them manually, or to use nested packages feature (in Scala 2.8). So, if you are using Scala version 2.7 or lower, then you will always get fully qualified imports after using this feature.