public class GStringExpression
extends Expression
Represents a GString (interpolated string) expression containing embedded values.
A GString consists of constant string parts and interpolated expression values that are evaluated at runtime.
For example, "hello there ${user how are you"} contains constant strings and user variable expressions.
The type of a GString expression is always ClassHelper.GSTRING_TYPE.
GStrings are expanded lazily during execution.
| Fields inherited from class | Fields |
|---|---|
class Expression |
EMPTY_ARRAY |
| Constructor and description |
|---|
GStringExpression(String verbatimText)Creates an empty GString expression with the given verbatim text. |
GStringExpression(String verbatimText, List<ConstantExpression> strings, List<Expression> values)Creates a GString expression with pre-populated strings and values. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addString(ConstantExpression text)Adds a constant string part to this GString. |
|
public void |
addValue(Expression value)Adds an interpolated expression (value) to this GString. |
|
public Expression |
asConstantString()Converts this GString to a constant string expression by concatenating all string parts. |
|
public List<ConstantExpression> |
getStrings()Returns the constant string parts of this GString. |
|
public String |
getText() |
|
public Expression |
getValue(int idx)Returns the interpolated expression at the specified index. |
|
public List<Expression> |
getValues()Returns the interpolated expressions in this GString. |
|
public boolean |
isConstantString()Indicates whether this GString contains no interpolated values (only constant strings). |
|
public String |
toString() |
|
public Expression |
transformExpression(ExpressionTransformer transformer) |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class Expression |
getType, setType, transformExpression, transformExpressions, transformExpressions |
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Creates an empty GString expression with the given verbatim text.
verbatimText - the original text representation (non-null)Creates a GString expression with pre-populated strings and values.
verbatimText - the original text representation (non-null)strings - the list of constant string parts (non-null)values - the list of interpolated expressions (non-null)Adds a constant string part to this GString.
text - the constant string expression to add (non-null)Adds an interpolated expression (value) to this GString. If this is the first value being added, an empty string constant is prepended to maintain alternation.
value - the expression to add (non-null)Converts this GString to a constant string expression by concatenating all string parts. This is only valid if isConstantString() returns true.
Returns the constant string parts of this GString. These alternate with the interpolated values in the final string.
Returns the interpolated expression at the specified index.
idx - the index of the valueReturns the interpolated expressions in this GString. These are evaluated at runtime and converted to strings.
Indicates whether this GString contains no interpolated values (only constant strings).
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.