From b76e03437143632ec9d42ffc0a5e7af2b88f11c9 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 18 Jan 2024 11:04:47 +0100 Subject: [PATCH] `MigrateRestTemplateBuilderTimeoutByInt`: Don't rely on cycles See: https://github.com/openrewrite/rewrite/pull/3921 --- ...igrateRestTemplateBuilderTimeoutByInt.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/boot2/MigrateRestTemplateBuilderTimeoutByInt.java b/src/main/java/org/openrewrite/java/spring/boot2/MigrateRestTemplateBuilderTimeoutByInt.java index 07f7d8620..fc2632507 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/MigrateRestTemplateBuilderTimeoutByInt.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/MigrateRestTemplateBuilderTimeoutByInt.java @@ -15,10 +15,7 @@ */ package org.openrewrite.java.spring.boot2; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Preconditions; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; +import org.openrewrite.*; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; @@ -48,17 +45,18 @@ public TreeVisitor getVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation m = super.visitMethodInvocation(method, ctx); - if (connectionTimeout.matches(method) || readTimeout.matches(method)) { + updateCursor(m); + if (connectionTimeout.matches(m) || readTimeout.matches(m)) { m = JavaTemplate - .builder("Duration.ofMillis(#{any(int)})") - .imports("java.time.Duration") - .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "spring-boot-2.*")) - .build() - .apply( - getCursor(), - m.getCoordinates().replaceArguments(), - m.getArguments().get(0)); + .builder("Duration.ofMillis(#{any(int)})") + .imports("java.time.Duration") + .javaParser(JavaParser.fromJavaVersion() + .classpathFromResources(ctx, "spring-boot-2.*")) + .build() + .apply( + getCursor(), + m.getCoordinates().replaceArguments(), + m.getArguments().get(0)); maybeAddImport("java.time.Duration"); } return m;