Skip to content

Commit 3e403bf

Browse files
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/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
implementation(project(":rewrite-properties"))
5656
implementation(project(":rewrite-toml"))
5757

58-
compileOnly("org.codehaus.groovy:groovy:latest.release")
58+
compileOnly("org.apache.groovy:groovy:4.+")
5959
compileOnly(gradleApi())
6060
// No particular reason to hold back upgrading this beyond 3.x, but it takes some effort: https://github.com/openrewrite/rewrite/issues/5270
6161
compileOnly("com.gradle:develocity-gradle-plugin:3.+")

rewrite-groovy/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ java {
4444
dependencies {
4545
api(project(":rewrite-java"))
4646

47-
implementation("org.codehaus.groovy:groovy:latest.release")
47+
implementation("org.apache.groovy:groovy:4.+")
4848

4949
compileOnly(project(":rewrite-test"))
5050
compileOnly("org.slf4j:slf4j-api:1.7.+")
@@ -59,7 +59,7 @@ dependencies {
5959
testImplementation(project(":rewrite-java-test"))
6060
testImplementation("org.junit-pioneer:junit-pioneer:latest.release")
6161
testRuntimeOnly("org.antlr:antlr4-runtime:4.13.2")
62-
testRuntimeOnly("org.codehaus.groovy:groovy-all:latest.release")
62+
testRuntimeOnly("org.apache.groovy:groovy-all:4.+")
6363
testRuntimeOnly(project(":rewrite-java-21"))
6464
}
6565

0 commit comments

Comments
 (0)