Integrated: 8287236: Reorganize AST related to pattern matching for switch

Jan Lahoda jlahoda at openjdk.java.net
Tue Jun 7 10:35:09 UTC 2022


On Tue, 31 May 2022 16:13:54 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Under JEP 427, case label elements may be: a) expressions; b) patterns; c) the default. Currently, this is modeled in the Trees API 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 is somewhat inconsistent for the Trees API.
> 
> A use a layer of indirection is proposed here: - the `CaseLabelTree` has three subtypes: `ConstantCaseLabelTree`, which contains `ExpressionTree` as a subnode; `PatternCaseLabelTree`, which contains `PatternTree` and a guard (`ExpressionTree`) as subnodes; and the `DefaultCaseLabelTree` for the default clause.
> 
> This patch also fixes `TreeScanner.visitCase`, which currently iterates only over `CaseTree.getExpressions()`, ignoring patterns. It is changed to iterate over `CaseTree.getLabels()`, to get all labels.

This pull request has now been integrated.

Changeset: bde7a7ae
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/bde7a7ae03f51360227c9757b2ab3ddbff4df908
Stats:     651 lines in 27 files changed: 423 ins; 101 del; 127 mod

8287236: Reorganize AST related to pattern matching for switch

Reviewed-by: mcimadamore

-------------

PR: https://git.openjdk.java.net/jdk/pull/8959


More information about the compiler-dev mailing list