Class ArrayInitExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class ArrayInitExpr
    extends Object
    implements Expression
    An array initializer expression: {elem1, elem2, ...}.
    • Constructor Detail

      • ArrayInitExpr

        public ArrayInitExpr​(List<Expression> elements,
                             SourceType type,
                             SourceLocation location)
        Creates an initializer over a defensive copy of the elements and reparents each one.
        Parameters:
        elements - the element expressions, or null for none
        type - the array type of the initializer
        location - the source location, or null for unknown
        Throws:
        NullPointerException - if type is null
      • ArrayInitExpr

        public ArrayInitExpr​(List<Expression> elements,
                             SourceType type)
        Creates an initializer with an unknown source location.
        Parameters:
        elements - the element expressions, or null for none
        type - the array type of the initializer
        Throws:
        NullPointerException - if type is null
    • Method Detail

      • getElements

        public List<Expression> getElements()
        Returns:
        the elements
      • 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
      • of

        public static ArrayInitExpr of​(SourceType elementType,
                                       List<Expression> elements)
        Creates an initializer typed as an array of the given element type.
        Parameters:
        elementType - the element type of the array
        elements - the element expressions, or null for none
        Returns:
        the new initializer
      • addElement

        public void addElement​(Expression elem)
        Appends an element and reparents it to this initializer.
        Parameters:
        elem - the element expression to add
      • size

        public int size()
        Returns:
        the number of elements
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if there are no elements
      • 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