Merged
Conversation
# Conflicts: # rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java
…1945) Groovy 4 desugars both features at parse time, so the parser must reconstruct them from the desugared AST and source text: - Multi-catch: Groovy splits catch(A | B e) into separate CatchStatements at the same source position; detect and merge into J.MultiCatch - Try-with-resources: Groovy nests each resource in a synthetic BlockStatement/TryCatchStatement structure; walk the nesting to extract resource declarations and the real body block
Groovy 4 represents enum anonymous bodies by appending a ClassExpression to the ListExpression initializer. Detect this pattern, parse the body via visitClassBlock, and populate J.NewClass.body to match Java parser LST structure. Use J.Empty for empty parens to preserve inner whitespace.
Parse Groovy 4 records (primary constructor, components) and sealed classes (sealed/non-sealed modifiers, permits clause) by leveraging the CANONICALIZATION phase AST. Filter synthetic record backing fields and guard against phantom type parameterizations from @Sealed transform.
…istic, add non-sealed test
- Use sourceBefore(")") for last record component to preserve trailing whitespace
- Tighten isDesugaredResourceBlock to also check inner block structure
- Add non-sealed modifier to sealed class test
- Split enum noArguments test to verify both A2() and A2( )
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.
Summary
LessAstTransformationsCompilationUnitto preserve AST structure through the CANONICALIZATION phaseIOException | UncheckedIOException e) and try-with-resources in Groovy parser (GroovyParser support for multi-catch blocks #1944, GroovyParser support for try-with-resources #1945)A1(1) { void foo() {} }) including properJ.NewClassconstruction withJ.Emptyfor empty parensrecorddeclarations with primary constructor parameters parsed asJ.VariableDeclarationssealedclass declarations withpermitsclause,sealed/non-sealedmodifiers@SealedAST transformTest plan
EnumTest.anonymousClassInitializer— enum constants with anonymous class bodies and constructorsEnumTest.noArguments— enum constants with empty parentheses preserving whitespace viaJ.EmptyTryTest.multiCatch,TryTest.multiCatchThreeTypes— multi-catch blocksTryTest.tryWithResource,TryTest.tryWithResources,TryTest.tryWithResourceAndFinally— try-with-resourcesClassDeclarationTest.recordDeclaration— record with primary constructorClassDeclarationTest.sealedClass— sealed class with permits clause and final subclasses