| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//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"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| |
| <title>Writing your own 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>Writing your own templates</h1> |
| |
| <p>You can define your own templates.</p> |
| |
| <ul> |
| <li>Open 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"> |
| <span class="control">Java > Editor > Templates</span></a> preference page |
| and press the <span class="control">New</span> button.</li> |
| |
| <li>In the <span class="control">Name</span> field, enter the name for the template. This name need not be unique. It is used for selecting templates from the Code Assist |
| list.</li> |
| |
| <li> |
| Specify the context for the template using the <span class="control">Context</span> combo-box: |
| |
| <ul> |
| <li>Select <span class="control">Java</span> if the template is to be used in normal Java code</li> |
| |
| <li>Select <span class="control">javadoc</span> if the template is to be used in Javadoc comments</li> |
| </ul> |
| </li> |
| |
| <li>Uncheck the <span class="control">Automatically insert</span> checkbox, if the template should not be inserted automatically if it is the only proposal available at the caret position.</li> |
| |
| <li>In the <span class="control">Description</span> field, enter a brief description of the template.</li> |
| |
| <li> |
| Use the <span class="control">Pattern</span> text field to enter the template pattern<br> |
| The pattern may contain pre-defined and custom template variables.<br> |
| 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 the form |
| <code>${variable_name}</code>. |
| |
| <ul> |
| <li>To insert a pre-defined template variable, use the <span class="control">Insert Variable</span> button or press <kbd>Ctrl+Space</kbd> and select the variable from |
| the presented list.</li> |
| |
| <li>You can insert your own template variables, which will 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.</li> |
| |
| <li>If the dollar symbol <code>$</code> should be displayed, it must be escaped by using two dollar symbols or by using the variable <code>${dollar}</code>.<br> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| |
| <p><img border="0" src="../images/ngrelc.png" alt="Related concepts" ><br> |
| <a href="../concepts/ctemplates.htm">Templates</a></p> |
| |
| <p><img border="0" src="../images/ngrelt.png" alt="Related tasks" ><br> |
| <a href="tasks-54.htm">Using the Java editor</a><br> |
| <a href="tasks-171.htm">Using templates</a></p> |
| |
| <p><img border="0" src="../images/ngrelr.png" alt="Related reference"><br> |
| <a href="../reference/ref-preferences-templates.htm">Template preference page</a></p> |
| |
| |
| </body> |
| </html> |
| |