Java Reference
In-Depth Information
Using template variables
As you can see in the File Templates dialog's Description box and accompanying
help text, special template variables fill in the pieces of the template that change
from file to file. Template variables start with a dollar sign and can be surrounded
by curly braces. Java classes can use the following predefined template variables:
PACKAGE_NAME —The name of the package in which the class was created
USER —The user creating the class (as determined by Java system properties)
DATE —The current date
TIME —The current time
You can define your own variables by using them in
your template text. When you create a new file using
your template, IDEA prompts you to define any vari-
able it doesn't recognize, as shown in figure 12.11.
IDEA uses Jakarta's Velocity Template
Engine for its file templates. Velocity is a
full-featured scripting language, and
you can create complex templates with
it. Visit http://jakarta.apache.org/veloc-
ity/ to learn more about Velocity and its
advanced scripting capabilities.
TIP
Template formatting
Each template has a Reformat according to style
option. If it's enabled, any source file created from
the template is automatically reformatted accord-
ing to the user's code style settings. This means you
don't have to worry about things such as indentation and spacing, because they're
corrected at creation time. It also means templates are portable across projects
and users, regardless of their code formatting preferences. If this option is dese-
lected, the template creates files unchanged from the template's formatting.
Figure 12.11 Custom templates
request data for parameters they
don't implicitly understand.
Defining a new file template
To create a new template, click the Create Template icon (the plus sign) in the
File Templates dialog and specify a meaningful name for the template. This
name will be the label used to identify the template when creating new files. Make
sure the file extension field is set to the appropriate type; for a Java class, the
 
 
 
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search