Writing your own templates
You can define your own templates.
- Go to Window > Preferences > Java > Templates
and press the New button.
- In the Name field, enter the name for the template. This name need
not be unique. It is used for selecting templates from the Code Assist list.
- Specify the context for the template using the Context combo-box:
- Select java if the template is to be used in normal Java code
- Select javadoc if the template is to be used in Javadoc comments
- In the Description field, enter a brief description of the template.
- Use the Pattern text field to enter the the template pattern
The pattern may contain pre-defined and custom template variables.
Template variables are place-holders for the dynamic part of the template
pattern, i.e. they are different in every application of the particular template.
Before a template is inserted, the variables in its pattern are evaluated
and the place-holders are replaced with the evaluated values. Variables are
of form ${variable_name}
.
- To insert a pre-defined template variable, use the Insert Variable
button or press Ctrl+Space and select the variable from the
presented list.
- You can insert your own template variables, which then evaluate to
the name of the variable itself. You must, however, make sure that the
name does not conflict with the pre-defined template variable names in
the specific context.
- If the dollar symbol
$
should be displayed, it must be
escaped by using two dollar symbols or using the variable ${dollar}
.
Templates
Using the Java editor
Using templates
Template preference page