Class SwitchExpr
java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.expr.Expression
com.github.javaparser.ast.expr.SwitchExpr
- All Implemented Interfaces:
NodeWithRange<Node>, NodeWithTokenRange<Node>, SwitchNode, Observable, Visitable, HasParentNode<Node>, Cloneable
The switch expression
Java 1.0-11
Not available.Java 12
LikeSwitchStmt,
but can also be used as an expression.
int a = switch(x) { case 5,6 -> 20; case 9 -> 30; default -> 40; };
int a = switch(x) { case 5,6: break 20; default: break 5+5; };
Java 13
The break statement has been reverted to what it was before Java 12, and break-with-value is now the YieldStatement.int a = switch(x) { case 5,6: yield 20; default: yield 5+5; };- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal -
Field Summary
FieldsFields inherited from class Expression
EXCLUDE_ENCLOSED_EXPR, IS_NOT_ENCLOSED_EXPRFields inherited from class Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, LINE_SEPARATOR_KEY, NODE_BY_BEGIN_POSITION, PHANTOM_KEY, prettyPrinterNoCommentsConfiguration, PRINTER_KEY, SYMBOL_RESOLVER_KEY -
Constructor Summary
ConstructorsConstructorDescriptionSwitchExpr(Expression selector, NodeList<SwitchEntry> entries) SwitchExpr(TokenRange tokenRange, Expression selector, NodeList<SwitchEntry> entries) This constructor is used by the parser and is considered private. -
Method Summary
Modifier and TypeMethodDescription<R,A> R accept(GenericVisitor<R, A> v, A arg) Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg) Accept method for visitor support.clone()getEntry(int i) voidifSwitchExpr(Consumer<SwitchExpr> action) booleanbooleanbooleansetEntries(NodeList<SwitchEntry> entries) setSelector(Expression selector) Methods inherited from class Expression
appearsInAssignmentContext, appearsInInvocationContext, asAnnotationExpr, asArrayAccessExpr, asArrayCreationExpr, asArrayInitializerExpr, asAssignExpr, asBinaryExpr, asBooleanLiteralExpr, asCastExpr, asCharLiteralExpr, asClassExpr, asComponentPatternExpr, asConditionalExpr, asDoubleLiteralExpr, asEnclosedExpr, asFieldAccessExpr, asInstanceOfExpr, asIntegerLiteralExpr, asLambdaExpr, asLiteralExpr, asLiteralStringValueExpr, asLongLiteralExpr, asMarkerAnnotationExpr, asMatchAllPatternExpr, asMethodCallExpr, asMethodReferenceExpr, asNameExpr, asNormalAnnotationExpr, asNullLiteralExpr, asObjectCreationExpr, asPatternExpr, asRecordPatternExpr, asSingleMemberAnnotationExpr, asStringLiteralExpr, asSuperExpr, asTextBlockLiteralExpr, asThisExpr, asTypeExpr, asTypePatternExpr, asUnaryExpr, asVariableDeclarationExpr, calculateResolvedType, elidesTypeArguments, ifAnnotationExpr, ifArrayAccessExpr, ifArrayCreationExpr, ifArrayInitializerExpr, ifAssignExpr, ifBinaryExpr, ifBooleanLiteralExpr, ifCastExpr, ifCharLiteralExpr, ifClassExpr, ifComponentPatternExpr, ifConditionalExpr, ifDoubleLiteralExpr, ifEnclosedExpr, ifFieldAccessExpr, ifInstanceOfExpr, ifIntegerLiteralExpr, ifLambdaExpr, ifLiteralExpr, ifLiteralStringValueExpr, ifLongLiteralExpr, ifMarkerAnnotationExpr, ifMatchAllPatternExpr, ifMethodCallExpr, ifMethodReferenceExpr, ifNameExpr, ifNormalAnnotationExpr, ifNullLiteralExpr, ifObjectCreationExpr, ifPatternExpr, ifRecordPatternExpr, ifSingleMemberAnnotationExpr, ifStringLiteralExpr, ifSuperExpr, ifTextBlockLiteralExpr, ifThisExpr, ifTypeExpr, ifTypePatternExpr, ifUnaryExpr, ifVariableDeclarationExpr, isAnnotationExpr, isArrayAccessExpr, isArrayCreationExpr, isArrayInitializerExpr, isAssignExpr, isAssignmentContext, isBinaryExpr, isBooleanLiteralExpr, isCastExpr, isCharLiteralExpr, isClassExpr, isComponentPatternExpr, isConditionalExpr, isDoubleLiteralExpr, isEnclosedExpr, isFieldAccessExpr, isInstanceOfExpr, isIntegerLiteralExpr, isInvocationContext, isLambdaExpr, isLiteralExpr, isLiteralStringValueExpr, isLongLiteralExpr, isMarkerAnnotationExpr, isMatchAllPatternExpr, isMethodCallExpr, isMethodReferenceExpr, isNameExpr, isNormalAnnotationExpr, isNullLiteralExpr, isObjectCreationExpr, isPatternExpr, isPolyExpression, isQualified, isRecordPatternExpr, isSingleMemberAnnotationExpr, isStandaloneExpression, isStringLiteralExpr, isSuperExpr, isTextBlockLiteralExpr, isThisExpr, isTypeExpr, isTypePatternExpr, isUnaryExpr, isVariableDeclarationExpr, toAnnotationExpr, toArrayAccessExpr, toArrayCreationExpr, toArrayInitializerExpr, toAssignExpr, toBinaryExpr, toBooleanLiteralExpr, toCastExpr, toCharLiteralExpr, toClassExpr, toComponentPatternExpr, toConditionalExpr, toDoubleLiteralExpr, toEnclosedExpr, toFieldAccessExpr, toInstanceOfExpr, toIntegerLiteralExpr, toLambdaExpr, toLiteralExpr, toLiteralStringValueExpr, toLongLiteralExpr, toMarkerAnnotationExpr, toMatchAllPatternExpr, toMethodCallExpr, toMethodReferenceExpr, toNameExpr, toNormalAnnotationExpr, toNullLiteralExpr, toObjectCreationExpr, toPatternExpr, toRecordPatternExpr, toSingleMemberAnnotationExpr, toStringLiteralExpr, toSuperExpr, toTextBlockLiteralExpr, toThisExpr, toTypeExpr, toTypePatternExpr, toUnaryExpr, toVariableDeclarationExprMethods inherited from class Node
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, walkMethods inherited from interface HasParentNode
findAncestor, findAncestor, findAncestor, hasParentNode, isDescendantOfMethods inherited from interface NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd, hasRangeMethods inherited from interface SwitchNode
getComment, isEmpty
-
Field Details
-
selector
-
entries
-
-
Constructor Details
-
SwitchExpr
public SwitchExpr() -
SwitchExpr
-
SwitchExpr
This constructor is used by the parser and is considered private.
-
-
Method Details
-
accept
Description copied from interface:VisitableAccept method for visitor support.- Specified by:
acceptin interfaceVisitable- Type Parameters:
R- the type of the return value of the visitorA- the type the user argument passed to the visitor- Parameters:
v- the visitor implementationarg- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
Description copied from interface:VisitableAccept method for visitor support. -
getEntries
- Specified by:
getEntriesin interfaceSwitchNode
-
getEntry
- Specified by:
getEntryin interfaceSwitchNode
-
getSelector
- Specified by:
getSelectorin interfaceSwitchNode
-
setEntries
- Specified by:
setEntriesin interfaceSwitchNode
-
setSelector
- Specified by:
setSelectorin interfaceSwitchNode
-
remove
- Specified by:
removein interfaceSwitchNode- Overrides:
removein classNode
-
clone
- Specified by:
clonein interfaceSwitchNode- Overrides:
clonein classExpression
-
replace
-
isSwitchExpr
public boolean isSwitchExpr()- Overrides:
isSwitchExprin classExpression
-
asSwitchExpr
- Overrides:
asSwitchExprin classExpression
-
toSwitchExpr
- Overrides:
toSwitchExprin classExpression
-
ifSwitchExpr
- Overrides:
ifSwitchExprin classExpression
-
getMetaModel
- Overrides:
getMetaModelin classExpression- Returns:
- get JavaParser specific node introspection information.
-