Skip to content

Commit 40588d8

Browse files
committed
Fix recipes containing comments.
1 parent 713fb1c commit 40588d8

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import org.openrewrite.internal.lang.Nullable;
2121
import org.openrewrite.java.*;
2222
import org.openrewrite.java.search.UsesType;
23-
import org.openrewrite.java.tree.Comment;
24-
import org.openrewrite.java.tree.Expression;
25-
import org.openrewrite.java.tree.J;
26-
import org.openrewrite.java.tree.Space;
23+
import org.openrewrite.java.tree.*;
2724
import org.openrewrite.marker.Markers;
2825

2926
import java.util.*;
@@ -117,8 +114,8 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ex
117114
} else if (anno.getArguments() != null && !anno.getArguments().isEmpty()) {
118115
// This conversion is not supported add a comment to the annotation and the method name to the not supported list
119116
String comment = " JunitParamsRunnerToParameterized conversion not supported";
120-
if (anno.getComments().stream().noneMatch(c -> c.getText().equals(comment))) {
121-
anno = anno.withComments(ListUtils.concat(anno.getComments(), new Comment(Comment.Style.LINE, comment,
117+
if (anno.getComments().stream().noneMatch(c -> c.printComment().endsWith(comment))) {
118+
anno = anno.withComments(ListUtils.concat(anno.getComments(), new TextComment(false, comment,
122119
"\n" + anno.getPrefix().getIndent(), Markers.EMPTY)));
123120
}
124121
J.MethodDeclaration m = getCursor().dropParentUntil(J.MethodDeclaration.class::isInstance).getValue();

src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public String getDescription() {
7171

7272
@Override
7373
protected TreeVisitor<?, ExecutionContext> getSingleSourceApplicableTest() {
74+
//noinspection ConstantConditions
7475
return new JavaIsoVisitor<ExecutionContext>() {
7576
private final Marker FOUND_TYPE = new JavaSearchResult(randomId(), null, null);
7677

@@ -114,7 +115,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
114115
if ("setUp".equals(name) || "tearDown".equals(name)) {
115116
return null;
116117
} else if ("setName".equals(name)) {
117-
mi = mi.withPrefix(mi.getPrefix().withComments(ListUtils.concat(mi.getPrefix().getComments(), new Comment(Comment.Style.LINE, "", "", Markers.EMPTY))));
118+
mi = mi.withPrefix(mi.getPrefix().withComments(ListUtils.concat(mi.getPrefix().getComments(), new TextComment(false, "", "", Markers.EMPTY))));
118119
}
119120
}
120121
return mi;

0 commit comments

Comments
 (0)