From dd7ec21d970eff5fa03682f8e3087581c18d822a Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 12 Nov 2024 12:48:07 +0100 Subject: [PATCH] Adopt `JavaTemplate.apply`; drop context sensitive in ThreadStopUnsupported --- .../java/migrate/lang/ThreadStopUnsupported.java | 4 +--- .../java/migrate/lang/ThreadStopUnsupportedTest.java | 9 +-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupported.java b/src/main/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupported.java index b9db254bdc..28c6819b07 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupported.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupported.java @@ -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()); diff --git a/src/test/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupportedTest.java b/src/test/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupportedTest.java index e3485e1d29..0dcbd41919 100644 --- a/src/test/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupportedTest.java +++ b/src/test/java/org/openrewrite/java/migrate/lang/ThreadStopUnsupportedTest.java @@ -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()); @@ -62,8 +63,6 @@ void bar() { } @Test - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194") - @DocumentExample void retainCommentIfPresent() { rewriteRun( //language=java @@ -82,8 +81,6 @@ void bar() { } @Test - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194") - @DocumentExample void replaceStopWithThrowsOnJava21() { rewriteRun( //language=java @@ -113,8 +110,6 @@ void bar() { } @Test - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194") - @DocumentExample void replaceResumeWithThrowsOnJava21() { rewriteRun( //language=java @@ -144,8 +139,6 @@ void bar() { } @Test - @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/194") - @DocumentExample void replaceSuspendWithThrowsOnJava21() { rewriteRun( //language=java