Under JEP 427, case label elements may be: a) expressions; b) patterns; c) the default. Currently, this is modeled in the AST in a way where all expressions and patterns extend CaseLabelTree.
When guarded patterns were removed in favor of guards on pattern case label element, it was necessary to augment all patterns with a guard, which is only used when the pattern is used as a case label element. This feels somewhat odd.
It might be better to use a layer of indirection - the CaseLabelTree would only have three subtypes: ExpressionCaseLabelTree, which would contain ExpressionTree as a subnode; PatternCaseLabelTree, which would contain PatternTree and a guard (ExpressionTree) as subnodes; and the DefaultCaseLabelTree for the default clause.
When guarded patterns were removed in favor of guards on pattern case label element, it was necessary to augment all patterns with a guard, which is only used when the pattern is used as a case label element. This feels somewhat odd.
It might be better to use a layer of indirection - the CaseLabelTree would only have three subtypes: ExpressionCaseLabelTree, which would contain ExpressionTree as a subnode; PatternCaseLabelTree, which would contain PatternTree and a guard (ExpressionTree) as subnodes; and the DefaultCaseLabelTree for the default clause.
- csr for
-
JDK-8287579 Reorganize AST related to pattern matching for switch
-
- Closed
-