Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip code references in comment #638

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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 @@ -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;
Expand All @@ -52,6 +50,19 @@ public JodaTimeScanner(JodaTimeRecipe.Accumulator acc) {
this.acc = acc;
}

@Override
protected JavadocVisitor<ExecutionContext> getJavadocVisitor() {
return new JavadocVisitor<ExecutionContext>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
"""
)
);
}
}
Loading