Record Class ListLiteralNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.ListLiteralNode
Record Components:
elements - the list elements | 列表元素
All Implemented Interfaces:
Node

public record ListLiteralNode(List<Node> elements) extends Record implements Node
List Literal Node 列表字面量节点

Represents a list literal like {1, 2, 3}.

表示列表字面量,如{1, 2, 3}。

Features | 主要功能:

  • Inline list construction in expressions - 表达式中的内联列表构造
  • Support nested expressions as elements - 支持嵌套表达式作为元素
  • Empty list creation - 空列表创建

Usage Examples | 使用示例:

Node list = ListLiteralNode.of(
    LiteralNode.ofInt(1),
    LiteralNode.ofInt(2),
    LiteralNode.ofInt(3)
);
List<?> result = (List<?>) list.evaluate(ctx);  // [1, 2, 3]

Security | 安全性:

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

    • ListLiteralNode

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

    • of

      public static ListLiteralNode of(List<Node> elements)
      Create list literal node 创建列表字面量节点
      Parameters:
      elements - the elements | 元素
      Returns:
      the list node | 列表节点
    • of

      public static ListLiteralNode of(Node... elements)
      Create list literal node from varargs 从可变参数创建列表字面量节点
      Parameters:
      elements - the elements | 元素
      Returns:
      the list node | 列表节点
    • empty

      public static ListLiteralNode empty()
      Create empty list literal node 创建空列表字面量节点
      Returns:
      the empty list 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.
    • elements

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