Add and organize import declarations

Add Import

Keyboard Shortcut: Ctrl + Shift + M

Creates an import declaration for a type reference currently selected. If the type reference if qualified, the qualification will be removed if possible. If the referenced type name can not be mapped uniquely to a type of the current project you will be prompted to specify the correct type. Add Import tries to follow the import order as specified in the Organize Import preference page

Adding required import statements

The Java editor can help you add required import statements for a selected type inside a compilation unit.

  1. Select a reference to a type in your Java code, and do one of the following:

    • Select Source > Add Import from the pop-up menu in the editor

    • Select Source > Add Import from the menu bar.

      Source > Add Import

    • Press Ctrl+Shift+M.

  2. Either the editor can identify the type or you are prompted to choose the desired type from a list of possible types.

  3. The import statement is generated and inserted as specified by the import order preference.

Organize Imports

Keyboard Shortcut: Ctrl + Shift + O

Organizes the import declarations in the compilation unit currently open or selected. Unnecessary import declarations are removed, and required import declarations are ordered as specified in the Organize Import preference page (Window > Preferences > Java > Organize Import). Organize import can be executed on incomplete source and will prompt you when a referenced type name can not be mapped uniquely to a type in the current project. You can also organize multiple compilation units by invoking the action on a package or selecting a set of compilation units.

Organizing existing import statements

The Java editor can help you improve the existing import statements inside a compilation unit.

  1. Do one of the following while editing your Java code:

    • Select Source > Organize Imports from the pop-up menu in the editor

    • Select Source > Organize Imports from the menu bar

    • Press Ctrl+Shift+O.

    Organize Imports

  2. The Java editor generates a complete list of import statements, as specified by the import order preference, and new import statements replace the old ones.

Note: You can specify the order of the import declarations in Preferences (Window > Preferences > Java > Organize Imports).

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine