SwitchEntry
One case in a switch statement
The main Javadoc is in SwitchStmtJava 1.0-11
switch (i) {
case 1:
case 2:
System.out.println(444);
break;
default:
System.out.println(0);
}
Content copied to clipboard
- 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-
case 1 -> 15*15;
case 2 -> { a++; b++; }
case 3 -> throw new Exception();
Content copied to clipboard
- The first one is of type EXPRESSION and stores its Expression in an ExpressionStmt 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.
case MONDAY, FRIDAY, SUNDAY -> 6;
Content copied to clipboard
case 16*16, 10+10 -> 6;
Content copied to clipboard
return switch (o) {
case String s -> (arg) -> System.out.println(arg + s);
case null, default -> (arg) -> {};
};
Content copied to clipboard
Author
Julio Vilmar Gesser
See also
Constructors
Link copied to clipboard
constructor()
constructor(tokenRange: TokenRange, labels: NodeList<Expression>, type: SwitchEntry.Type, statements: NodeList<Statement>)
This constructor exists for backwards compatibility for code that instantiated `SwitchEntries` before the `isDefault` and guard fields were added.
This constructor exists for backwards compatibility for code that instantiated `SwitchEntries` before the `isDefault` and guard fields were added.
constructor(labels: NodeList<Expression>, type: SwitchEntry.Type, statements: NodeList<Statement>, isDefault: Boolean, guard: Expression)
constructor(tokenRange: TokenRange, labels: NodeList<Expression>, type: SwitchEntry.Type, statements: NodeList<Statement>, isDefault: Boolean, guard: Expression)
This constructor is used by the parser and is considered private.
constructor(tokenRange: TokenRange, labels: NodeList<Expression>, type: SwitchEntry.Type, statements: NodeList<Statement>, isDefault: Boolean)
This constructor is used by the parser and is considered private.
Properties
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
This can be used to sort nodes on position.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
It will use parseStatement inside, so it should end with a semicolon
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Checks whether the range of the given
Node is contained within the range of this NodeWithRange.Link copied to clipboard
Link copied to clipboard
Walks the AST with pre-order traversal, returning all nodes of type "nodeType".
Walks the AST with specified traversal order, returning all nodes of type "nodeType".
Walks the AST with pre-order traversal, returning all nodes of type "nodeType" that match the predicate.
Link copied to clipboard
Walks the parents of this node and returns the first node of type
type, or empty() if none is found.Walks the parents of this node and returns the first node of type
type that matches predicate, or empty() if none is found.Walks the parents of this node and returns the first node that matches one of types
types, or empty() if none is found.Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Walks the AST with pre-order traversal, returning the first node of type "nodeType" or empty() if none is found.
Walks the AST, applying the function for every node, with traversal algorithm "traversal".
Walks the AST with pre-order traversal, returning the first node of type "nodeType" that matches "predicate" or empty() if none is found.
Link copied to clipboard
Finds the root node of this AST by finding the topmost parent.
Link copied to clipboard
This is the list of Comment which are contained in the Node either because they are properly associated to one of its children or because they are floating around inside the Node
Link copied to clipboard
This field is used by key to associated (JML) comments to this node.
Link copied to clipboard
Contains all nodes that have this node set as their parent.
Link copied to clipboard
Link copied to clipboard
This is a comment associated with this node.
Link copied to clipboard
This method was added to support the clone method.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
This is a list of Comment which are inside the node and are not associated with any meaningful AST Node.
Link copied to clipboard
Returns the parent node, or
Optional.empty if no parent is set.Link copied to clipboard
Returns the parent node from the perspective of the children of this node.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Returns true if the parent has a parent
Link copied to clipboard
Determines whether this node is an ancestor of the given node.
Link copied to clipboard
Determines whether this
HasParentNode node is a descendant of the given node.Link copied to clipboard
Was this observer registered?
Link copied to clipboard
This is required for the ConcreteSyntaxModel, specifically to determine whether this entry uses the classic switch statement syntax (e.g.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Register an observer.
Register a new observer for the given node.
Link copied to clipboard
Register the observer for the current node and all the contained node and nodelists, recursively.
Link copied to clipboard
Link copied to clipboard
Remove data by key.
Link copied to clipboard
Forcibly removes this node from the AST.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun setAssociatedSpecificationComments(@Nullable associatedSpecificationComments: @Nullable NodeList<Comment>): Node
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Link copied to clipboard
Use this to store additional information to this node.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Unregister an observer.
Link copied to clipboard
Walks the AST, calling the consumer for every node with pre-order traversal.
Walks the AST, calling the consumer for every node, with traversal algorithm "traversal".
Walks the AST with pre-order traversal, calling the consumer for every node of type "nodeType".