Inserting Code From a Template

See Also

The Source Editor has a set of customizable code templates for common snippets of code, such as for loops and combinations of Java keywords.

You can generate snippets from these code templates in either of the following ways:

There are also multi-line templates that provide the following benefits:

Creating and Customizing Code Templates

To customize the list of code templates:

  1. Choose Tools > Options.
  2. Click Editor and select the Code Templates tab.
  3. Select a programming language from the Language drop-down list to display the code template list for that language.
  4. Edit, create, and remove templates according to your wishes.

Special Code Template Syntax

When you use the Options window to create code templates, there are several constructs that you can use to customize the way the code template behaves. The table below lists these constructs.

Code Template Syntax Construct Explanation
${cursor} Indicates where the insertion point should go after the code snippet has been added to your code.
${Identifier} Indicates an identifer that needs to be filled in when you use the code template. When you use this construct in a template definition, replace Identifier with the identifer name that you want to appear in the template.
index An attribute that you can use within a ${Identifier} segment to designate that an unused variable name should be generated in the code snippet. For example, you could use ${ind index}.
instanceof="FullyQualifiedType" An attribute that you can use within a ${Identifier} segment to designate the type that the identifier must represent an instance of. For example, you could use ${collection instanceof="java.util.Collection"} where collection is the default identifier in the template and java.util.Collection is the class of which the identifier must represent an instance.
See Also
Using Code Completion
Using the Word Match Feature
Sharing Source Editor Settings

Legal Notices