From 4b029f77e60c77e7d7f4571333c7c901a24d35ae Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Mon, 19 Jun 2023 12:55:36 -0700 Subject: [PATCH] Get rid of static JavaParser field to avoid classloading issues on the saas --- ...UseReactivePanacheMongoEntityBaseUniT.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/openrewrite/quarkus/quarkus2/UseReactivePanacheMongoEntityBaseUniT.java b/src/main/java/org/openrewrite/quarkus/quarkus2/UseReactivePanacheMongoEntityBaseUniT.java index 69932f8..b4111d1 100644 --- a/src/main/java/org/openrewrite/quarkus/quarkus2/UseReactivePanacheMongoEntityBaseUniT.java +++ b/src/main/java/org/openrewrite/quarkus/quarkus2/UseReactivePanacheMongoEntityBaseUniT.java @@ -33,26 +33,6 @@ public class UseReactivePanacheMongoEntityBaseUniT extends Recipe { private static final MethodMatcher PERSIST_MATCHER = new MethodMatcher("io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase persist()"); private static final MethodMatcher UPDATE_MATCHER = new MethodMatcher("io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase update()"); private static final MethodMatcher PERSIST_OR_UPDATE_MATCHER = new MethodMatcher("io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase persistOrUpdate()"); - private static final JavaParser.Builder PARSER = - JavaParser.fromJavaVersion().dependsOn( - Stream.of( - Parser.Input.fromString("" + - "package io.smallrye.mutiny;" + - "public interface Uni {" + - " Uni replaceWithVoid() {};" + - "}" - ), - Parser.Input.fromString("" + - "package io.quarkus.mongodb.panache.reactive;" + - "import io.smallrye.mutiny.Uni;" + - "public abstract class ReactivePanacheMongoEntityBase {" + - " public Uni persist() {};" + - " public Uni update() {};" + - " public Uni persistOrUpdate() {};" + - "}" - ) - ).collect(Collectors.toList()) - ); @Override public String getDisplayName() { @@ -74,6 +54,28 @@ public TreeVisitor getVisitor() { } private static class UseReactivePanacheMongoEntityBaseUniTVisitor extends JavaIsoVisitor { + + private static final JavaParser.Builder parser = + JavaParser.fromJavaVersion().dependsOn( + Stream.of( + Parser.Input.fromString("" + + "package io.smallrye.mutiny;" + + "public interface Uni {" + + " Uni replaceWithVoid() {};" + + "}" + ), + Parser.Input.fromString("" + + "package io.quarkus.mongodb.panache.reactive;" + + "import io.smallrye.mutiny.Uni;" + + "public abstract class ReactivePanacheMongoEntityBase {" + + " public Uni persist() {};" + + " public Uni update() {};" + + " public Uni persistOrUpdate() {};" + + "}" + ) + ).collect(Collectors.toList()) + ); + private static boolean hasVoidParameterization(J.MethodInvocation method) { JavaType.Parameterized returnType = TypeUtils.asParameterized(method.getType()); if (returnType != null) { @@ -91,7 +93,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (PERSIST_MATCHER.matches(mi)) { if (hasVoidParameterization(mi)) { mi = JavaTemplate.builder("#{any(io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase)}.persist().replaceWithVoid()") - .javaParser(PARSER) + .javaParser(parser) .build().apply(new Cursor(getCursor().getParent(), mi), mi.getCoordinates().replace(), mi.getSelect()); @@ -99,7 +101,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } else if (UPDATE_MATCHER.matches(mi)) { if (hasVoidParameterization(mi)) { mi = JavaTemplate.builder("#{any(io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase)}.update().replaceWithVoid()") - .javaParser(PARSER) + .javaParser(parser) .build().apply(new Cursor(getCursor().getParent(), mi), mi.getCoordinates().replace(), mi.getSelect()); @@ -107,7 +109,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } else if (PERSIST_OR_UPDATE_MATCHER.matches(mi)) { if (hasVoidParameterization(mi)) { mi = JavaTemplate.builder("#{any(io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntityBase)}.persistOrUpdate().replaceWithVoid()") - .javaParser(PARSER) + .javaParser(parser) .build().apply(new Cursor(getCursor().getParent(), mi), mi.getCoordinates().replace(), mi.getSelect());