[java] Handle default case in switch labels
This commit is contained in:
@ -2259,21 +2259,20 @@ void SwitchLabel() :
|
||||
{
|
||||
{ inSwitchLabel = true; }
|
||||
(
|
||||
"case" CaseLabelElement() ( {checkForMultipleCaseLabels();} "," CaseLabelElement() )*
|
||||
"case" CaseLabelElement(jjtThis) ( {checkForMultipleCaseLabels();} "," CaseLabelElement(jjtThis) )*
|
||||
|
|
||||
"default" {jjtThis.setDefault();}
|
||||
)
|
||||
{ inSwitchLabel = false; }
|
||||
}
|
||||
|
||||
void CaseLabelElement() #void:
|
||||
void CaseLabelElement(ASTSwitchLabel label) #void:
|
||||
{}
|
||||
{
|
||||
LOOKAHEAD(1) NullLiteral() {checkForNullCaseLabel();}
|
||||
|
|
||||
"default" {checkForDefaultCaseLabel();}
|
||||
"default" {label.setDefault(); checkForDefaultCaseLabel();}
|
||||
|
|
||||
// LOOKAHEAD(Type() <IDENTIFIER>) Type() VariableDeclaratorId() #TypePattern(2) {checkForPatternMatchingInSwitch();}
|
||||
LOOKAHEAD(Pattern()) Pattern() {checkForPatternMatchingInSwitch();}
|
||||
|
|
||||
ConditionalExpression() #Expression
|
||||
|
@ -32,11 +32,6 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
|
||||
java17.parseResource("PatternsInSwitchLabels.java");
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void dealingWithNullBeforeJava17Preview() {
|
||||
java17.parseResource("DealingWithNull.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternMatchingForSwitch() {
|
||||
doTest("PatternsInSwitchLabels");
|
||||
@ -52,6 +47,11 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
|
||||
doTest("ScopeOfPatternVariableDeclarations");
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void dealingWithNullBeforeJava17Preview() {
|
||||
java17.parseResource("DealingWithNull.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dealingWithNull() {
|
||||
doTest("DealingWithNull");
|
||||
|
@ -275,7 +275,7 @@
|
||||
| | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | +- Name[@Image = "o"]
|
||||
| +- SwitchLabeledExpression[]
|
||||
| +- SwitchLabel[@Default = false]
|
||||
| +- SwitchLabel[@Default = true]
|
||||
| | +- NullLiteral[]
|
||||
| +- Expression[@StandAlonePrimitive = false]
|
||||
| +- PrimaryExpression[]
|
||||
|
Reference in New Issue
Block a user