diff --git a/src/main/java/org/openrewrite/java/spring/boot2/ChangeEmbeddedServletContainerCustomizer.java b/src/main/java/org/openrewrite/java/spring/boot2/ChangeEmbeddedServletContainerCustomizer.java index 5767453b..2c7609b7 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/ChangeEmbeddedServletContainerCustomizer.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/ChangeEmbeddedServletContainerCustomizer.java @@ -28,9 +28,6 @@ public class ChangeEmbeddedServletContainerCustomizer extends Recipe { - - private static J.@Nullable ParameterizedType webFactoryCustomizerIdentifier; - private static final String DEPRECATED_INTERFACE_FQN = "org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer"; @Override @@ -47,6 +44,8 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return Preconditions.check(new UsesType<>(DEPRECATED_INTERFACE_FQN, false), new JavaIsoVisitor() { + private J.@Nullable ParameterizedType webFactoryCustomizerIdentifier; + @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration c = super.visitClassDeclaration(classDecl, ctx); @@ -65,30 +64,30 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex return c; } - }); - } - private static J.ParameterizedType getWebFactoryCustomizerIdentifier(ExecutionContext ctx) { - // Really no need to use a JavaTemplate in this recipe, we just compile a stubbed out class and extract - // the J.ParameterizedType from the class's stub's implements. - if (webFactoryCustomizerIdentifier == null) { - JavaParser parser = JavaParser - .fromJavaVersion() - .classpathFromResources(ctx, "spring-boot-2.*") - .build(); - J.CompilationUnit cu = parser.parse( - "import org.springframework.boot.web.server.WebServerFactoryCustomizer;\n" + - "import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;\n" + - "public abstract class Template implements WebServerFactoryCustomizer {}" - ) - .map(J.CompilationUnit.class::cast) - .findFirst() - .get(); + private J.ParameterizedType getWebFactoryCustomizerIdentifier(ExecutionContext ctx) { + // Really no need to use a JavaTemplate in this recipe, we just compile a stubbed out class and extract + // the J.ParameterizedType from the class's stub's implements. + if (webFactoryCustomizerIdentifier == null) { + JavaParser parser = JavaParser + .fromJavaVersion() + .classpathFromResources(ctx, "spring-boot-2.*") + .build(); + J.CompilationUnit cu = parser.parse( + "import org.springframework.boot.web.server.WebServerFactoryCustomizer;\n" + + "import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;\n" + + "public abstract class Template implements WebServerFactoryCustomizer {}" + ) + .map(J.CompilationUnit.class::cast) + .findFirst() + .get(); - webFactoryCustomizerIdentifier = (J.ParameterizedType) requireNonNull(cu.getClasses() - .get(0).getImplements()).get(0); - } + webFactoryCustomizerIdentifier = (J.ParameterizedType) requireNonNull(cu.getClasses() + .get(0).getImplements()).get(0); + } - return webFactoryCustomizerIdentifier.withId(Tree.randomId()); + return webFactoryCustomizerIdentifier.withId(Tree.randomId()); + } + }); } }