Record Class PropertyAccessNode

java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.PropertyAccessNode
Record Components:
target - the target object node | 目标对象节点
property - the property name | 属性名
nullSafe - whether to use null-safe access | 是否使用空安全访问
All Implemented Interfaces:
Node

public record PropertyAccessNode(Node target, String property, boolean nullSafe) extends Record implements Node
Property Access Node 属性访问节点

Represents property access: object.property, object?.property (null-safe)

表示属性访问:object.property, object?.property(空安全)

Features | 主要功能:

  • JavaBean getter access (getXxx, isXxx) - JavaBean getter访问
  • Record accessor method support - Record访问器方法支持
  • Map key access - Map键访问
  • Public field access - 公共字段访问
  • Null-safe navigation (?.) - 空安全导航
  • Custom PropertyAccessor SPI support - 自定义PropertyAccessor SPI支持
  • Sandbox-controlled property access - 沙箱控制的属性访问

Usage Examples | 使用示例:

// user.name
Node prop = PropertyAccessNode.of(userNode, "name");
Object name = prop.evaluate(ctx);

// user?.address - null-safe
Node safe = PropertyAccessNode.nullSafe(userNode, "address");

Security | 安全性:

  • Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
  • Null-safe: Optional via nullSafe mode - 空值安全: 通过nullSafe模式可选
  • Only public fields and methods accessible - 仅可访问公共字段和方法
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • PropertyAccessNode

      public PropertyAccessNode(Node target, String property, boolean nullSafe)
      Creates an instance of a PropertyAccessNode record class.
      Parameters:
      target - the value for the target record component
      property - the value for the property record component
      nullSafe - the value for the nullSafe record component
  • Method Details

    • of

      public static PropertyAccessNode of(Node target, String property)
      Create standard property access 创建标准属性访问
      Parameters:
      target - the target node | 目标节点
      property - the property name | 属性名
      Returns:
      the property access node | 属性访问节点
    • nullSafe

      public static PropertyAccessNode nullSafe(Node target, String property)
      Create null-safe property access 创建空安全属性访问
      Parameters:
      target - the target node | 目标节点
      property - the property name | 属性名
      Returns:
      the null-safe property access node | 空安全属性访问节点
    • of

      public static PropertyAccessNode of(Node target, String property, boolean nullSafe)
      Create property access with null-safe option 创建带空安全选项的属性访问
      Parameters:
      target - the target node | 目标节点
      property - the property name | 属性名
      nullSafe - whether to use null-safe access | 是否使用空安全访问
      Returns:
      the property access 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 | 求值结果
    • getPropertyValue

      public static Object getPropertyValue(Object target, String property, EvaluationContext context)
      Get property value from object 从对象获取属性值
      Parameters:
      target - the target object | 目标对象
      property - the property name | 属性名
      context - the evaluation context | 求值上下文
      Returns:
      the property value | 属性值
    • 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
    • property

      public String property()
      Returns the value of the property record component.
      Returns:
      the value of the property record component
    • nullSafe

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