Package com.github.javaparser.ast.stmt
Class SwitchEntry
- java.lang.Object
-
- com.github.javaparser.ast.Node
-
- com.github.javaparser.ast.stmt.SwitchEntry
-
- All Implemented Interfaces:
NodeWithRange<Node>
,NodeWithStatements<SwitchEntry>
,NodeWithTokenRange<Node>
,Observable
,Visitable
,HasParentNode<Node>
,Cloneable
public class SwitchEntry extends Node implements NodeWithStatements<SwitchEntry>
One case in a switch statement
The main Javadoc is inSwitchStmt
Java 1.0-11
switch (i) { case 1: case 2: System.out.println(444); break; default: System.out.println(0); }
This contains three SwitchEntrys. All of them are of type STATEMENT_GROUP.- The first one has label 1 and no statements.
- The second has label 2 and two statements (the println and the break).
- The third, the default, has no label and one statement.
Java 12-
These are three new variants.case 1 -> 15*15; case 2 -> { a++; b++; } case 3 -> throw new Exception();
- The first one is of type EXPRESSION and stores its
Expression
in anExpressionStmt
which is stored as the first and only statement in statements. - The second one is of type BLOCK and stores its
BlockStmt
as the first and only statement in statements. - The third one is of type THROWS_STATEMENT and stores its
ThrowStmt
as the first and only statement in statements.
Multiple case labels are now allowed.case MONDAY, FRIDAY, SUNDAY -> 6;
Many kinds of expressions are now allowed.case 16*16, 10+10 -> 6;
- Author:
- Julio Vilmar Gesser
- See Also:
SwitchStmt
,SwitchExpr
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SwitchEntry.Type
-
Nested classes/interfaces inherited from class com.github.javaparser.ast.Node
Node.BreadthFirstIterator, Node.DirectChildrenIterator, Node.ObserverRegistrationMode, Node.ParentsVisitor, Node.Parsedness, Node.PostOrderIterator, Node.PreOrderIterator, Node.TreeTraversal
-
-
Field Summary
-
Fields inherited from class com.github.javaparser.ast.Node
ABSOLUTE_BEGIN_LINE, ABSOLUTE_END_LINE, NODE_BY_BEGIN_POSITION, prettyPrinterNoCommentsConfiguration, SYMBOL_RESOLVER_KEY
-
-
Constructor Summary
Constructors Constructor Description SwitchEntry()
SwitchEntry(NodeList<Expression> labels, SwitchEntry.Type type, NodeList<Statement> statements)
SwitchEntry(TokenRange tokenRange, NodeList<Expression> labels, SwitchEntry.Type type, NodeList<Statement> statements)
This constructor is used by the parser and is considered private.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,A>
Raccept(GenericVisitor<R,A> v, A arg)
Accept method for visitor support.<A> void
accept(VoidVisitor<A> v, A arg)
Accept method for visitor support.SwitchEntry
clone()
NodeList<Expression>
getLabels()
SwitchEntryMetaModel
getMetaModel()
NodeList<Statement>
getStatements()
SwitchEntry.Type
getType()
boolean
remove(Node node)
boolean
replace(Node node, Node replacementNode)
SwitchEntry
setLabels(NodeList<Expression> labels)
Sets the labelSwitchEntry
setStatements(NodeList<Statement> statements)
SwitchEntry
setType(SwitchEntry.Type type)
-
Methods inherited from class com.github.javaparser.ast.Node
addOrphanComment, containsData, customInitialization, equals, findAll, findAll, findCompilationUnit, findFirst, findFirst, findFirst, findRootNode, getAllContainedComments, getChildNodes, getChildNodesByType, getComment, getData, getDataKeys, getNodesByType, getOrphanComments, getParentNode, getParentNodeForChildren, getParsed, getRange, getSymbolResolver, getTokenRange, getToStringPrettyPrinterConfiguration, hashCode, isAncestorOf, isRegistered, notifyPropertyChange, register, register, registerForSubtree, remove, removeComment, removeData, removeForced, removeOrphanComment, replace, setAsParentNodeOf, setAsParentNodeOf, setBlockComment, setComment, setData, setLineComment, setParentNode, setParsed, setRange, setTokenRange, setToStringPrettyPrinterConfiguration, stream, stream, toString, toString, tryAddImportToParentCompilationUnit, unregister, walk, walk, walk
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.HasParentNode
findAncestor, findAncestor, isDescendantOf
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithRange
containsWithin, containsWithinRange, getBegin, getEnd
-
Methods inherited from interface com.github.javaparser.ast.nodeTypes.NodeWithStatements
addAndGetStatement, addAndGetStatement, addAndGetStatement, addAndGetStatement, addStatement, addStatement, addStatement, addStatement, addStatement, copyStatements, copyStatements, getStatement, isEmpty, setStatement
-
-
-
-
Constructor Detail
-
SwitchEntry
public SwitchEntry()
-
SwitchEntry
public SwitchEntry(NodeList<Expression> labels, SwitchEntry.Type type, NodeList<Statement> statements)
-
SwitchEntry
public SwitchEntry(TokenRange tokenRange, NodeList<Expression> labels, SwitchEntry.Type type, NodeList<Statement> statements)
This constructor is used by the parser and is considered private.
-
-
Method Detail
-
accept
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.- Specified by:
accept
in 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
public <A> void accept(VoidVisitor<A> v, A arg)
Description copied from interface:Visitable
Accept method for visitor support.
-
getLabels
public NodeList<Expression> getLabels()
-
getStatements
public NodeList<Statement> getStatements()
- Specified by:
getStatements
in interfaceNodeWithStatements<SwitchEntry>
-
setLabels
public SwitchEntry setLabels(NodeList<Expression> labels)
Sets the label- Parameters:
labels
- the label, can be null- Returns:
- this, the SwitchEntry
-
setStatements
public SwitchEntry setStatements(NodeList<Statement> statements)
- Specified by:
setStatements
in interfaceNodeWithStatements<SwitchEntry>
-
clone
public SwitchEntry clone()
-
getMetaModel
public SwitchEntryMetaModel getMetaModel()
- Overrides:
getMetaModel
in classNode
- Returns:
- get JavaParser specific node introspection information.
-
getType
public SwitchEntry.Type getType()
-
setType
public SwitchEntry setType(SwitchEntry.Type type)
-
-