Issue #6615: Add support for Java 14 switch and yield#8449
Conversation
This comment has been minimized.
This comment has been minimized.
20a6016 to
96c9237
Compare
96c9237 to
1257317
Compare
08f32ec to
0f0f626
Compare
5e4d6b5 to
8ccdf55
Compare
8ccdf55 to
030137a
Compare
nrmancuso
left a comment
There was a problem hiding this comment.
Some items to discuss:
030137a to
6bbd01f
Compare
6bbd01f to
f9850b0
Compare
pbludov
left a comment
There was a problem hiding this comment.
@esilkensen @romani @rnveach
I agree with @nmancus1 on the idea of a separate token for the SWITCH_RULE. Please share your thoughts.
esilkensen
left a comment
There was a problem hiding this comment.
This is great, nice work again Nick.
|
Has there been any time regression done for antlr changes to see if changes had any negative impact on time taken to parse? |
Not since full records support. Should I run trials against 8.34? |
|
Let's move performance consideration to separate issue. It should not block ability to parse in general. |
cf3f665 to
8893bb8
Compare
8893bb8 to
4482173
Compare
4482173 to
ea441e3
Compare
|
Can be merged when CI passes. |
Run time for guava report for Checkstyle 8.34: 23.460 seconds Difference in report generation times: -0.45 There is no noticeable difference between the execution times of these two runs. The number of files in the guava repo: |


Issue #6615: Add support for Java 14 switch and yield
This PR will introduce support for Java 14 switch expressions, and yield statements.
Relevant JLS grammar for switch expressions:
UnaryExpression:
PreIncrementExpression
PreDecrementExpression
+UnaryExpression-UnaryExpressionUnaryExpressionNotPlusMinus
PreIncrementExpression:
++UnaryExpressionPreDecrementExpression:
--UnaryExpressionUnaryExpressionNotPlusMinus:
PostfixExpression
~UnaryExpression!UnaryExpressionCastExpression
SwitchExpression
SwitchExpression:
switch( Expression ) SwitchBlockSwitchBlock:
{ SwitchLabeledRule {SwitchLabeledRule} }
{ {SwitchLabeledStatementGroup} {SwitchLabel :} }
SwitchLabeledRule:
SwitchLabeledExpression
SwitchLabeledBlock
SwitchLabeledThrowStatement
SwitchLabeledExpression:
SwitchLabel -> Expression ;
SwitchLabeledBlock:
SwitchLabel -> Block
SwitchLabeledThrowStatement:
SwitchLabel -> ThrowStatement
SwitchLabel:
caseCaseConstant {, CaseConstant}defaultCaseConstant:
ConditionalExpression
SwitchLabeledStatementGroup:
SwitchLabel : {SwitchLabel :} BlockStatements
Relevant grammar for yield statements:
YieldStatement:
yieldExpression ;I have introduced the new token, SWITCH_RULE, for the following reasons:
From JLS: When a selector expression matches a switch label for a switch labeled rule, the labeled expression or statement is executed and nothing else.
This means that there is no reason to check for fall-through, as in the case of switch case groups. In checks, we can simply conclude that we are in a switch rule, and know that there will be definite assignment and no fall through.
The java grammar differentiates between the two, so we should also.
The body of both a switch statement and a switch expression (15.28) is known as a switch block. This block can consist of either:
Switch labeled rules, which use -> to introduce either a switch labeled expression, switch labeled block, or a switch labeled throw statement; or
Switch labeled statement groups, which use : to introduce switch labeled block statements.