blob: 1fa51f6b4c2533ad0bd336e2b79a13ad80619ab4 [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>
Code 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>
Code templates
</h1>
<p>The
<a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)")'>
<img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
<b>Java &gt; Code Style &gt; Code Templates</b></a> preference page
lets you configure the format of newly generated code and comments.</p>
<h2>Code and Comments</h2>
<p>The code and comment page contains code templates that are used by actions that generate code. Templates contain variables that are substituted when the template is applied. Some variables are available in all templates, some are specific to templates.</p><table
border="1" cellspacing="0" cellpadding="5" width="600">
<thead>
<tr>
<th>
<p>Action</p>
</th>
<th>
<p>Description</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top" width="25%">
<p>Edit...</p>
</td>
<td valign="top">
<p>Opens a dialog to edit the currently selected code template.</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Import...</p>
</td>
<td valign="top">
<p>Imports code templates from the file system.</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Export...</p>
</td>
<td valign="top">
<p>Exports all selected code templates to the file system.</p>
</td>
</tr>
<tr>
<td valign="top">
<p>Export All...</p>
</td>
<td valign="top">
<p>Exports all code templates to the file system.</p>
</td>
</tr>
</tbody>
</table>
<h3>Comment templates</h3>
<p>Comment templates can contain the variable <b>${tags}</b> that will be substituted by the standard Javadoc tags (@param, @return..) for the commented element.
The 'Overriding method' comment can additionally contain the template <b>${see_to_overridden}</b></p><ul>
<li>Getter comment: Template that specifies the comment for a getter method</li>
<li>Setter comment: Template that specifies the comment for a setter method</li>
<li>Constructor comment: Template that specifies the comment for new constructors</li>
<li>File comment: Template that specifies the header comment for newly created files. Note that this template can be referenced in the 'New Java File' template</li>
<li>Type comment: Template that specifies the comment for new types. Note that this template can be referenced in the 'New Java File' template</li>
<li>Field comment: Template that specifies the comment for new fields. Note that this template can be referenced in the 'New Java File' template</li>
<li>Method comment: Template that specifies the comment for new methods that do not override an method in a base class</li>
<li>Overriding method comment: Template that specifies the comment for new methods that override an method in a base class. By default the comment is defined as a non-Javadoc comment (Javadoc will replace this comment with the comment of the overridden method). You can change this to a real Javadoc comment if you want</li>
</ul>
<h3>New Java files template</h3>
<p>The 'New Java files' template is used by the New Type wizards when a new Java file is created. The template can specify where comments are added. Note that the template can contain the variable <b>${typecomment}</b> that will be substituted by the evaluation of the type comment template.</p>
<h3>Catch block body template</h3>
<p>The 'Catch block body' template is used when a catch block body is
created. It can use the variables <b>${exception_type}</b> and <b>${exception_var}</b>.</p>
<h3>Method body template</h3>
<p>The 'Method body' templates are used when new method with a body is created that still needs some code to complete its functionality. It contains the variable
<b>${body_statement}</b> that resolves to a return statement or/and a super-call. </p>
<h3>Constructor body template</h3>
<p>The 'Constructor body' templates are used when new method or constructor with body is
created. It contains the variable <b>${body_statement}</b> that resolves a super call.<b></b></p>
<h3>Getter body template</h3>
<p>The 'Getter body' templates are used when new getter method is created
. It contains the variable <b>${body_statement}</b> that resolves to the appropriate return statement.<b></b></p>
<h3>Setter body template</h3>
<p>The 'Setter body' templates are used when new setter method is created
. It contains the variable <b>${body_statement}</b> that resolves to the appropriate assignment statement.<b></b></p>
<p>
&nbsp;
</p>
<h2>Code Template dialog</h2>
<p>The following fields and buttons appear in the dialog:</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>Description</p>
</td>
<td valign="top">
<p>A description of 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 template specific variables.</p>
</td>
</tr>
</tbody>
</table><p>
<img src="../images/ngrelt.png" alt="Related tasks" border="0"
></p>
<p>
<a href="../tasks/tasks-57.htm">Generating getters and setters</a>
</p>
<p>
<img border="0" src="../images/ngrelr.png" alt="Related reference"></p>
<p>
<a href="../reference/ref-menu-source.htm">Source actions</a><br>
<a href="../reference/ref-java-editor.htm">Java editor</a><br>
<a href="../reference/ref-21.htm">Java editor preferences</a><br>
<a href="../reference/ref-preferences-templates.htm">Templates preferences</a>
</p>
</body>
</html>