Class SwitchCase
- java.lang.Object
-
- com.tonic.analysis.source.ast.stmt.SwitchCase
-
public final class SwitchCase extends Object
A case clause of a switch statement, keyed by integer labels or expression labels.
-
-
Constructor Summary
Constructors Constructor Description SwitchCase(List<Integer> labels, boolean isDefault, List<Statement> statements)Creates a case with integer labels; the statement list stays mutable for AST transforms.SwitchCase(List<Integer> labels, List<Expression> expressionLabels, boolean isDefault, List<Statement> statements)Creates a case with integer and expression labels.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SwitchCasedefaultCase(List<Statement> statements)Creates a default case.booleanequals(Object o)List<Expression>expressionLabels()booleanfallsThrough()booleanhasExpressionLabels()inthashCode()booleanisDefault()List<Integer>labels()static SwitchCaseof(int label, List<Statement> statements)Creates a case with a single integer label.static SwitchCaseof(List<Integer> labels, List<Statement> statements)Creates a case with multiple integer labels sharing one body.static SwitchCaseofExpressions(List<Expression> expressionLabels, List<Statement> statements)Creates a case keyed by expression labels, as used for enum switches.List<Statement>statements()StringtoString()SwitchCasewithFallsThrough(boolean value)Marks whether this case falls through to the next.
-
-
-
Constructor Detail
-
SwitchCase
public SwitchCase(List<Integer> labels, boolean isDefault, List<Statement> statements)
Creates a case with integer labels; the statement list stays mutable for AST transforms.- Parameters:
labels- integer case labels, or null for noneisDefault- whether this is the default casestatements- the case body, or null for empty
-
SwitchCase
public SwitchCase(List<Integer> labels, List<Expression> expressionLabels, boolean isDefault, List<Statement> statements)
Creates a case with integer and expression labels.- Parameters:
labels- integer case labels, or null for noneexpressionLabels- expression case labels, or null for noneisDefault- whether this is the default casestatements- the case body, or null for empty
-
-
Method Detail
-
defaultCase
public static SwitchCase defaultCase(List<Statement> statements)
Creates a default case.- Parameters:
statements- the case body- Returns:
- the new case
-
of
public static SwitchCase of(int label, List<Statement> statements)
Creates a case with a single integer label.- Parameters:
label- the case labelstatements- the case body- Returns:
- the new case
-
of
public static SwitchCase of(List<Integer> labels, List<Statement> statements)
Creates a case with multiple integer labels sharing one body.- Parameters:
labels- the case labelsstatements- the case body- Returns:
- the new case
-
ofExpressions
public static SwitchCase ofExpressions(List<Expression> expressionLabels, List<Statement> statements)
Creates a case keyed by expression labels, as used for enum switches.- Parameters:
expressionLabels- the case label expressionsstatements- the case body- Returns:
- the new case
-
expressionLabels
public List<Expression> expressionLabels()
- Returns:
- the expression case labels, unmodifiable
-
hasExpressionLabels
public boolean hasExpressionLabels()
- Returns:
- true if this case is keyed by expression labels
-
isDefault
public boolean isDefault()
- Returns:
- whether default
-
fallsThrough
public boolean fallsThrough()
- Returns:
- true if control flows off the end of this case into the next
-
withFallsThrough
public SwitchCase withFallsThrough(boolean value)
Marks whether this case falls through to the next.- Parameters:
value- the new fall-through flag- Returns:
- this case
-
-