[java] Handle default case in switch labels

This commit is contained in:
Andreas Dangel
2021-07-01 20:29:07 +02:00
parent 808b571a82
commit 36f6f50c0f
3 changed files with 9 additions and 10 deletions

View File

@ -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

View File

@ -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");

View File

@ -275,7 +275,7 @@
| | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
| | +- Name[@Image = "o"]
| +- SwitchLabeledExpression[]
| +- SwitchLabel[@Default = false]
| +- SwitchLabel[@Default = true]
| | +- NullLiteral[]
| +- Expression[@StandAlonePrimitive = false]
| +- PrimaryExpression[]