-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: align pattern matching with Java 21 spec #611
feat: align pattern matching with Java 21 spec #611
Conversation
4071438
to
5310992
Compare
Fixed a printer indentation bug with (and added a test for) nested record patterns. |
$.SUBRULE($.pattern); | ||
$.CONSUME(t.RBrace); | ||
} | ||
GATE: () => this.BACKTRACK_LOOKAHEAD($.recordPattern), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could switch the two options: as there is recursion in the pattern/recordPattern definition, I would suggest backtracking on the typePattern instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Done.
079cf1d
to
ea767b9
Compare
packages/prettier-plugin-java/test/unit-test/pattern-matching/_input.java
Outdated
Show resolved
Hide resolved
packages/prettier-plugin-java/test/unit-test/pattern-matching/_input.java
Outdated
Show resolved
Hide resolved
packages/prettier-plugin-java/test/unit-test/pattern-matching/_output.java
Outdated
Show resolved
Hide resolved
packages/prettier-plugin-java/src/printers/blocks-and-statements.ts
Outdated
Show resolved
Hide resolved
ea767b9
to
46e379e
Compare
46e379e
to
9b6e751
Compare
Thanks @jtkiesel ! |
What changed with this PR:
Aligns pattern matching parsing with the Java 21 spec, and attempts to improve the formatting of switch pattern matching. Record patterns are now supported, and the preview-style guards (
&&
) have been replaced with the official-style guards (when
).NOTE: This means that the
&&
-style guards will no longer be supported by the parser/printer. Because that style was only present as a preview feature (and has been removed as of Java 21 in favor of the official style), perhaps that is okay. I will defer to the project owners. If they decide we must continue supporting the pattern matching preview-style guards, I can attempt to modify this PR to support both simultaneously. My initial thought is that it would be incredibly easy to support both -- I should be able to simply allow aGuard
to contain either aWhen
or anAndAnd
, instead of only aWhen
.Example
Input
Output
Simultaneously fixes an
instanceof
pattern matching printer bug.Example
Input
Output
Relative issues or prs:
Closes #605
Closes #610
Obsoletes #606