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:
For example, in Java files, you can type Psfb, followed by the spacebar, to automatically generate public static final boolean in Java files.
See Code Template Abbreviations: Quick Reference for a list of abbreviations for Java, JSP, XML, DTD, and CSS files.
For example, to generate public static final boolean, you can type pu, press Ctrl-Spacebar, press the down arrow key twice, and press Enter.
There are also multi-line templates that provide the following benefits:
To customize the list of code templates:
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. |