diff --git a/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java b/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java index 74df986dd..1bd326c99 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java @@ -26,11 +26,9 @@ import org.openrewrite.analysis.dataflow.Dataflow; import org.openrewrite.analysis.dataflow.analysis.SinkFlowSummary; import org.openrewrite.java.JavaIsoVisitor; -import org.openrewrite.java.tree.Expression; -import org.openrewrite.java.tree.J; +import org.openrewrite.java.JavadocVisitor; +import org.openrewrite.java.tree.*; import org.openrewrite.java.tree.J.VariableDeclarations.NamedVariable; -import org.openrewrite.java.tree.JavaType; -import org.openrewrite.java.tree.MethodCall; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -52,6 +50,19 @@ public JodaTimeScanner(JodaTimeRecipe.Accumulator acc) { this.acc = acc; } + @Override + protected JavadocVisitor getJavadocVisitor() { + return new JavadocVisitor(this) { + /** + * Do not visit the method referenced from the Javadoc, may cause recipe to fail. + */ + @Override + public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx) { + return reference; + } + }; + } + @Override public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) { super.visitCompilationUnit(cu, ctx); diff --git a/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java b/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java index 4f3590a65..a54ef7cec 100644 --- a/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java +++ b/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java @@ -467,4 +467,39 @@ public Interval interval() { ) ); } + + @Test + void migrateWithMethodReferenceInComment() { + //language=java + rewriteRun( + java( + """ + import org.joda.time.DateTime; + + class A { + public void foo() { + /** + * some method reference in comment + * {@link java.util.List#add(DateTime)} + */ + System.out.println(new DateTime()); + } + } + """, + """ + import java.time.ZonedDateTime; + + class A { + public void foo() { + /** + * some method reference in comment + * {@link java.util.List#add(DateTime)} + */ + System.out.println(ZonedDateTime.now()); + } + } + """ + ) + ); + } }