Source panes and some other dialogs and browsers (for example, the Configure Breakpoints dialog) contain code assist, a tool to help you find the classes, methods, and fields you are looking for without having to refer to class library reference information. Code assist is accessed by typing Ctrl+Spacebar.
When you type Ctrl+Spacebar, classes methods, and types that could be inserted in the code at the cursor are shown in a pop-up list, from which you can select one. Code assist performs a visibility check and classes, methods, and fields that are not visible are not displayed. If the code assist mechanism cannot find a member that fits the current location of the cursor, the information line at the bottom of the pane will indicate that no code assist is available for the current context.
Code Assist for Types
To insert the name of a class or interface in your code, enter the first one or
more letters of the type name, and then type Ctrl+Spacebar. A pop-up list appears,
containing types that start with what you have entered. Enter more letters to narrow
down the list. Select an item to insert it into your code at the cursor. If
the type needs to be qualified, the qualification is also automatically inserted.
Example:
Create a test project and package. In the test package, create a class called AssistTest. In the AssistTest class, create a method called assistMethod. Suppose you want to declare a local Integer variable, i. In the body of the assistMethod source, type the following letters:InType Ctrl+Spacebar. The list of available types is long. To find "Integer," enter the letters "te". Now, "Integer" will be near the top of the list. Select it using the arrow keys and Enter.
Now, finish the declaration, so that the method looks like this:
public void assistMethod() { Integer i; }Save the method by typing Ctrl+S. You will use this test method in the next example.
Code Assist for Methods and Fields
Code assist will also list the methods and fields available for an object or
class. Enter objectName., and optionally one or more letters from
the start of the method or field name, and then type Ctrl+Spacebar. The list of
methods and fields for the object will pop-up. Select one to insert it in the code.
Example:
In the assistMethod method you created in the previous example, below the line that declares i, enter the following code (the period is important):i = Integer.Type Ctrl+Spacebar. A list of methods and fields in Integer will pop up. Enter the letters "val", until you find "valueOf(String) Integer". The parameter types (in this case "String") and return type ("Integer") are shown.
Select "valueOf(String) Integer", and it will be inserted into your code. Enter a string such as "35" between the parentheses and end the line with a semi-colon. The method source will now look like this:
public void assistMethod() { Integer i; i = Integer.valueOf("35"); }
If you request code assist for a method or field from a class that requires qualification, the class must be qualified before you type Ctrl+Spacebar. Otherwise, no code assist will be available. Generally, the code that appears before the cursor must be compilable before you request code assist.
Example:
Suppose java.util.* is not in your class' import statement. This means that the class ResourceBundle must be qualified when you use it in your class. If you type the following code, and then type Ctrl+Spacebar to get the list of methods available, no list will be available:public String newMethod ( ) { ResourceBundle a = ResourceBundle. // place cursor after period // and type Ctrl+SpacebarHowever, if you type the following code, where the class qualification is provided, code assist is available:
public String newMethod ( ) { ResourceBundle a = java.util.ResourceBundle. // place cursor after period // and type Ctrl+Spacebar
An easier way to produce a qualified name in this case (assuming you do not want to add this class or package to the import list) is to place the cursor before the period and type Ctrl+Spacebar. Select the class name from the list and it will be fully qualified for you automatically. Then type the period and Ctrl+Spacebar. The list of methods in ResourceBundle will now pop-up.
Code Assist for Method Parameters
Code assist includes pop-up help for method parameters. For example when you select
"valueOf(String) Integer" from the pop-up list in an example, above, the
following text is inserted at the cursor:
valueOf()
The cursor is automatically placed between the parentheses, and the pop-up label "String" appears to let you know what type of parameter to add.
Important to Note: