Interface Node
- All Known Implementing Classes:
BinaryOpNode, CollectionFilterNode, CollectionProjectNode, FunctionCallNode, IdentifierNode, IndexAccessNode, ListLiteralNode, LiteralNode, MethodCallNode, PropertyAccessNode, TernaryOpNode, UnaryOpNode
public sealed interface Node
permits LiteralNode, IdentifierNode, BinaryOpNode, UnaryOpNode, TernaryOpNode, PropertyAccessNode, IndexAccessNode, MethodCallNode, FunctionCallNode, CollectionFilterNode, CollectionProjectNode, ListLiteralNode
AST Node Interface
AST 节点接口
Base interface for all Abstract Syntax Tree nodes in the expression engine. Each node represents a syntactic element that can be evaluated.
表达式引擎中所有抽象语法树节点的基础接口。每个节点代表一个可求值的语法元素。
Features | 主要功能:
- Sealed interface with known implementations - 密封接口,已知实现类
- Context-based evaluation - 基于上下文的求值
- String representation for debugging - 用于调试的字符串表示
Usage Examples | 使用示例:
Node literal = LiteralNode.of(42);
Node binary = BinaryOpNode.of(literal, "+", LiteralNode.of(8));
Object result = binary.evaluate(new StandardContext()); // 50
String repr = binary.toExpressionString(); // "(42 + 8)"
Security | 安全性:
- Thread-safe: Yes, implementations are immutable records - 线程安全: 是,实现为不可变记录
- Null-safe: No, null context may cause exceptions - 空值安全: 否,null上下文可能导致异常
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionevaluate(EvaluationContext context) Evaluate this node 求值此节点default StringGet node type name 获取节点类型名称Get string representation for debugging 获取用于调试的字符串表示
-
Method Details
-
evaluate
Evaluate this node 求值此节点- Parameters:
context- the evaluation context | 求值上下文- Returns:
- the evaluation result | 求值结果
-
getTypeName
-
toExpressionString
String toExpressionString()Get string representation for debugging 获取用于调试的字符串表示- Returns:
- the string representation | 字符串表示
-