public class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr,ReferenceType>, NodeWithExpression<InstanceOfExpr>
instanceof
expression is a
relational operator,
evaluating to true if the object on the left hand side
is an instance of the type (ReferenceType
) on the right hand side.
tool instanceof Drill
if (obj instanceof String) {
String s = (String) obj;
// use s
}
Pattern
within JEP305,
and avoids the need to cast to the desired type.
tool instanceof Drill d
if (obj instanceof String s) {
// can use s here
} else {
// can't use s here
}
RelationalExpression:
...
RelationalExpression instanceof ReferenceType
RelationalExpression instanceof Pattern
Pattern:
ReferenceType Identifier
PatternExpr
,
JEP305: https://bugs.openjdk.java.net/browse/JDK-8181287,
https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.20Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
EXCLUDE_ENCLOSED_EXPR, IS_NOT_ENCLOSED_EXPR
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY
Constructor and Description |
---|
InstanceOfExpr() |
InstanceOfExpr(Expression expression,
ReferenceType type) |
InstanceOfExpr(Expression expression,
ReferenceType type,
PatternExpr pattern) |
InstanceOfExpr(TokenRange tokenRange,
Expression expression,
ReferenceType type,
PatternExpr pattern)
This constructor is used by the parser and is considered private.
|
Modifier and Type | Method and Description |
---|---|
<R,A> R |
accept(GenericVisitor<R,A> v,
A arg)
Accept method for visitor support.
|
<A> void |
accept(VoidVisitor<A> v,
A arg)
Accept method for visitor support.
|
InstanceOfExpr |
asInstanceOfExpr() |
InstanceOfExpr |
clone() |
Expression |
getExpression() |
InstanceOfExprMetaModel |
getMetaModel() |
Optional<SimpleName> |
getName()
Helper method which, if this is an expression with a type pattern, returns the identifier/name.
|
Optional<PatternExpr> |
getPattern() |
ReferenceType |
getType()
Gets the type
|
void |
ifInstanceOfExpr(Consumer<InstanceOfExpr> action) |
boolean |
isInstanceOfExpr() |
boolean |
remove(Node node) |
InstanceOfExpr |
removePattern() |
boolean |
replace(Node node,
Node replacementNode) |
InstanceOfExpr |
setExpression(Expression expression) |
InstanceOfExpr |
setPattern(PatternExpr pattern) |
InstanceOfExpr |
setType(ReferenceType type)
Sets the type
|
Optional<InstanceOfExpr> |
toInstanceOfExpr() |
appearsInAssignmentContext, appearsInInvocationContext, asAnnotationExpr, asArrayAccessExpr, asArrayCreationExpr, asArrayInitializerExpr, asAssignExpr, asBinaryExpr, asBooleanLiteralExpr, asCastExpr, asCharLiteralExpr, asClassExpr, asConditionalExpr, asDoubleLiteralExpr, asEnclosedExpr, asFieldAccessExpr, asIntegerLiteralExpr, asLambdaExpr, asLiteralExpr, asLiteralStringValueExpr, asLongLiteralExpr, asMarkerAnnotationExpr, asMethodCallExpr, asMethodReferenceExpr, asNameExpr, asNormalAnnotationExpr, asNullLiteralExpr, asObjectCreationExpr, asPatternExpr, asRecordPatternExpr, asSingleMemberAnnotationExpr, asStringLiteralExpr, asSuperExpr, asSwitchExpr, asTextBlockLiteralExpr, asThisExpr, asTypeExpr, asTypePatternExpr, asUnaryExpr, asVariableDeclarationExpr, calculateResolvedType, elidesTypeArguments, ifAnnotationExpr, ifArrayAccessExpr, ifArrayCreationExpr, ifArrayInitializerExpr, ifAssignExpr, ifBinaryExpr, ifBooleanLiteralExpr, ifCastExpr, ifCharLiteralExpr, ifClassExpr, ifConditionalExpr, ifDoubleLiteralExpr, ifEnclosedExpr, ifFieldAccessExpr, ifIntegerLiteralExpr, ifLambdaExpr, ifLiteralExpr, ifLiteralStringValueExpr, ifLongLiteralExpr, ifMarkerAnnotationExpr, ifMethodCallExpr, ifMethodReferenceExpr, ifNameExpr, ifNormalAnnotationExpr, ifNullLiteralExpr, ifObjectCreationExpr, ifPatternExpr, ifRecordPatternExpr, ifSingleMemberAnnotationExpr, ifStringLiteralExpr, ifSuperExpr, ifSwitchExpr, ifTextBlockLiteralExpr, ifThisExpr, ifTypeExpr, ifTypePatternExpr, ifUnaryExpr, ifVariableDeclarationExpr, isAnnotationExpr, isArrayAccessExpr, isArrayCreationExpr, isArrayInitializerExpr, isAssignExpr, isAssignmentContext, isBinaryExpr, isBooleanLiteralExpr, isCastExpr, isCharLiteralExpr, isClassExpr, isConditionalExpr, isDoubleLiteralExpr, isEnclosedExpr, isFieldAccessExpr, isIntegerLiteralExpr, isInvocationContext, isLambdaExpr, isLiteralExpr, isLiteralStringValueExpr, isLongLiteralExpr, isMarkerAnnotationExpr, isMethodCallExpr, isMethodReferenceExpr, isNameExpr, isNormalAnnotationExpr, isNullLiteralExpr, isObjectCreationExpr, isPatternExpr, isPolyExpression, isQualified, isRecordPatternExpr, isSingleMemberAnnotationExpr, isStandaloneExpression, isStringLiteralExpr, isSuperExpr, isSwitchExpr, isTextBlockLiteralExpr, isThisExpr, isTypeExpr, isTypePatternExpr, isUnaryExpr, isVariableDeclarationExpr, toAnnotationExpr, toArrayAccessExpr, toArrayCreationExpr, toArrayInitializerExpr, toAssignExpr, toBinaryExpr, toBooleanLiteralExpr, toCastExpr, toCharLiteralExpr, toClassExpr, toConditionalExpr, toDoubleLiteralExpr, toEnclosedExpr, toFieldAccessExpr, toIntegerLiteralExpr, toLambdaExpr, toLiteralExpr, toLiteralStringValueExpr, toLongLiteralExpr, toMarkerAnnotationExpr, toMethodCallExpr, toMethodReferenceExpr, toNameExpr, toNormalAnnotationExpr, toNullLiteralExpr, toObjectCreationExpr, toPatternExpr, toRecordPatternExpr, toSingleMemberAnnotationExpr, toStringLiteralExpr, toSuperExpr, toSwitchExpr, toTextBlockLiteralExpr, toThisExpr, toTypeExpr, toTypePatternExpr, toUnaryExpr, toVariableDeclarationExpr
addOrphanComment, containsData, createDefaultPrinter, createDefaultPrinter, customInitialization, equals, findAll, findAll, findAll, findByRange, findCompilationUnit, findData, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getDefaultPrinterConfiguration, getLineEndingStyle, getLineEndingStyleOrDefault, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getPrinter, getPrinter, getRange, getSymbolResolver, getTokenRange, hashCode, hasScope, isAncestorOf, isPhantom, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
finalize, getClass, notify, notifyAll, wait, wait, wait
getTypeAsString, setType, setType, tryAddImportToParentCompilationUnit
setExpression
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOf
containsWithin, containsWithinRange, getBegin, getEnd, hasRange
public InstanceOfExpr()
public InstanceOfExpr(Expression expression, ReferenceType type)
public InstanceOfExpr(Expression expression, ReferenceType type, PatternExpr pattern)
public InstanceOfExpr(TokenRange tokenRange, Expression expression, ReferenceType type, PatternExpr pattern)
public Optional<SimpleName> getName()
obj instanceof String stringName
getName()
returns stringName
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Visitable
accept
in interface Visitable
R
- the type of the return value of the visitorA
- the type the user argument passed to the visitorv
- the visitor implementationarg
- the argument passed to the visitor (of type A)public <A> void accept(VoidVisitor<A> v, A arg)
Visitable
public InstanceOfExpr asInstanceOfExpr()
asInstanceOfExpr
in class Expression
public InstanceOfExpr clone()
clone
in class Expression
public Expression getExpression()
getExpression
in interface NodeWithExpression<InstanceOfExpr>
public InstanceOfExprMetaModel getMetaModel()
getMetaModel
in class Expression
public Optional<PatternExpr> getPattern()
public ReferenceType getType()
NodeWithType
getType
in interface NodeWithType<InstanceOfExpr,ReferenceType>
public void ifInstanceOfExpr(Consumer<InstanceOfExpr> action)
ifInstanceOfExpr
in class Expression
public boolean isInstanceOfExpr()
isInstanceOfExpr
in class Expression
public InstanceOfExpr removePattern()
public InstanceOfExpr setExpression(Expression expression)
setExpression
in interface NodeWithExpression<InstanceOfExpr>
public InstanceOfExpr setPattern(PatternExpr pattern)
public InstanceOfExpr setType(ReferenceType type)
NodeWithType
setType
in interface NodeWithType<InstanceOfExpr,ReferenceType>
type
- the typepublic Optional<InstanceOfExpr> toInstanceOfExpr()
toInstanceOfExpr
in class Expression
Copyright © 2007–2024. All rights reserved.