Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.SourceFile;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.java.JavaIsoVisitor;
Expand Down Expand Up @@ -60,6 +61,13 @@ public class ExtractExplicitConstructorInvocationArguments extends Recipe {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesJavaVersion<>(25), new JavaIsoVisitor<ExecutionContext>() {
@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
// JEP 513 is a Java language feature, and the rewrite is expressed as a `JavaTemplate`, which
// parses its stub as Java. Other JVM languages sharing the Java LST are therefore out of scope.
return sourceFile instanceof J.CompilationUnit;
}

@Override
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
J.MethodDeclaration md = super.visitMethodDeclaration(method, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.condition.JRE.JAVA_25;
import static org.openrewrite.groovy.Assertions.groovy;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.javaVersion;

Expand Down Expand Up @@ -691,4 +692,30 @@ class Child {
)
);
}

@Test
void doNotRunOnGroovySources() {
rewriteRun(
//language=groovy
groovy(
// `@CompileStatic` gives the `super(..)` call a method type; without one the recipe returns early
// and this source would not reach the guard under test
"""
import groovy.transform.CompileStatic

class Parent {
Parent(String name) {
}
}

@CompileStatic
class Child extends Parent {
Child(String name) {
super(name.trim())
}
}
"""
)
);
}
}
Loading