Record Class MethodCallNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.MethodCallNode
Record Components:
target - the target object node | 目标对象节点
methodName - the method name | 方法名
arguments - the method arguments | 方法参数
nullSafe - whether to use null-safe access | 是否使用空安全访问
All Implemented Interfaces:
Node

public record MethodCallNode(Node target, String methodName, List<Node> arguments, boolean nullSafe) extends Record implements Node
Method Call Node 方法调用节点

Represents method calls: str.toUpperCase(), list.size()

表示方法调用:str.toUpperCase(), list.size()

Features | 主要功能:

  • Reflective method invocation on target objects - 对目标对象的反射方法调用
  • Null-safe method call (?.) support - 空安全方法调用(?.)支持
  • Varargs method support - 可变参数方法支持
  • Sandbox-controlled method access - 沙箱控制的方法访问
  • Primitive type auto-boxing - 原始类型自动装箱

Usage Examples | 使用示例:

// str.toUpperCase()
Node call = MethodCallNode.of(strNode, "toUpperCase", List.of());
Object result = call.evaluate(ctx);

// obj?.method() - null-safe
Node safe = MethodCallNode.nullSafe(objNode, "method", List.of());

Security | 安全性:

  • Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
  • Null-safe: Optional via nullSafe mode - 空值安全: 通过nullSafe模式可选
  • Sandbox enforcement on method calls - 方法调用的沙箱强制执行
  • Only public methods accessible - 仅可访问公共方法
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • MethodCallNode

      public MethodCallNode(Node target, String methodName, List<Node> arguments, boolean nullSafe)
      Creates an instance of a MethodCallNode record class.
      Parameters:
      target - the value for the target record component
      methodName - the value for the methodName record component
      arguments - the value for the arguments record component
      nullSafe - the value for the nullSafe record component
  • Method Details

    • of

      public static MethodCallNode of(Node target, String methodName, List<Node> arguments)
      Create method call node 创建方法调用节点
      Parameters:
      target - the target node | 目标节点
      methodName - the method name | 方法名
      arguments - the arguments | 参数
      Returns:
      the method call node | 方法调用节点
    • nullSafe

      public static MethodCallNode nullSafe(Node target, String methodName, List<Node> arguments)
      Create null-safe method call node 创建空安全方法调用节点
      Parameters:
      target - the target node | 目标节点
      methodName - the method name | 方法名
      arguments - the arguments | 参数
      Returns:
      the null-safe method call node | 空安全方法调用节点
    • of

      public static MethodCallNode of(Node target, String methodName, List<Node> arguments, boolean nullSafe)
      Create method call node with null-safe option 创建带空安全选项的方法调用节点
      Parameters:
      target - the target node | 目标节点
      methodName - the method name | 方法名
      arguments - the arguments | 参数
      nullSafe - whether to use null-safe access | 是否使用空安全访问
      Returns:
      the method call 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • target

      public Node target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • methodName

      public String methodName()
      Returns the value of the methodName record component.
      Returns:
      the value of the methodName record component
    • arguments

      public List<Node> arguments()
      Returns the value of the arguments record component.
      Returns:
      the value of the arguments record component
    • nullSafe

      public boolean nullSafe()
      Returns the value of the nullSafe record component.
      Returns:
      the value of the nullSafe record component