Skip to content

Commit 1bcf355

Browse files
authored
fix: Skip code references in comment (#638)
* fix NPE for records * fix: Skip code references in comment
1 parent 9a50b85 commit 1bcf355

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

src/main/java/org/openrewrite/java/migrate/joda/JodaTimeScanner.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
import org.openrewrite.analysis.dataflow.Dataflow;
2727
import org.openrewrite.analysis.dataflow.analysis.SinkFlowSummary;
2828
import org.openrewrite.java.JavaIsoVisitor;
29-
import org.openrewrite.java.tree.Expression;
30-
import org.openrewrite.java.tree.J;
29+
import org.openrewrite.java.JavadocVisitor;
30+
import org.openrewrite.java.tree.*;
3131
import org.openrewrite.java.tree.J.VariableDeclarations.NamedVariable;
32-
import org.openrewrite.java.tree.JavaType;
33-
import org.openrewrite.java.tree.MethodCall;
3432

3533
import java.util.*;
3634
import java.util.concurrent.atomic.AtomicBoolean;
@@ -52,6 +50,19 @@ public JodaTimeScanner(JodaTimeRecipe.Accumulator acc) {
5250
this.acc = acc;
5351
}
5452

53+
@Override
54+
protected JavadocVisitor<ExecutionContext> getJavadocVisitor() {
55+
return new JavadocVisitor<ExecutionContext>(this) {
56+
/**
57+
* Do not visit the method referenced from the Javadoc, may cause recipe to fail.
58+
*/
59+
@Override
60+
public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx) {
61+
return reference;
62+
}
63+
};
64+
}
65+
5566
@Override
5667
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
5768
super.visitCompilationUnit(cu, ctx);

src/test/java/org/openrewrite/java/migrate/joda/JodaTimeRecipeTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,39 @@ public Interval interval() {
467467
)
468468
);
469469
}
470+
471+
@Test
472+
void migrateWithMethodReferenceInComment() {
473+
//language=java
474+
rewriteRun(
475+
java(
476+
"""
477+
import org.joda.time.DateTime;
478+
479+
class A {
480+
public void foo() {
481+
/**
482+
* some method reference in comment
483+
* {@link java.util.List#add(DateTime)}
484+
*/
485+
System.out.println(new DateTime());
486+
}
487+
}
488+
""",
489+
"""
490+
import java.time.ZonedDateTime;
491+
492+
class A {
493+
public void foo() {
494+
/**
495+
* some method reference in comment
496+
* {@link java.util.List#add(DateTime)}
497+
*/
498+
System.out.println(ZonedDateTime.now());
499+
}
500+
}
501+
"""
502+
)
503+
);
504+
}
470505
}

0 commit comments

Comments
 (0)