Class FieldAccessExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class FieldAccessExpr
    extends Object
    implements Expression
    A field access expression: obj.field or Type.staticField.
    • Constructor Detail

      • FieldAccessExpr

        public FieldAccessExpr​(Expression receiver,
                               String fieldName,
                               String ownerClass,
                               boolean isStatic,
                               SourceType type,
                               SourceLocation location)
        Creates a field access and reparents the receiver if present.
        Parameters:
        receiver - the receiver expression, or null for static access
        fieldName - the field name
        ownerClass - the declaring class in internal format
        isStatic - true for a static field access
        type - the field type
        location - the source location, or null for unknown
        Throws:
        NullPointerException - if fieldName, ownerClass, or type is null
      • FieldAccessExpr

        public FieldAccessExpr​(Expression receiver,
                               String fieldName,
                               String ownerClass,
                               boolean isStatic,
                               SourceType type)
        Creates a field access with an unknown source location.
        Parameters:
        receiver - the receiver expression, or null for static access
        fieldName - the field name
        ownerClass - the declaring class in internal format
        isStatic - true for a static field access
        type - the field type
        Throws:
        NullPointerException - if fieldName, ownerClass, or type is null
    • Method Detail

      • getReceiver

        public Expression getReceiver()
        Returns:
        the receiver
      • setReceiver

        public void setReceiver​(Expression receiver)
        Replaces the receiver, reparenting the new child.
        Parameters:
        receiver - the new receiver, or null for static access
      • getFieldName

        public String getFieldName()
        Returns:
        the field name
      • setFieldName

        public void setFieldName​(String fieldName)
        Parameters:
        fieldName - the new field name
      • getOwnerClass

        public String getOwnerClass()
        Returns:
        the owner class
      • getDescriptor

        public String getDescriptor()
        Returns:
        the descriptor
      • withDescriptor

        public FieldAccessExpr withDescriptor​(String descriptor)
        Records the JVM field descriptor recovered from bytecode.
        Parameters:
        descriptor - the field descriptor
        Returns:
        this expression
      • isStatic

        public boolean isStatic()
        Returns:
        whether static
      • getType

        public SourceType getType()
        Description copied from interface: Expression
        Gets the inferred type of this expression.
        Specified by:
        getType in interface Expression
        Returns:
        the type
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Description copied from interface: ASTNode
        Sets the parent node in the AST tree.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the enclosing AST node
      • staticField

        public static FieldAccessExpr staticField​(String ownerClass,
                                                  String fieldName,
                                                  SourceType type)
        Creates a static field access with no receiver.
        Parameters:
        ownerClass - the declaring class in internal format
        fieldName - the field name
        type - the field type
        Returns:
        the new field access
      • instanceField

        public static FieldAccessExpr instanceField​(Expression receiver,
                                                    String fieldName,
                                                    String ownerClass,
                                                    SourceType type)
        Creates an instance field access.
        Parameters:
        receiver - the receiver expression
        fieldName - the field name
        ownerClass - the declaring class in internal format
        type - the field type
        Returns:
        the new field access
      • getOwnerSimpleName

        public String getOwnerSimpleName()
        Returns:
        the simple name of the owner class, keeping inner-class segments
      • withReceiver

        public FieldAccessExpr withReceiver​(Expression receiver)
        Replaces the receiver, reparenting the new child and releasing the former one.
        Parameters:
        receiver - the new receiver, or null for static access
        Returns:
        this expression
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor