Using templates
To use templates:
- In the Java editor, position the caret in a place where you want to insert a template.
- Invoke content assist by pressing Ctrl+Space.
- Templates appear in the presented list. Note that the list is filtered as you type, so typing a few first characters of a template name will reveal it.
- Note that a preview is presented for each selected template.
Notes:
Templates can have variables, which are place-holders for the dynamic part of a template pattern, e.g. subject to change with every application of the particular template.
When a template is inserted in the Java editor and the template pattern contained a template variable, the editor enters the template edit mode.
The first variable is underlined and selected. The variable can be modified by typing in the editor. If the same variable existed multiple times in the template pattern, all instances of the same variable are updated instantaneously to save typing.
Pressing Tab navigates to the next unique template variable, Shift-Tab navigates to the previous unique template variable.
The template edit mode is left by either pressing Tab on the last template variable or pressing Esc or Enter.
Example:
- Create a method void m(int[] intarray){} and position the caret inside the method.
- Type for and press Ctrl+Space to open Code Assist
- Select the first entry from the list (i.e.for - iterate over array). Note the template preview window.
- Note also that the name of the array (i.e. intarray) is automatically detected.
- The local variable i is now selected and you are in the template edit mode. Typing another name instantaneously updates all occurrences of it.
- Press Tab. You can now modify the suggested name for the array (pressing Shift-Tab will let you modify the name of the local variable again).
- To leave the template edit mode
- press Tab or Enter, which will move the caret so that you can enter the body of the newly created loop or
- press Esc, which will not move the caret and preserves the current selection in the editor.
Using the Java editor
Writing your own templates