WebSphere V5.0 : Java Development - Use content assist function and declarations
In this tutorial you will learn about Content/code assist, Using content/code assist, Add and organize import declarations, Add Import, Adding required import statements,Organize Imports andOrganizing existing import statements.
Content/code assist
If activated from a valid line of code in an editor, this command opens a scrollable list of available code completions. Some tips for using code assist:
- If you select and then hover over a selected line in the content assist list, you can view Javadoc information for that line.
.
- You can use the mouse or the keyboard (Up Arrow, Down Arrow, Page Up, Page Down, Home, End, Enter) to navigate and select lines in the list.
.
- Clicking or pressing "Enter" on a selected line in the list inserts the selection into the editor.
.
- You can access specialized content assist features inside Javadoc comments.

Configure the behaviour of the content assist in the Editor preference page (Code Assist tab).
Using content/code assist
1. Place your cursor in a valid position on a line of code in an editor and either
- Press Ctrl+Space
.
- Select Edit > Content Assist from the menu bar
If the Java editor finds valid candidates for this position, a list of possible completions is shown in a floating window. You can type further to narrow the list. You can also hover over the selected list items to view its Javadoc information, if it is available.
2. Use the arrow keys or the mouse pointer to navigate through the possible completions.
3. Select an item in the list to complete the fragment by doing one of the following:
- Selecting it and pressing Enter
.
- Double-clicking it
Note: When a list item is selected, you can view any available Javadoc information for this item in hover help. Note that you must click an item to select it in the list before you can view Javadoc hover help for it.
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.

.
- 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.
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.

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).
_____________
Author: Mikalai Zaikin. Please Click Here to visit Authors site for any updates and changes to the study notes.
Trackback(0)
|