The Templates preference page allows to create new and edit existing templates. A template is a convenience for the programmer to quickly insert often reoccurring source code patterns.
The following buttons allow manipulation and configuration of templates:
Action |
Description |
---|---|
New... |
Opens a dialog to create a new template. |
Edit... |
Opens a dialog to edit the currently selected template. |
Remove |
Removes all selected templates. |
Import... |
Imports templates from the file system. |
Export... |
Exports all selected templates to the file system. |
Export All... |
Exports all templates to the file system. |
Enable All |
Enables all templates. |
Disable All |
Disables all templates. |
Use Code Formatter |
If enabled, the template is formatted according to the code formatting rules specified in the Code Formatter preferences, prior to insertion. Otherwise, the template is inserted as is, but correctly indented. |
Creating a new template and editing an existing template uses the same dialog, which is described here.
The following fields and buttons appear in the dialog:
Option |
Description |
---|---|
Name |
The name of the template. |
Context |
The context determines where the template can be used and the set of available pre-defined template variables.
|
Description |
A description of the template, which is displayed to the user when choosing the template. |
Pattern |
The template pattern. |
Insert Variables... |
Displays a list of pre-defined context specific variables. |
Both Java and Javadoc context define the following variables:
Variable |
Description |
---|---|
${cursor} |
Specifies the cursor position when the template edit mode is left. This is useful when the cursor should jump to another place than to the end of the template on leaving template edit mode. |
${date} |
Evaluates to the current date. |
${dollar} |
Evaluates to the dollar symbol '$'. Alternatively, two dollars can be used: '$$'. |
${enclosing_method} |
Evaluates to the name of the enclosing name. |
${enclosing_method_arguments} |
Evaluates to a comma separated list of argument names of the enclosing method. This variable can be useful when generating log statements for many methods. |
${enclosing_package} |
Evaluates to the name of the enclosing package. |
${enclosing_project} |
Evaluates to the name of the enclosing project. |
${enclosing_type} |
Evaluates to the name of the enclosing type. |
${file} |
Evaluates to the name of the file. |
${return_type} |
Evaluates to the return type of the enclosing method. |
${time} |
Evaluates to the current time. |
${user} |
Evaluates to the user name. |
The Java context additionally defines the following variables:
Variable |
Description |
---|---|
${array} |
Evaluates to a proposal for a declared array name. |
${array_element} |
Evaluates to a proposal for an element name of a declared array. |
${array_type} |
Evaluates to a proposal for the element type of a declared array. |
${collection} |
Evaluates to a proposal for a declared collection implementing
|
${index} |
Evaluates to a proposal for an undeclared array index iterator. |
${iterator} |
Evaluates to a proposal for an undeclared collection iterator. |
Using
templates
Writing
your own templates