blob: a95be642001fd0506194cb9e1f412808822a4905 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>
Templates
</title>
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
<script language="JavaScript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js"> </script>
</head>
<body>
<h1>
Templates
</h1>
<p>
The
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
<b>Java &gt; Editor &gt; Templates</b></a> 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.
</p>
<p>
The following buttons allow manipulation and configuration of templates:
</p>
<table border="1" cellspacing="0" cellpadding="5" width="100%">
<thead>
<tr>
<th>
<p>
Action
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p>
New...
</p>
</td>
<td valign="top">
<p>
Opens a dialog to create a new template.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Edit...
</p>
</td>
<td valign="top">
<p>
Opens a dialog to edit the currently selected template.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Remove
</p>
</td>
<td valign="top">
<p>
Removes all selected templates.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Import...
</p>
</td>
<td valign="top">
<p>
Imports templates from the file system.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Export...
</p>
</td>
<td valign="top">
<p>
Exports all selected templates to the file system.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Export All...
</p>
</td>
<td valign="top">
<p>
Exports all templates to the file system.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Enable All
</p>
</td>
<td valign="top">
<p>
Enables all templates.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Disable All
</p>
</td>
<td valign="top">
<p>
Disables all templates.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Use code formatter
</p>
</td>
<td valign="top">
<p>
If enabled, the template is formatted according to the code formatting rules specified in the <a href="ref-17.htm">Code Formatter preferences</a>, prior to insertion.
Otherwise, the template is inserted as is, but correctly indented.
</p>
</td>
</tr>
</tbody>
</table>
<h2>
Template dialog
</h2>
<p>
Creating a new template and editing an existing template uses the same dialog, which is described here.
</p>
<p>
The following fields and buttons appear in the dialog:
</p>
<table border="1" cellspacing="0" cellpadding="5" width="100%">
<thead>
<tr>
<th>
<p>
Option
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p>
Name
</p>
</td>
<td valign="top">
<p>
The name of the template.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Context
</p>
</td>
<td valign="top">
<p>
The context determines where the template can be used and the set of available pre-defined template variables.
</p>
<dl>
<dt>
Java
</dt>
<dd>
The Java context
</dd>
<dt>
Javadoc
</dt>
<dd>
The Javadoc context
</dd>
</dl>
</td>
</tr>
<tr>
<td valign="top">
<p>
Automatically insert
</p>
</td>
<td valign="top">
<p>
If selected, code assist will automatically insert the template if it is the only proposal available at the caret position.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Description
</p>
</td>
<td valign="top">
<p>
A description of the template, which is displayed to the user when choosing the template.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Pattern
</p>
</td>
<td valign="top">
<p>
The template pattern.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
Insert Variables...
</p>
</td>
<td valign="top">
<p>
Displays a list of pre-defined context specific variables.
</p>
</td>
</tr>
</tbody>
</table>
<h2>
Template variables
</h2>
<p>
Both Java and Javadoc context define the following variables:
</p>
<table border="1" cellspacing="0" cellpadding="5" width="100%">
<thead>
<tr>
<th>
<p>
Variable
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p>
<strong>${cursor}</strong>
</p>
</td>
<td valign="top">
<p>
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.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${date}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the current date.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${dollar}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the dollar symbol '$'.
</p>
<p>
Alternatively, two dollars can be used: '$$'.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${enclosing_method}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name of the enclosing name.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${enclosing_method_arguments}</strong>
</p>
</td>
<td valign="top">
<p>
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.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${enclosing_package}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name of the enclosing package.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${enclosing_project}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name of the enclosing project.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${enclosing_type}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name of the enclosing type.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${file}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name of the file.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${line_selection}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to content of all currently selected lines.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${primary_type_name}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the name primary type of the current compilation unit.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${return_type}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the return type of the enclosing method.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${time}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the current time.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${user}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the user name.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${word_selection}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the content of the current text selection.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${year}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to the current year.
</p>
</td>
</tr>
</tbody>
</table>
<p>
The Java context additionally defines the following variables:
</p>
<table border="1" cellspacing="0" cellpadding="5" width="100%">
<thead>
<tr>
<th>
<p>
Variable
</p>
</th>
<th>
<p>
Description
</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p>
<strong>${array}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for a declared array name.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${array_element}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for an element name of a declared array.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${array_type}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for the element type of a declared array.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${collection}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for a declared collection implementing <code>java.util.Collection</code>.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${index}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for an undeclared array index iterator.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${iterator}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for an undeclared collection iterator.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${iterable}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for a declared iterable name.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${iterable_element}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for an element name of a declared iterable.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${iterable_type}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for the element type of a declared iterable.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<strong>${todo}</strong>
</p>
</td>
<td valign="top">
<p>
Evaluates to a proposal for the currently specified default task tag.
</p>
</td>
</tr>
</tbody>
</table>
<p>
<img src="../images/ngrelc.png" alt="Related concepts" border="0" ></p>
<p>
<a href="../concepts/ctemplates.htm">Templates</a><br>
</p>
<p>
<img src="../images/ngrelt.png" alt="Related tasks" border="0" ></p>
<p>
<a href="../tasks/tasks-171.htm">Using templates</a><br>
<a href="../tasks/tasks-203.htm">Writing your own templates</a>
</p>
<p>
<img border="0" src="../images/ngrelr.png" alt="Related reference"></p>
<p>
<a href="../reference/ref-143.htm">Java content assist</a><br>
<a href="../reference/ref-preferences-task-tags.htm">Task tag preferences</a><br>
<a href="../reference/ref-preferences-code-templates.htm">Code templates preferences</a><br>
<a href="../reference/ref-preferences-code-generation.htm">Code style preferences</a>
</p>
</body>
</html>