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
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 Summary
ConstructorsConstructorDescriptionStringInterpolationNode(List<Node> parts) Creates an instance of aStringInterpolationNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.evaluate(EvaluationContext context) Evaluate this node 求值此节点final inthashCode()Returns a hash code value for this object.static StringInterpolationNodeCreate string interpolation node 创建字符串插值节点parts()Returns the value of thepartsrecord component.Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
StringInterpolationNode
-
-
Method Details
-
of
Create string interpolation node 创建字符串插值节点- Parameters:
parts- the interpolation parts | 插值部分- Returns:
- the string interpolation node | 字符串插值节点
-
evaluate
Description copied from interface:NodeEvaluate this node 求值此节点 -
toExpressionString
Description copied from interface:NodeGet string representation for debugging 获取用于调试的字符串表示- Specified by:
toExpressionStringin interfaceNode- Returns:
- the string representation | 字符串表示
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
parts
-