Class ArrayAccessExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.ArrayAccessExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class ArrayAccessExpr extends Object implements Expression
An array access expression: array[index].
-
-
Constructor Summary
Constructors Constructor Description ArrayAccessExpr(Expression array, Expression index, SourceType type)Creates an array access with an unknown source location.ArrayAccessExpr(Expression array, Expression index, SourceType type, SourceLocation location)Creates an array access over the given array and index and reparents both operands.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.ExpressiongetArray()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetIndex()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.voidsetArray(Expression array)Replaces the array operand, reparenting the new child.voidsetIndex(Expression index)Replaces the index operand, reparenting the new child.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.StringtoString()ArrayAccessExprwithArray(Expression array)Replaces the array operand, reparenting the new child and releasing the former one.ArrayAccessExprwithIndex(Expression index)Replaces the index operand, reparenting the new child and releasing the former one.-
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
-
ArrayAccessExpr
public ArrayAccessExpr(Expression array, Expression index, SourceType type, SourceLocation location)
Creates an array access over the given array and index and reparents both operands.- Parameters:
array- the array operandindex- the index operandtype- the element type produced by the accesslocation- the source location, or null for unknown- Throws:
NullPointerException- if array, index, or type is null
-
ArrayAccessExpr
public ArrayAccessExpr(Expression array, Expression index, SourceType type)
Creates an array access with an unknown source location.- Parameters:
array- the array operandindex- the index operandtype- the element type produced by the access- Throws:
NullPointerException- if array, index, or type is null
-
-
Method Detail
-
getArray
public Expression getArray()
- Returns:
- the array
-
setArray
public void setArray(Expression array)
Replaces the array operand, reparenting the new child.- Parameters:
array- the new array operand
-
getIndex
public Expression getIndex()
- Returns:
- the index
-
setIndex
public void setIndex(Expression index)
Replaces the index operand, reparenting the new child.- Parameters:
index- the new index operand
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the static type of this expression
-
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.
-
withArray
public ArrayAccessExpr withArray(Expression array)
Replaces the array operand, reparenting the new child and releasing the former one.- Parameters:
array- the new array operand- Returns:
- this expression
-
withIndex
public ArrayAccessExpr withIndex(Expression index)
Replaces the index operand, reparenting the new child and releasing the former one.- Parameters:
index- the new index operand- Returns:
- this expression
-
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.
-
-