Skip to content

Commit

Permalink
MigrateRestTemplateBuilderTimeoutByInt: Don't rely on cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 18, 2024
1 parent 2ce6e11 commit b76e034
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,17 +45,18 @@ public TreeVisitor<?, ExecutionContext> 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;
Expand Down

0 comments on commit b76e034

Please sign in to comment.