How to use Code Completion
Code completion has been improved in several ways.
- Code completion behavior Ctrl+Space lists symbols which are already imported in your source file, plus of course symbols from the java.lang package. Pressing Ctrl+Space
again will list all symbols from the project class path whether
imported or not. If you want to go to the list of all types immediately
you can use the All Symbols Completion, which is invoked by pressing Ctrl+Alt+Space.
- Smart completion - Notice that the standard completion listbox is divided into two parts separated by a black line. The first section includes smart completion items.
The editor chooses these items based on the current context (i.e.
around the current caret position) when completion is invoked. See
other bullet points below starting with "smart" for more information
and examples of this smart completion feature.
- Completing Keywords You may use code completion for
completing keywords: the editor knows which keywords fit into which
place in your code. Just don't be surprised if you don't see the
keyword if. It is so short that we decided not to put it into code completion.
- Field/Variable names When you introduce a new field or
variable, you often want its name to mimic its type. Code completion
now supports this. To prepend a prefix to the guessed name, simply type
the prefix and then invoke code completion. This works for method names
as well.
- Smart completion examples Here is a list of places where smart completion kicks in.
- After new (with generics) This will help especially when you are declaring a field or variable with complicated generics.
- In method call parameters Smart completion will offer only those fields, variables, methods which can be passed as an argument to the method.
- Smart code completion for types
- For exceptions In a catch block smart completion will offer only those exceptions which have been thrown in the try block but not yet caught.
- Parameter guessing Code completion of method calls
guesses which variable, field or parameter should be used based on type
and similarity of the name. See the screenshot to see how the correct
variables were picked by code completion when completing the call to
the createRectangle() method.
- Code completion ending character Notice that you may select the item of choice with different keys. Selecting with Enter you'll get what you expect. Should you select the item with ".", "," or ";" code completion will append the character you typed at the end of the completed word.
- Generics in generation of implementation
- Creation of elements - Invoking code completion between
class members will offer to create a constructor (either a default
constructor or one initializing uninitialized fields), override methods or implementation methods. For more code generation features please look at the code generation dialog section.
- Completion for annotations
- Completion in Collections.<String>| - works fine when Collections is imported.
-- Wagner R. Santos |
|