public class CaseStatement
extends Statement
Represents a case arm of a SwitchStatement or a SwitchExpression. A case consists of a pattern (expression) to match against the switch selector and the statement to execute if the pattern matches.
| Constructor and description |
|---|
CaseStatement(Expression expression, Statement code)Constructs a case statement with the given expression pattern and code block. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public Statement |
getCode()Returns the statement executed if this case pattern matches. |
|
public Expression |
getExpression()Returns the pattern expression matched against the switch control expression. |
|
public boolean |
isArrow()Indicates whether this case uses an arrow label ( case L ->) rather
than a colon label (case L:). |
|
public void |
setArrow(boolean arrow)Marks this case as an arrow label ( case L ->) or a colon label. |
|
public void |
setCode(Statement code)Sets the statement executed if this case pattern matches. |
|
public void |
setExpression(Expression e)Sets the pattern expression matched against the switch control expression. |
|
public String |
toString() |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class Statement |
addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Constructs a case statement with the given expression pattern and code block.
expression - the Expression pattern to match against the switch control expressioncode - the Statement to execute if the pattern matchesReturns the statement executed if this case pattern matches.
Returns the pattern expression matched against the switch control expression.
Indicates whether this case uses an arrow label (case L ->) rather
than a colon label (case L:). Arrow labels do not fall through
(JEP 361).
true if this case was written with -> Marks this case as an arrow label (case L ->) or a colon label.
arrow - true if this case was written with ->Sets the statement executed if this case pattern matches.
code - the Statement to executeSets the pattern expression matched against the switch control expression.
e - the pattern ExpressionCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.