Class ArrayInitExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.ArrayInitExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class ArrayInitExpr extends Object implements Expression
An array initializer expression: {elem1, elem2, ...}.
-
-
Constructor Summary
Constructors Constructor Description ArrayInitExpr(List<Expression> elements, SourceType type)Creates an initializer with an unknown source location.ArrayInitExpr(List<Expression> elements, SourceType type, SourceLocation location)Creates an initializer over a defensive copy of the elements and reparents each one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.voidaddElement(Expression elem)Appends an element and reparents it to this initializer.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.List<Expression>getElements()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()Gets the inferred type of this expression.booleanisEmpty()static ArrayInitExprof(SourceType elementType, List<Expression> elements)Creates an initializer typed as an array of the given element type.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.intsize()StringtoString()-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
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 nonetype- the array type of the initializerlocation- 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 nonetype- 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:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
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 arrayelements- 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:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-