Package: org.codehaus.groovy.ast.expr

## [Java] Class GStringExpression

- org.codehaus.groovy.ast.expr.GStringExpression

-     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.

  See Also:
    ConstantExpression for string constant parts
    Expression for interpolated expressions
    ClassHelper.GSTRING_TYPE for the GString type

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class Expression` | `EMPTY_ARRAY`

  - ### Constructor Summary

    Constructors
    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.

  - ### Methods Summary

    Methods
    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)`

  - ### Inherited Methods Summary

    Inherited Methods
    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`

- - ### Constructor Detail

    - #### public GStringExpression(String verbatimText)

      Creates an empty GString expression with the given verbatim text.

      Parameters:
        `verbatimText` - the original text representation (non-null)

    - #### public GStringExpression(String verbatimText, List<ConstantExpression> strings, List<Expression> values)

      Creates a GString expression with pre-populated strings and values.

      Parameters:
        `verbatimText` - the original text representation (non-null)
        `strings` - the list of constant string parts (non-null)
        `values` - the list of interpolated expressions (non-null)

  - ### Method Detail

    - #### public void addString(ConstantExpression text)

      Adds a constant string part to this GString.

      throws:
        NullPointerException if text is null
      Parameters:
        `text` - the constant string expression to add (non-null)

    - #### public void addValue(Expression value)

      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.

      Parameters:
        `value` - the expression to add (non-null)

    - #### public Expression asConstantString()

      Converts this GString to a constant string expression by concatenating all string parts. This is only valid if isConstantString() returns true.

      Returns:
        a ConstantExpression with the complete concatenated string value

    - #### public List<ConstantExpression> getStrings()

      Returns the constant string parts of this GString. These alternate with the interpolated values in the final string.

      Returns:
        a list of constant string expressions (non-null)

    - #### public String getText()

    - #### public Expression getValue(int idx)

      Returns the interpolated expression at the specified index.

      throws:
        IndexOutOfBoundsException if the index is out of range
      Parameters:
        `idx` - the index of the value
      Returns:
        the expression at the specified index

    - #### public List<Expression> getValues()

      Returns the interpolated expressions in this GString. These are evaluated at runtime and converted to strings.

      Returns:
        a list of value expressions (non-null)

    - #### public boolean isConstantString()

      Indicates whether this GString contains no interpolated values (only constant strings).

      Returns:
        true if there are no interpolated values, false if there are embedded expressions

    - #### public String toString()

    - #### public Expression transformExpression(ExpressionTransformer transformer)

    - #### public void visit(GroovyCodeVisitor visitor)