GoLand 2022.2 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

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

  • Predefined functions 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 GoLand 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 GoLand will switch between the corresponding input fields when the template is expanded.

Functions used in live template variables

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.

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.

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.

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.

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.

errorVariable()

Returns the first error variable in the current context. Autocompletes all error variables in the current context.

errorVariableDefinition(expressionWithErrorResult)

Converts an expression to the variable definition if the expression returns the error type. For example, if the a() function returns (int, error), the errorVariableDefinition("a()") expression returns _, err.

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.

fieldName()

Returns the first field name in the current context. Autocompletes all field names in the current context.

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 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);

goFunctionParameters()

Suggests the list of parameters from the function signature. For example, inside the func exampleFunction(str1, str2 string) function the goFunctionParameters() returns [str1, str2].

the goFunctionParameters variable

goFunctionResultParameters()

Suggests the list of return parameters of the function. For example, inside the func exampleFunction() (str string, i int) function the goFunctionResultParameters() returns [str, i].

the goFunctionResultParameters variable

goSuggestVariableName()

Suggests a variable name in the context of Go code where you have this variable. This expression is used in for and forr live templates. For example, the expression suggests the k for keys, and v for values.

lineCommentStart()

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

lineNumber()

Returns the current line number.

localName()

Qualifies a variable name. The localName expression receives the import path and name. If the path is imported in the file, the expression takes this imported path as a qualifier, otherwise adds a new import. The result is qualifier.name. Note that the expression might skip the qualifier if the file is in the package that is addressed by the import path.

This expression is used in the .sort postfix template. For this template to work, you need a function from the sort package that must be imported.

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.

nonBlankVariable

Receives a list of expressions as input and returns the first expression that is not empty _. For example, _,_,a,b returns a.

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.

showParameterInfo()

Returns the parameter details when adding a parameter to a function or method.

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.

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.

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.

Last modified: 09 February 2022