Aqua 2024.3 Help

Edit Template Variables dialog

If a live template contains user-defined variables, you can use the Edit Template Variables dialog to configure expressions that define those variables.

Controls

Item

Description

Name

In this field, view or edit the variable name in the format $<variable_name>$.

Expression

In this field, specify the expression to have the value of the corresponding template input field calculated automatically.

This expression may contain the following constructs:

  • String constants in double quotes

  • Names of other variables defined in a live template

  • with possible arguments

Type an expression manually or select a predefined function from the list. The list shows also the number and type of parameters, if any, for the selected function. The available functions are listed alphabetically in the Functions table.

Default value

In this field, specify the default string to be entered in the corresponding input field of the expanded template, if the expression does not give any result after calculation.

Note that a default value of a variable is an expression that can refer to other live template variables. To define the default value as a literal, enclose it in quotation marks.

Skip if defined

Select this checkbox to have Aqua proceed with the next input field, if the value of the current input field is defined.

Move Up / Move Down

Use these buttons to change the order of variables in the list. The order of variables in the table determines the order in which Aqua will switch between the corresponding input fields when the template is expanded.

Functions used in live template variables

Item

Description

annotated(<annotation>)

Returns a class, method, or field annotated with the specified qualified name. If there is more than one program element with the specified annotation in your project, it shows a list from which you can choose.

For example, annotated("java.lang.Deprecated") returns all program elements annotated with @Deprecated.

Some predefined live templates in the RESTful Web Services and Web Services groups use the annotated() function.

arrayVariable()

Returns the most recently declared array in the current scope (as a method variable or class field). If there is more than one array declared in the current scope, it also shows a list from which you can choose.

For example, if you have the following method and expand a template with a variable that uses the arrayVariable() function after both array declarations, it will return the b array by default and also suggest to choose a, along with other arrays defined as class fields:

public String getCode() { int a[] = new int[5]; int b[] = new int[10]; return code; }

Some predefined live templates in the iterations group (itar and ritar) use the arrayVariable() function.

blockCommentEnd()

Returns the characters that indicate the end of a block comment in the current language context.

blockCommentStart()

Returns the characters that indicate the start of a block comment in the current language context.

camelCase(<String>)

Converts a string into camelCase.

For example, camelCase("my-text-file"), camelCase("my text file"), and camelCase("my_text_file") all return myTextFile.

capitalize(<String>)

Capitalizes the first letter of a string.

For example, capitalize("name") returns Name. Or you can combine it into capitalize(camelCase("my awesome class")) to get MyAwesomeClass.

capitalizeAndUnderscore(<String>)

Capitalizes all the letters of a string, and inserts an underscore between the parts.

For example, capitalizeAndUnderscore("FooBar"), capitalizeAndUnderscore("foo bar"), and capitalizeAndUnderscore("foo-bar") all return FOO_BAR.

castToLeftSideType()

Casts the right-side expression to the left-side expression type if necessary.

Some predefined templates in the iterations group use the castToLeftSideType() function to have a single template for both raw types and generic types.

Compare to rightSideType().

className()

Returns the name of the current class (where you expand the template). Can be useful for constructor templates.

Available in the Java context only.

clipboard()

Returns the contents of the system clipboard.

commentEnd()

Returns the characters that indicate the end of a comment in the current language context. For languages with line comments, the return value is empty.

commentStart()

Returns the characters that indicate the start of a comment in the current language context. For languages with line comments, the return value is the start of a line comment, same as lineCommentStart().

complete()

Invokes code completion at the position of the variable.

completeSmart()

Invokes smart type completion at the position of the variable.

componentTypeOf(<array>)

Returns the component type of an array.

For example, you can pass the return value of arrayVariable() to the componentTypeOf() function. The itar template uses this logic to properly specify the iterated elements of an array.

Available in the Java context only.

concat(<String>, ...)

Returns a concatenation of all the strings passed to the function as parameters.

For example, concat(date()," ",user()) returns the current system date and username separated with a space.

currentPackage()

Returns the name of the current package (with the class where you expanded the template).

Available in the Java context only.

date([format])

Returns the current system date.

By default, without a parameter, it returns the date in the current system format. To use a different format, provide a parameter according to the SimpleDateFormat specification. For example, the date("Y-MM-d, E, H:m") returns the date formatted as 2020-02-27, Thu, 16:11.

dbColumns()

Returns a list of columns for a table or a view. The dbColumns() is used in context live templates (for example, ins). You can access context live templates by right-clicking an object and selecting SQL Scripts.

dbObjectName()

Returns a name of a table or a view. The dbObjectName() is used in context live templates (for example, top). You can access context live templates by right-clicking an object and selecting SQL Scripts.

decapitalize(<String>)

Replaces the first letter of a string with the corresponding lowercase letter.

For example, decapitalize("Name") returns name.

defaultReturnValues

Returns the default value if the expression is used in the return statement. Uses the errorVariableName parameter if the expression is of the error type.

descendantClassEnum(<String>)

Returns the children of the specified class.

If there is more than one child, it shows a list of subclasses from which you can choose. For example, descendantClassEnum("java.lang.Number") returns all the number type classes, such as, java.lang.Float, java.math.BigDecimal, and so on.

Available in the Java context only.

enum(<String>, ...)

Returns a list of strings suggested for completion when the template expands.

For example, enum("Foo","Bar","Baz") shows a list from which you can choose one of the specified strings.

escapeString(<String>)

Escapes special characters so that the result can be used in a Java string.

For example, it replaces the tab character with \t, the newline character with \n, escapes the backslash as \\, quotes as \", and so on.

expectedType()

Returns the expected type of the expression where the template expands (in the right part of an assignment, after return, as a method parameter, and so on).

Available in the Java context only.

fileName()

Returns the name of the current file with its extension.

fileNameWithoutExtension()

Returns the name of the current file without its extension.

filePath()

Returns the absolute path to the current file.

fileRelativePath()

Returns the current file path relative to the current project. To check what the relative path is for a given file, right-click it and select Copy Reference, or press Ctrl+Alt+Shift+C.

firstWord(<String>)

Returns the first word of the string passed as the parameter.

For example, firstWord("one two three") returns one.

groovyScript(<String>, [arg, ...])

Executes the Groovy script passed as a string.

The first argument is a string with either the text of the script or the path to the file that contains the script. The function passes other optional arguments to the script as values for _1, _2, _3, ..., _n variables. Also, you can access the current editor from inside the script using the _editor variable.

The following example shows a groovyScript() function that converts a given string (the value of another variable, $MyVar$) to upper case letters:

groovyScript("_1.toUpperCase()", MyVar)

The following example shows a groovyScript() function that splits the selected text into words and displays them as a numbered list:

groovyScript("def result = ''; _1.split().eachWithIndex { item, index -> result = result + index.next() + '. ' + item + System.lineSeparator() }; return result;", SELECTION)

The last example uses the SELECTION predefined variable meaning you have to select text and press Ctrl+Alt+T (Surround with) to apply it.

guessElementType(<Collection>)

Returns the likely type of elements stored in a java.util.Collection. Aqua looks for code that adds or extracts elements from a collection to define their type.

iterableComponentType(<Iterable>)

Returns the type of an iterable object, such as an array or a collection.

Available in the Java context only.

iterableVariable()

Returns the most recently declared iterable object in the current scope (like an array or a collection). If there is more than one iterable object in the current scope, it also shows a list from which you can choose.

The predefined live template iter uses the iterableVariable() function.

Available in the Java context only.

lineCommentStart()

Returns the characters that indicate the start of a line comment in the current language context.

lineNumber()

Returns the current line number.

lowercaseAndDash(<String>)

Converts a string into lower case and inserts n-dashes as separators. For example, lowercaseAndDash("MyExampleName") and lowercaseAndDash("my example name") both return my-example-name.

methodName()

Returns the name of the method in which the template expands.

Available in the Java context only.

methodParameterTypes()

Returns the list of parameter types of the method in which the template expands.

Available in the Java context only.

methodParameters()

Returns the list of parameter names of the method in which the template expands.

Available in the Java context only.

methodReturnType()

Returns the type of the value returned by the current method in which the template expands.

Available in the Java context only.

qualifiedClassName()

Returns the fully qualified name of the current class in which the template expands.

Available in the Java context only.

regularExpression(<String>, <Pattern>, <Replacement>)

Finds all occurrences of Pattern in a String and replaces them with Replacement. You can specify the pattern as a regular expression to find everything that matches it in the string.

For example, the regularExpression(NAME, "a", "b") expression will replace any letter "a" in the $NAME$ template variable with the letter "b". You can use regexp character classes in the pattern part; for example, regularExpression(NAME, "[a-z]", "b") will replace any letter in the variable. If you want patterns, such as \d or \w, to be considered as regexp character classes, you have to escape the slash so that your pattern looks like "\\d".

rightSideType()

Declares the left-side variable with a type of the right-side expression.

Some predefined templates in the iterations group use the rightSideType() function to have a single template for both raw types and generic types.

Compare to castToLeftSideType().

snakeCase(<String>)

Converts a string into snake_case. For example, snakeCase("fooBar") and snakeCase("foo bar") both return foo_bar.

spaceSeparated(<String>)

Returns the specified string with spaces as separators. For example, spaceSeparated("fooBar") returns foo Bar and spaceSeparated("Foo_BAR") returns Foo BAR.

spacesToUnderscores(<String>)

Replaces spaces with underscores in the string passed as the parameter. For example, spacesToUnderscores("foo bar BAZ") returns foo_bar_BAZ.

substringBefore(<String>, <Delimeter>)

Returns the substring up to the specified delimiter. This is helpful for removing the extensions in test file names. For example, substringBefore(fileName(),".") returns component-test if used in a file named component-test.js.

subtypes(<String>)

Returns the subtypes of the type passed as a string in the current scope.

The predefined lazy live template uses the subtypes(typeOfVariable(VAR)) function to perform lazy initialization of a variable with one of its subtypes.

Available in the Java context only.

suggestFirstVariableName(<String>)

Returns all variables that may be assigned to the type passed as the parameter in the given context.

This is similar to variableOfType() but it does not suggest true, false, this, and super.

suggestIndexName()

Returns a suggested name for the index variable in an iteration from most commonly used ones: i, j, k, and so on (the first one that is not used in the current scope).

Some of the predefined templates in the iterations group (fori, itar, ritar) use the suggestIndexName() function to suggest a suitable index variable name.

suggestVariableName()

Suggests the name for a variable based on the variable type and its initializer expression, according to your code style settings that refer to the variable naming rules.

For example, if it is a variable that holds an element within an iteration, Aqua makes a guess on the most reasonable name taking into account the name of the iterated container. Some of the predefined templates in the iterations group (itar, itco, iten) use the suggestVariableName() function to suggest a suitable variable name for iterated elements.

time([format])

Returns the current system time.

By default, without a parameter, it returns the time in the current system format. To use a different format, provide a parameter according to the SimpleDateFormat specification. For example, the time("H:m z") returns the time formatted as 13:10 UTC.

typeOfVariable(<String>)

Returns the type of the variable passed as the parameter.

Available in the Java context only.

typeParameterOf(VAR[,indexOrName])

Returns the type of an object parameter (for example, of a collection element). It accepts two parameters:

  • VAR: the name of the variable (can be another live template variable)

  • indexOrName: the 0-based index of the parameter, the type of which you want to retrieve. It can also be the name of a type variable. If omitted, the type of the first parameter is returned.

For example, typeParameterOf(NAME, "1") returns the type of the second parameter of the NAME variable, and typeParameterOf(NAME, "K") returns the type of the K parameter of the NAME variable.

Available in the Java context only.

See also the Java itm live template for an example of the function implementation.

underscoresToCamelCase(<String>)

Transforms a string with underscores (like snake_case) into camelCase. For example, underscoresToCamelCase(foo_bar_baz) and underscoresToCamelCase(FOO_BaR_baZ) both return fooBarBaz.

underscoresToSpaces(<String>)

Transforms underscores in a string to spaces. For example, underscoresToSpaces(foo_bar_baz) returns foo bar baz and underscoresToSpaces(FOO_BaR_baZ) returns FOO BaR baZ.

user()

Returns the name of the current user.

variableOfType(<String>)

Returns all variables that may be assigned to the type passed as the parameter. For example, variableOfType("double"), variableOfType("java.util.Vector"), or variableOfType(methodReturnType()).

If you pass an empty string "" as the parameter, the function suggests all variables regardless of their types.

Unlike suggestFirstVariableName(), this function also returns standard expressions, such as true, false, this, and Outer.this.

Last modified: 24 September 2024