Class ArrayAccessNode

  • All Implemented Interfaces:
    org.plumelib.util.UniqueId

    public class ArrayAccessNode
    extends Node
    A node for an array access:
       arrayref [ index ]
     
    We allow array accesses without corresponding AST Trees.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Node array
      The array expression being accessed.
      protected @Nullable com.sun.source.tree.ExpressionTree arrayExpression
      If this ArrayAccessNode is a node for an array desugared from an enhanced for loop, then the arrayExpression field is the expression in the for loop, e.g., arr in for(Object o: arr.
      protected Node index
      The index expresssion used to access the array.
      protected com.sun.source.tree.ArrayAccessTree tree
      The corresponding ArrayAccessTree.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayAccessNode​(com.sun.source.tree.ArrayAccessTree t, Node array, Node index)
      Create an ArrayAccessNode.
    • Field Detail

      • tree

        protected final com.sun.source.tree.ArrayAccessTree tree
        The corresponding ArrayAccessTree.
      • array

        protected final Node array
        The array expression being accessed.
      • index

        protected final Node index
        The index expresssion used to access the array.
      • arrayExpression

        protected @Nullable com.sun.source.tree.ExpressionTree arrayExpression
        If this ArrayAccessNode is a node for an array desugared from an enhanced for loop, then the arrayExpression field is the expression in the for loop, e.g., arr in for(Object o: arr.

        Is set by setArrayExpression(com.sun.source.tree.ExpressionTree).

    • Constructor Detail

      • ArrayAccessNode

        public ArrayAccessNode​(com.sun.source.tree.ArrayAccessTree t,
                               Node array,
                               Node index)
        Create an ArrayAccessNode.
        Parameters:
        t - tree for the array access
        array - the node for the array expression being accessed
        index - the node for the index used to access the array
    • Method Detail

      • getArrayExpression

        public @Nullable com.sun.source.tree.ExpressionTree getArrayExpression()
        If this ArrayAccessNode is a node for an array desugared from an enhanced for loop, then return the expression in the for loop, e.g., arr in for(Object o: arr. Otherwise, return null.
        Returns:
        the array expression, or null if this is not an array desugared from an enhanced for loop
      • setArrayExpression

        public void setArrayExpression​(@Nullable com.sun.source.tree.ExpressionTree arrayExpression)
        Set the array expression from a for loop.
        Parameters:
        arrayExpression - array expression
        See Also:
        getArrayExpression()
      • getArray

        public Node getArray()
        Get the node that represents the array expression being accessed.
        Returns:
        the array expression node
      • getIndex

        public Node getIndex()
      • getTree

        public com.sun.source.tree.ArrayAccessTree getTree()
        Description copied from class: Node
        Returns the Tree in the abstract syntax tree, or null if no corresponding tree exists. For instance, this is the case for an ImplicitThisNode.
        Specified by:
        getTree in class Node
        Returns:
        the corresponding Tree or null
      • accept

        public <R,​P> R accept​(NodeVisitor<R,​P> visitor,
                                    P p)
        Description copied from class: Node
        Accept method of the visitor pattern.
        Specified by:
        accept in class Node
        Type Parameters:
        R - result type of the operation
        P - parameter type
        Parameters:
        visitor - the visitor to be applied to this node
        p - the parameter for this operation
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(@Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getOperands

        @SideEffectFree
        public java.util.Collection<Node> getOperands()
        Description copied from class: Node
        Returns a collection containing all of the operand Nodes of this Node.
        Specified by:
        getOperands in class Node
        Returns:
        a collection containing all of the operand Nodes of this Node