Class UnaryExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.UnaryExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class UnaryExpr extends Object implements Expression
Represents a unary expression: op operand (prefix) or operand op (postfix)
-
-
Constructor Summary
Constructors Constructor Description UnaryExpr(UnaryOperator operator, Expression operand, SourceType type)Creates a unary expression with an unknown source location.UnaryExpr(UnaryOperator operator, Expression operand, SourceType type, SourceLocation location)Creates a unary expression and adopts the operand as a child.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.SourceLocationgetLocation()Gets the source location of this node.ExpressiongetOperand()UnaryOperatorgetOperator()ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetType()Gets the inferred type of this expression.booleanisIncDec()booleanisPostfix()booleanisPrefix()voidsetOperand(Expression operand)Sets the operand, reparenting the new one and releasing the old one.voidsetOperator(UnaryOperator operator)Sets the operator.voidsetParent(ASTNode parent)Sets the enclosing AST node.StringtoString()UnaryExprwithOperand(Expression operand)Sets the operand, reparenting the new one and releasing the old one.UnaryExprwithOperator(UnaryOperator operator)Sets the operator.-
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
-
UnaryExpr
public UnaryExpr(UnaryOperator operator, Expression operand, SourceType type, SourceLocation location)
Creates a unary expression and adopts the operand as a child.- Parameters:
operator- the prefix or postfix operatoroperand- the operand expressiontype- the result typelocation- the source location, null for unknown- Throws:
NullPointerException- if the operator, operand or type is null
-
UnaryExpr
public UnaryExpr(UnaryOperator operator, Expression operand, SourceType type)
Creates a unary expression with an unknown source location.- Parameters:
operator- the prefix or postfix operatoroperand- the operand expressiontype- the result type- Throws:
NullPointerException- if the operator, operand or type is null
-
-
Method Detail
-
getOperator
public UnaryOperator getOperator()
- Returns:
- the operator
-
setOperator
public void setOperator(UnaryOperator operator)
Sets the operator.- Parameters:
operator- the new operator
-
getOperand
public Expression getOperand()
- Returns:
- the operand
-
setOperand
public void setOperand(Expression operand)
Sets the operand, reparenting the new one and releasing the old one.- Parameters:
operand- the new 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)
Sets the enclosing AST node.
-
isPrefix
public boolean isPrefix()
- Returns:
- true if the operator is written before the operand
-
isPostfix
public boolean isPostfix()
- Returns:
- true if the operator is written after the operand
-
isIncDec
public boolean isIncDec()
- Returns:
- true if the operator is an increment or decrement
-
withOperator
public UnaryExpr withOperator(UnaryOperator operator)
Sets the operator.- Parameters:
operator- the new operator- Returns:
- this expression
-
withOperand
public UnaryExpr withOperand(Expression operand)
Sets the operand, reparenting the new one and releasing the old one.- Parameters:
operand- the new 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.
-
-