Class BinaryExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.BinaryExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class BinaryExpr extends Object implements Expression
A binary expression: left op right, including assignments and logical operators.
-
-
Constructor Summary
Constructors Constructor Description BinaryExpr(BinaryOperator operator, Expression left, Expression right, SourceType type)Creates a binary expression with an unknown source location.BinaryExpr(BinaryOperator operator, Expression left, Expression right, SourceType type, SourceLocation location)Creates a binary expression 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.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetLeft()SourceLocationgetLocation()Gets the source location of this node.BinaryOperatorgetOperator()ASTNodegetParent()Gets the parent node in the AST tree.intgetPrecedence()ExpressiongetRight()SourceTypegetType()Gets the inferred type of this expression.booleanisAssignment()booleanisComparison()booleanisLogical()voidsetLeft(Expression left)Replaces the left operand, reparenting the new child.voidsetOperator(BinaryOperator operator)voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetRight(Expression right)Replaces the right operand, reparenting the new child.StringtoString()BinaryExprwithLeft(Expression left)Replaces the left operand, reparenting the new child and releasing the former one.BinaryExprwithOperator(BinaryOperator operator)Replaces the operator.BinaryExprwithRight(Expression right)Replaces the right 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
-
BinaryExpr
public BinaryExpr(BinaryOperator operator, Expression left, Expression right, SourceType type, SourceLocation location)
Creates a binary expression and reparents both operands.- Parameters:
operator- the binary operatorleft- the left operandright- the right operandtype- the result type of the expressionlocation- the source location, or null for unknown- Throws:
NullPointerException- if operator, left, right, or type is null
-
BinaryExpr
public BinaryExpr(BinaryOperator operator, Expression left, Expression right, SourceType type)
Creates a binary expression with an unknown source location.- Parameters:
operator- the binary operatorleft- the left operandright- the right operandtype- the result type of the expression- Throws:
NullPointerException- if operator, left, right, or type is null
-
-
Method Detail
-
getOperator
public BinaryOperator getOperator()
- Returns:
- the operator
-
setOperator
public void setOperator(BinaryOperator operator)
- Parameters:
operator- the new binary operator
-
getLeft
public Expression getLeft()
- Returns:
- the left
-
setLeft
public void setLeft(Expression left)
Replaces the left operand, reparenting the new child.- Parameters:
left- the new left operand
-
getRight
public Expression getRight()
- Returns:
- the right operand
-
setRight
public void setRight(Expression right)
Replaces the right operand, reparenting the new child.- Parameters:
right- the new right 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.
-
getPrecedence
public int getPrecedence()
- Returns:
- the precedence of the operator
-
isAssignment
public boolean isAssignment()
- Returns:
- true if the operator is an assignment
-
isComparison
public boolean isComparison()
- Returns:
- true if the operator is a comparison
-
isLogical
public boolean isLogical()
- Returns:
- true if the operator is logical (&& or ||)
-
withOperator
public BinaryExpr withOperator(BinaryOperator operator)
Replaces the operator.- Parameters:
operator- the new binary operator- Returns:
- this expression
-
withLeft
public BinaryExpr withLeft(Expression left)
Replaces the left operand, reparenting the new child and releasing the former one.- Parameters:
left- the new left operand- Returns:
- this expression
-
withRight
public BinaryExpr withRight(Expression right)
Replaces the right operand, reparenting the new child and releasing the former one.- Parameters:
right- the new right 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.
-
-