Skip to content

Commit

Permalink
Adopt JavaTemplate.apply; drop context sensitive in ThreadStopUnsup…
Browse files Browse the repository at this point in the history
…ported
  • Loading branch information
timtebeek committed Nov 12, 2024
1 parent 941c654 commit dd7ec21
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
J j = super.visitMethodInvocation(method, ctx);
if (THREAD_STOP_MATCHER.matches(method) || THREAD_RESUME_MATCHER.matches(method) || THREAD_SUSPEND_MATCHER.matches(method)) {
if (usesJava21(ctx)) {
JavaTemplate template = JavaTemplate.builder("throw new UnsupportedOperationException()")
.contextSensitive().build();
j = template.apply(getCursor(), method.getCoordinates().replace());
j = JavaTemplate.apply("throw new UnsupportedOperationException()", getCursor(), method.getCoordinates().replace());
}
if (j.getComments().isEmpty()) {
j = getWithComment(j, method.getName().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.openrewrite.java.Assertions.javaVersion;

class ThreadStopUnsupportedTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new ThreadStopUnsupported());
Expand Down Expand Up @@ -62,8 +63,6 @@ void bar() {
}

@Test
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194")
@DocumentExample
void retainCommentIfPresent() {
rewriteRun(
//language=java
Expand All @@ -82,8 +81,6 @@ void bar() {
}

@Test
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194")
@DocumentExample
void replaceStopWithThrowsOnJava21() {
rewriteRun(
//language=java
Expand Down Expand Up @@ -113,8 +110,6 @@ void bar() {
}

@Test
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194")
@DocumentExample
void replaceResumeWithThrowsOnJava21() {
rewriteRun(
//language=java
Expand Down Expand Up @@ -144,8 +139,6 @@ void bar() {
}

@Test
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194")
@DocumentExample
void replaceSuspendWithThrowsOnJava21() {
rewriteRun(
//language=java
Expand Down

0 comments on commit dd7ec21

Please sign in to comment.