From 1464e136de0a881ecd3a91259d699c1de41ee5a9 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Fri, 15 Nov 2024 18:09:09 +0100 Subject: [PATCH] Remove static `JavaTemplate` field --- .../java/migrate/util/OptionalStreamRecipe.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/util/OptionalStreamRecipe.java b/src/main/java/org/openrewrite/java/migrate/util/OptionalStreamRecipe.java index df57a47ebb..9b7d01ebec 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/OptionalStreamRecipe.java +++ b/src/main/java/org/openrewrite/java/migrate/util/OptionalStreamRecipe.java @@ -50,10 +50,6 @@ public TreeVisitor getVisitor() { } private static class OptionalStreamVisitor extends JavaIsoVisitor { - private static final JavaTemplate template = - JavaTemplate.builder("#{any(java.util.stream.Stream)}.flatMap(Optional::stream)") - .imports("java.util.Optional") - .build(); @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation invocation, ExecutionContext ctx) { @@ -77,6 +73,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation invocation, E JRightPadded mapSelect = mapInvocation.getPadding().getSelect(); JavaType.Method mapInvocationType = mapInvocation.getMethodType(); Space flatMapComments = getFlatMapComments(mapSelect, filterSelect); + JavaTemplate template = + JavaTemplate.builder("#{any(java.util.stream.Stream)}.flatMap(Optional::stream)") + .imports("java.util.Optional") + .build(); J.MethodInvocation flatMapInvocation = template .apply(updateCursor(mapInvocation), mapInvocation.getCoordinates().replace(), filterInvocation.getSelect()); return flatMapInvocation.getPadding()