Record Class StringInterpolationNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.StringInterpolationNode
Record Components:
parts - the interpolation parts (literal strings and expressions) | 插值部分(字面字符串和表达式)
All Implemented Interfaces:
Node

public record StringInterpolationNode(List<Node> parts) extends Record implements Node
String Interpolation Node 字符串插值节点

Represents string interpolation like "text ${expr} text". Parts consist of LiteralNode (string segments) and expression nodes (interpolated segments) that are evaluated and concatenated at runtime.

表示字符串插值,如 "text ${expr} text"。 部分由 LiteralNode(字符串段)和表达式节点(插值段)组成,在运行时求值并拼接。

Features | 主要功能:

  • Inline string interpolation with expression evaluation - 内联字符串插值与表达式求值
  • Mixed literal text and dynamic expressions - 混合字面文本和动态表达式
  • Null values converted to "null" string - null 值转换为 "null" 字符串
  • Supports any expression type in interpolated segments - 插值段支持任意表达式类型

Usage Examples | 使用示例:

Node interpolation = StringInterpolationNode.of(List.of(
    LiteralNode.ofString("Hello, "),
    IdentifierNode.of("name"),
    LiteralNode.ofString("! You are "),
    IdentifierNode.of("age"),
    LiteralNode.ofString(" years old.")
));
// With name="John", age=30:
String result = (String) interpolation.evaluate(ctx);
// "Hello, John! You are 30 years old."

Security | 安全性:

  • Thread-safe: Yes, immutable record with defensive copy - 线程安全: 是,不可变记录,防御性拷贝
  • Null-safe: No, null parts list rejected - 空值安全: 否,null 部分列表被拒绝
Since:
JDK 25, opencode-base-expression V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • StringInterpolationNode

      public StringInterpolationNode(List<Node> parts)
      Creates an instance of a StringInterpolationNode record class.
      Parameters:
      parts - the value for the parts record component
  • Method Details

    • of

      public static StringInterpolationNode of(List<Node> parts)
      Create string interpolation node 创建字符串插值节点
      Parameters:
      parts - the interpolation parts | 插值部分
      Returns:
      the string interpolation node | 字符串插值节点
    • evaluate

      public Object evaluate(EvaluationContext context)
      Description copied from interface: Node
      Evaluate this node 求值此节点
      Specified by:
      evaluate in interface Node
      Parameters:
      context - the evaluation context | 求值上下文
      Returns:
      the evaluation result | 求值结果
    • toExpressionString

      public String toExpressionString()
      Description copied from interface: Node
      Get string representation for debugging 获取用于调试的字符串表示
      Specified by:
      toExpressionString in interface Node
      Returns:
      the string representation | 字符串表示
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • parts

      public List<Node> parts()
      Returns the value of the parts record component.
      Returns:
      the value of the parts record component