From 67ac1ccea64186eddb593695591b2790ea0aa435 Mon Sep 17 00:00:00 2001 From: Jonathan Schneider Date: Fri, 25 Jun 2021 11:43:26 -0700 Subject: [PATCH] Removing JavaVisitor#template --- .../openrewrite/java/spring/NoRequestMappingAnnotation.java | 6 ++---- .../spring/boot2/ConditionalOnBeanAnyNestedCondition.java | 4 ++-- .../java/spring/boot2/OutputCaptureExtension.java | 4 ++-- .../spring/boot2/ReplaceDeprecatedEnvironmentTestUtils.java | 3 ++- .../spring/boot2/RestTemplateBuilderRequestFactory.java | 2 +- .../java/spring/boot2/OutputCaptureExtensionTest.kt | 1 - 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java b/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java index 2c90d861b..93bd65fee 100644 --- a/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java +++ b/src/main/java/org/openrewrite/java/spring/NoRequestMappingAnnotation.java @@ -28,10 +28,8 @@ import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.J; -import java.util.Collections; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Replace method declaration @RequestMapping annotations with the associated variant @@ -100,13 +98,13 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct if (resolvedRequestMappingAnnotationClassName != null) { maybeAddImport("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName); if (a.getArguments() == null || a.getArguments().isEmpty()) { - a = a.withTemplate(template("@" + associatedRequestMapping(requestType.get())) + a = a.withTemplate(JavaTemplate.builder(this::getCursor, "@" + associatedRequestMapping(requestType.get())) .imports("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName) .javaParser(JAVA_PARSER::get).build(), a.getCoordinates().replace()); } else { String annotationTemplateString = "@" + associatedRequestMapping(requestType.get()) + "(" + a.getArguments().stream().map(J::print).collect(Collectors.joining(",")) + ")"; - JavaTemplate tb = template(annotationTemplateString) + JavaTemplate tb = JavaTemplate.builder(this::getCursor, annotationTemplateString) .imports("org.springframework.web.bind.annotation." + resolvedRequestMappingAnnotationClassName) .javaParser(JAVA_PARSER::get).build(); a = a.withTemplate(tb, a.getCoordinates().replace()); diff --git a/src/main/java/org/openrewrite/java/spring/boot2/ConditionalOnBeanAnyNestedCondition.java b/src/main/java/org/openrewrite/java/spring/boot2/ConditionalOnBeanAnyNestedCondition.java index 64c5a5ba1..b22c2288f 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/ConditionalOnBeanAnyNestedCondition.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/ConditionalOnBeanAnyNestedCondition.java @@ -70,7 +70,7 @@ private static class ConditionalOnBeanAnyNestedConditionVisitor extends JavaIsoV private static final String ANY_CONDITION_TEMPLATES = "any_condition_templates"; private static final AnnotationMatcher CONDITIONAL_BEAN = new AnnotationMatcher("@org.springframework.boot.autoconfigure.condition.ConditionalOnBean"); - private final JavaTemplate conditionalTemplate = template("@Conditional(#{}.class)") + private final JavaTemplate conditionalTemplate = JavaTemplate.builder(this::getCursor, "@Conditional(#{}.class)") .imports("org.springframework.context.annotation.Conditional") .javaParser(JAVA_PARSER::get) .build(); @@ -162,7 +162,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex Set conditionalTemplates = getCursor().pollMessage(ANY_CONDITION_TEMPLATES); if (conditionalTemplates != null && !conditionalTemplates.isEmpty()) { for (String s : conditionalTemplates) { - JavaTemplate t = template(s) + JavaTemplate t = JavaTemplate.builder(this::getCursor, s) .imports("org.springframework.boot.autoconfigure.condition.AnyNestedCondition") .javaParser(() -> JavaParser.fromJavaVersion() .dependsOn(Parser.Input.fromResource("/AnyNestedCondition.java", "---")) diff --git a/src/main/java/org/openrewrite/java/spring/boot2/OutputCaptureExtension.java b/src/main/java/org/openrewrite/java/spring/boot2/OutputCaptureExtension.java index d4436f490..18d05e616 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/OutputCaptureExtension.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/OutputCaptureExtension.java @@ -78,7 +78,7 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon @Override protected TreeVisitor getVisitor() { return new JavaIsoVisitor() { - private final JavaTemplate addOutputCaptureExtension = template("@ExtendWith(OutputCaptureExtension.class)") + private final JavaTemplate addOutputCaptureExtension = JavaTemplate.builder(this::getCursor, "@ExtendWith(OutputCaptureExtension.class)") .javaParser(JAVA_PARSER::get) .imports("org.junit.jupiter.api.extension.ExtendWith", "org.springframework.boot.test.system.OutputCaptureExtension") @@ -149,7 +149,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex ); private static class ConvertExpectMethods extends JavaIsoVisitor { - private final JavaTemplate matchesTemplate = template("#{any()}.matches(#{}.getAll())") + private final JavaTemplate matchesTemplate = JavaTemplate.builder(this::getCursor, "#{any()}.matches(#{}.getAll())") .javaParser(JAVA_PARSER::get) .build(); diff --git a/src/main/java/org/openrewrite/java/spring/boot2/ReplaceDeprecatedEnvironmentTestUtils.java b/src/main/java/org/openrewrite/java/spring/boot2/ReplaceDeprecatedEnvironmentTestUtils.java index 122bcf177..7f75fb7c9 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/ReplaceDeprecatedEnvironmentTestUtils.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/ReplaceDeprecatedEnvironmentTestUtils.java @@ -19,6 +19,7 @@ import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; +import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.search.SemanticallyEqual; import org.openrewrite.java.search.UsesType; @@ -253,7 +254,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (maybeMarker.isPresent()) { ReplaceEnvironmentUtilsMarker marker = maybeMarker.get(); m = m.withTemplate( - template(marker.templateString) + JavaTemplate.builder(this::getCursor, marker.templateString) .javaParser(JAVA_PARSER::get) .imports("org.springframework.boot.test.util.TestPropertyValues") .build(), diff --git a/src/main/java/org/openrewrite/java/spring/boot2/RestTemplateBuilderRequestFactory.java b/src/main/java/org/openrewrite/java/spring/boot2/RestTemplateBuilderRequestFactory.java index 8a5c9a907..a868b7c83 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/RestTemplateBuilderRequestFactory.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/RestTemplateBuilderRequestFactory.java @@ -69,7 +69,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method.getArguments().get(0).getType()); if (REQUEST_FACTORY.matches(method) && isArgumentClientHttpRequestFactory) { - JavaTemplate.Builder t = template("() -> #{any(org.springframework.http.client.ClientHttpRequestFactory)}") + JavaTemplate.Builder t = JavaTemplate.builder(this::getCursor, "() -> #{any(org.springframework.http.client.ClientHttpRequestFactory)}") .javaParser(() -> JavaParser.fromJavaVersion() .dependsOn(Parser.Input.fromResource("/RestTemplateBuilder.java", "---")) .build()); diff --git a/src/test/kotlin/org/openrewrite/java/spring/boot2/OutputCaptureExtensionTest.kt b/src/test/kotlin/org/openrewrite/java/spring/boot2/OutputCaptureExtensionTest.kt index 7fcc82a5c..f091c6c95 100644 --- a/src/test/kotlin/org/openrewrite/java/spring/boot2/OutputCaptureExtensionTest.kt +++ b/src/test/kotlin/org/openrewrite/java/spring/boot2/OutputCaptureExtensionTest.kt @@ -17,7 +17,6 @@ package org.openrewrite.java.spring.boot2 import org.junit.jupiter.api.Test import org.openrewrite.Issue -import org.openrewrite.Parser import org.openrewrite.Recipe import org.openrewrite.java.JavaParser import org.openrewrite.java.JavaRecipeTest