Special Code Template Syntax

You can use code templates to speed up the entry of commonly used sequences of reserved words and common code patterns. For example, if you enter forc and press the Tab key, it expands into the following:

for (Iterator it = collection.iterator(); it.hasNext();) {
       Object elem = (Object) it.next();
        } 

When you create code templates, there are several constructs that you can use to customize the way the code template behaves. The most useful of these constructs are listed below. You can look at the default IDE code templates in the Options window, under the Tools menu, for examples from which you can learn.

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}.
${selection} Defines a position for pasting a content of the editor selection. Used by selection templates, which appear as hints whenever you select some text in the editor (see next item).
${selection line allowSurround} Defines a selection template by using the allowSurround parameter. When there is an editor selection, a lightbulb is presented to the user, and all the surround-with code templates are listed as possible fixes.
${param_name default="value"} Defines the parameter's default value. Set to empty to create a tab stop.
${param_name editable=false} Can be used to disable user's editing of the parameter. Useful for creating caret locations (tab stops).
${class} Expands to the name of the class surrounding the template expansion location, such as Foo
${classfqn} Same as ${class} , but instead of just the class name expands to the fully qualified class name, such as Bar::Baz::Foo
${superclass} Expands to the name of the superclass of the class surrounding the template expansion location, such as SuperFoo
${method} Expands to the name of the method surrounding the template expansion location, such as foo
${methodfqn} Same as ${method} , but instead of just the class method expands to the fully qualified name, such as Bar::Baz::Foo#foo
${file} Expands to the name of the current file, such as foo_bar.rb
${path} Expands to the name of the current full file path, such as /foo/bar/baz.rb
${unusedlocal defaults="i,j,k"} Picks the name of an unused local variable in the current scope. It will first try each of the candidates listed in the defaults attribute, and if none of those succeed, create another unique name.

Legal Notices