Smart.Templates - Pro!

This tool introduces advanced templates concept and offers a lot of new possibilities and usability features. Smart.Templates may be invoked using usual Ctrl+J (CUA) shortcut or by typing template name and pressing Tab (by default) key. There is also possibility to expand last used template by pressing Ctrl+Shift+J (CUA) shortcut. This is useful if template is defined as one that may store and utilize user input collected during previous invocation.

The purpose of this tool is ability to maintain, easy find and paste frequently used code snippets (templates hereafter) to the currently editing document.

JBuilder built-in templates represents usual code fragment, which pastes "as is" and may be optionally formatted according to project code style (built-in templates only). Such a templates concept suits well for simple needs while leaving lots of manual modifications of paste code for most of complicate cases.

Smart.Templates provides all functionality offered by build-in JBuilder templates and correctly indents the code fragment and optionally formats it according to current indent level and braces' style. To minimaze efforts needed to fit templates to the developers' needs the concept of advanced templates is used. The main difference of this concept is ability to specify template fields inside the code snippet.

Each field is represented by its own name enclosued by # sign written right in the code snippet. In this case template acts as "live" running form rather then simple code fragment. On template expansion, all the code outside fields is pasted exactly as it is defined, while fields are represented by a set of editors those allows entering values using usual way. Each field "editor" has each own border and the focused one has the special border, which highlights it.

There is ability to navigate through all the fields using the Tab and Shift+Tab shortcuts. The Enter and Shift+Enter shortcuts allow navigating through the fields skipping ones with the same type.

Smart Template with Fields
Smart Template with Fields
It's possible to invoke another tools like Member Insight for selecting values of template fields.

Entering Field Value Using Member Insight
Entering Field Value Using Member Insight

The following major features are applicable to template fields:

Expanded template enters the "running" state after invocation and user is able to fill template fiels. A running template can be completed by pressing Esc key, changing code outside of any template fields (if appropriate option is turned on) or by filling all fields and using Enter key to navigate between them.

After the completion of running template, all the code written in the field "editor' is pasted directly to the document and the editor caret is optionally placed to the position specified by location of predefined field #|# (if one is included into template definition).

In addition, the Smart.Templates tool introduces the following features:

Predefined Fields

The following table outlines predefined template fields which always available to any template definition.

Field Name Description
| Specifies the location should be used for caret after template completion
selBlock Inserts content of the code block has been selected before the template expansion.
selBlock.asComment Inserts a code block has been selected before the template expansion and transforms it into a Java block comment.
selBlock.asString Inserts a code block has been selected before the template expansion and correctly transforms it to a Java string.
currentDate Inserts current date string.
currentDateTime Insert current date and time string.

Expressions

The most powerful feature of Smart.Templates is ability to specify expressions needed to be evaluated during template execution. This allows developing truly "smart" and dynamic templates those can be easy adapted to developers' needs. In general, any expression should conform to expressions' definition rules in Java language and can contains only the following lexemes:

The Smart.Templates provides automatic types conversion during evaluation of expressions so expression can contains literals, variables and functions with different types and/or return types. If possible, all these different types will be correctly cased.

The following functions are available:

Utility Functions

Functions are included into this group are intended to suit miscellaneous utility purposes.

String getLocalVariableName(String aType)

Composes variable name based on passed variable type.

Parameters: aType - string that represents variable type

Return: name for variable based on variable type

String getVariableInitValue(String aType)

Composes variable initialization value based on passed variable type.

Parameters: aType - variable type

Return: variable initialization value. It will be -1 for numeric types, false for boolean and null for any other Java type.

Template Functions

Functions are included into this group allow gaining access to any field within running template.

String getFieldValue(String aName)

Returns current value of the template field

Parameters: aName - name of the field

Return: value of the field; null if field with passed name is not found

void saveFieldValue(String aName)

Saves field value as string to allow it future use

Parameters: aName - name of the field

void saveFieldValueAsInteger(String aName)

Saves field value as integer to allow it future use

Parameters: aName - name of the field

Object loadFieldValue(String aName, Object aDefaultValue)

Obtains previously saved field value

Parameters:

 aName - name of the field

 aDefaultValue - optional default value

Return: previously saved field value; if field value was not saved before it returns aDefaultValue or null if default value is not specified.

System Functions

Functions from this group provide access to some of system properties and resources.

String getSystemProperty(String aName)

Obtains the value of system property

Parameters: aName - name of system property to get

Return: value of system property; null if property with such name is not found

String getDate(String aFormat)

Obtains string representation of current date according to optional format

Parameters: aFormat - optional parameter that defines the form of date output. The valid values are "SHORT", "MEDIUM", "LONG", "FULL".

Return: string representation of current date

String getDateTime(String aDateFormat, String aTimeFormat)

Obtains string representation of current date and time according to optional format

Parameters:

 aDateFormat - optional parameter that defines the form of date output. The valid values are "SHORT", "MEDIUM", "LONG", "FULL".

 aFormat - optional parameter that defines the form of time output. The valid values are "SHORT", "MEDIUM", "LONG", "FULL".

Return: string representation of current date and time

String Functions

Functions from this group provide different string manipulation routines.

String toUpper(String aString)

Converts passed string to upper case.

Parameters: aFormat - string need to be converted.

Return: string converted to upper case

String toLower(String aString)

Converts passed string to lower case.

Parameters: aFormat - string need to be converted.

Return: string converted to lower case

String toggleCase(String aString)

Converts passed string so each character of it became toggled from lower case to upper one and vice versa.

Parameters: aFormat - string need to be converted.

Return: converted string

String toConst(String aLiteralValue)

Composes name for string literal based on passed literal value. It is composed as "C" style constant where locations of underscores are match to locations of characters in upper case in the literal value.

Parameters: aLiteralValue - string literal value

Return: name for string literal based on literal value

String fromConst(String aLiteralName)

Composes value for string literal based on passed literal name using the same rules as for composing name for literal based on its value.

Parameters: aLiteralName - string literal value

Return: value for string literal based on literal name

String capitalize(String aString)

Capitalizes the first letter of passed string.

Parameters: aString - string to capitalize

Return: capitalized string value

String deCapitalize(String aString)

Decapitalizes the first letter of passed string.

Parameters: aString - string to decapitalize

Return: decapitalized string value

String subString(String aString, String aStringToFind)

Obtains a new string by trimming the right part of passed one starting from occurrence of another string.

Parameters:

 aString - string to be trimmed

 aStringToFind - string to find

Return: trimmed string value

String getConstPrefix(String aName)

Obtains the prefix from the passed literal name.

Parameters: aName - name of literal

Return: obtained prefix or passed literal name if prefix can't be obtained

Project and Editor Dependant Functions

Functions included into this group provide access to some properties of the active project and to information about context available for the caret position of the editor.

String getProjectProperty(String aName)

Obtains the value of property of active project

Parameters: aName - name of project property to get

Return: value of project property; null if property with such name is not found

String getFullClassName()

Obtains the name of Java class at caret position

Return: full-qualified name of class

String getClassName()

Obtains the short name of Java class at caret position

Return:short name of class

String getPackageName()

Obtains the package name of Java class at caret position

Return:package name

Smart.Templates.Insight

This tool allows choosing a template to expand. When editing a file, press Ctrl+J (CUA) to invoke Smart.Templates.Insight. The Smart.Templates.Insight popup will be shown with the list of template matching a word at the cursor position. The list may be empty if there are no matching templates though. To find matches, type a word in the Template edit box and Smart.Templates.Insight will dynamically rearrange the list of templates to show the matching ones. You can also leave the Template edit box blank to view all templates.

Smart.Templates.Insight Window
Smart.Templates.Insight Window

You can select a template navigating through the list with the help of the usual keyboard. An alternative way to do it is to continue typing the word; the list selection will be changed to produce the closest match possible. Press the Enter key when you select the template and Smart.Templates.Insight will expand selected one.

"On the Fly" Smart Templates

The main idea of such templates is ability to quickly generate and use template definition based on the block of text. All the repetitive tokens from the block those are not predefined ones will be replaced by the template fields definitions. This approach allows using templates those need one or several times only without having to manually manage template definitions. To invoke "On The Fly" template based on the clipboard content please use Alt+Shift+J (CUA) shortcut. Another option to invoke "On The Fly" template is using Clipboard.Insight. You just need to select required item from the local clipboard list and press Ctrl+Enter shortcut to invoke template based on it.

Options Dependency

You can control Smart.Templates behavior and manage the template list using the Editor Options | Productivity | Smart.Templates property page.

See also: Productivity! Tools , Customizing Productivity!