Class InstanceOfExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.InstanceOfExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class InstanceOfExpr extends Object implements Expression
An instanceof expression: expression instanceof Type, with an optional Java 16+ pattern variable.
-
-
Constructor Summary
Constructors Constructor Description InstanceOfExpr(Expression expression, SourceType checkType)Creates a classic instanceof test without a pattern variable.InstanceOfExpr(Expression expression, SourceType checkType, String patternVariable)Creates an instanceof test with an unknown source location.InstanceOfExpr(Expression expression, SourceType checkType, String patternVariable, SourceLocation location)Creates an instanceof test and reparents the tested expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.SourceTypegetCheckType()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetExpression()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.StringgetPatternVariable()SourceTypegetType()Gets the inferred type of this expression.booleanhasPatternVariable()voidsetExpression(Expression expression)Replaces the tested expression, reparenting the new child.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetPatternVariable(String patternVariable)StringtoString()InstanceOfExprwithExpression(Expression expression)Replaces the tested expression, reparenting the new child and releasing the former one.InstanceOfExprwithPatternVariable(String patternVariable)Replaces the pattern variable name.-
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
-
InstanceOfExpr
public InstanceOfExpr(Expression expression, SourceType checkType, String patternVariable, SourceLocation location)
Creates an instanceof test and reparents the tested expression.- Parameters:
expression- the expression being testedcheckType- the type tested againstpatternVariable- the pattern variable name, or null for classic instanceoflocation- the source location, or null for unknown- Throws:
NullPointerException- if expression or checkType is null
-
InstanceOfExpr
public InstanceOfExpr(Expression expression, SourceType checkType, String patternVariable)
Creates an instanceof test with an unknown source location.- Parameters:
expression- the expression being testedcheckType- the type tested againstpatternVariable- the pattern variable name, or null for classic instanceof- Throws:
NullPointerException- if expression or checkType is null
-
InstanceOfExpr
public InstanceOfExpr(Expression expression, SourceType checkType)
Creates a classic instanceof test without a pattern variable.- Parameters:
expression- the expression being testedcheckType- the type tested against- Throws:
NullPointerException- if expression or checkType is null
-
-
Method Detail
-
getExpression
public Expression getExpression()
- Returns:
- the expression
-
setExpression
public void setExpression(Expression expression)
Replaces the tested expression, reparenting the new child.- Parameters:
expression- the new tested expression
-
getCheckType
public SourceType getCheckType()
- Returns:
- the check type
-
getPatternVariable
public String getPatternVariable()
- Returns:
- the pattern variable
-
setPatternVariable
public void setPatternVariable(String patternVariable)
- Parameters:
patternVariable- the pattern variable name, or null for classic instanceof
-
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.
-
withExpression
public InstanceOfExpr withExpression(Expression expression)
Replaces the tested expression, reparenting the new child and releasing the former one.- Parameters:
expression- the new tested expression- Returns:
- this expression
-
withPatternVariable
public InstanceOfExpr withPatternVariable(String patternVariable)
Replaces the pattern variable name.- Parameters:
patternVariable- the pattern variable name, or null for classic instanceof- Returns:
- this expression
-
hasPatternVariable
public boolean hasPatternVariable()
- Returns:
- true if this is a pattern matching instanceof (Java 16+)
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type of 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.
-
-