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 @@ -27,6 +27,7 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.staticanalysis.java.JavaFileChecker;

import java.util.Iterator;

Expand Down Expand Up @@ -57,7 +58,10 @@ public class AddMissingMethodImplementation extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>(fullyQualifiedClassName, true), new ClassImplementationVisitor());
// The method template is Java, so printing it into a Kotlin or Groovy class would not compile.
return Preconditions.check(
Preconditions.and(new JavaFileChecker<>(), new UsesType<>(fullyQualifiedClassName, true)),
new ClassImplementationVisitor());
}

public class ClassImplementationVisitor extends JavaIsoVisitor<ExecutionContext> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.javaVersion;
import static org.openrewrite.kotlin.Assertions.kotlin;

class AddMissingMethodImplementationTest implements RewriteTest {

Expand Down Expand Up @@ -234,4 +235,18 @@ class C2 {
)
);
}

@Test
void leaveKotlinAlone() {
rewriteRun(
spec -> spec.recipe(new AddMissingMethodImplementation("java.lang.Runnable", "java.lang.Runnable run()",
"public void run() { }")),
//language=kotlin
kotlin(
"""
class Delegating(runnable: Runnable) : Runnable by runnable
"""
)
);
}
}