feat: align pattern matching with Java 21 spec#611
Merged
clementdessoude merged 1 commit intojhipster:mainfrom Nov 11, 2023
Merged
feat: align pattern matching with Java 21 spec#611clementdessoude merged 1 commit intojhipster:mainfrom
clementdessoude merged 1 commit intojhipster:mainfrom
Conversation
4071438 to
5310992
Compare
Contributor
Author
|
Fixed a printer indentation bug with (and added a test for) nested record patterns. |
| $.SUBRULE($.pattern); | ||
| $.CONSUME(t.RBrace); | ||
| } | ||
| GATE: () => this.BACKTRACK_LOOKAHEAD($.recordPattern), |
Contributor
There was a problem hiding this comment.
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
079cf1d to
ea767b9
Compare
ea767b9 to
46e379e
Compare
46e379e to
9b6e751
Compare
Contributor
|
Thanks @jtkiesel ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aGuardto contain either aWhenor anAndAnd, instead of only aWhen.Example
Input
Output
Simultaneously fixes an
instanceofpattern matching printer bug.Example
Input
Output
Relative issues or prs:
Closes #605
Closes #610
Obsoletes #606