Commit 3e403bf
Use Groovy 4 parser (#6228)
* Use Groovy 4 parser
* Fix missed `visit()` to `doVisit()` rename in GroovyParserVisitor
* Support multi-catch and try-with-resources in Groovy parser (#1944, #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
* Support enum constants with anonymous class bodies in Groovy parser
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.
* Support record and sealed class declarations in Groovy parser
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.
* Address review findings: fix record whitespace, tighten resource heuristic, 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( )
---------
Co-authored-by: Tim te Beek <tim@moderne.io>1 parent 2301028 commit 3e403bf
6 files changed
Lines changed: 393 additions & 97 deletions
File tree
- rewrite-gradle
- rewrite-groovy
- src
- main/java/org/openrewrite/groovy
- test/java/org/openrewrite/groovy/tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
0 commit comments