Skip to content

Commit 55004c5

Browse files
authored
Fix NumberToDuraion recipe to handle variable (#5208)
1 parent 55da9ba commit 55004c5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

migration-tool/src/main/java/software/amazon/awssdk/migration/internal/recipe/NumberToDuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
8787
String durationStr = durationCreationStr();
8888

8989
JavaTemplate template = JavaTemplate
90-
.builder(durationStr + "(#{})")
90+
.builder(durationStr + "(#{any()})")
9191
.contextSensitive()
9292
.imports("java.time.Duration")
9393
.build();

migration-tool/src/test/java/software/amazon/awssdk/migration/internal/recipe/NumberToDurationTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,37 @@ void timeUnitSpecified_shouldHonor() {
8787
)
8888
);
8989
}
90+
91+
@Test
92+
@EnabledOnJre({JRE.JAVA_8})
93+
void variableProvided_shouldRewrite() {
94+
rewriteRun(
95+
spec -> spec.recipe(new NumberToDuration("com.amazonaws.ClientConfiguration setRequestTimeout(int)",
96+
TimeUnit.SECONDS))
97+
.parser(Java8Parser.builder().classpath("sqs", "aws-core", "sdk-core", "aws-java-sdk-sqs")),
98+
java(
99+
"import com.amazonaws.ClientConfiguration;\n"
100+
+ "\n"
101+
+ "public class Example {\n"
102+
+ " \n"
103+
+ " void test() {\n"
104+
+ " int timeout = 1000;\n"
105+
+ " ClientConfiguration clientConfiguration = new ClientConfiguration();\n"
106+
+ " clientConfiguration.setRequestTimeout(timeout);\n"
107+
+ " }\n"
108+
+ "}\n",
109+
"import com.amazonaws.ClientConfiguration;\n\n"
110+
+ "import java.time.Duration;\n"
111+
+ "\n"
112+
+ "public class Example {\n"
113+
+ " \n"
114+
+ " void test() {\n"
115+
+ " int timeout = 1000;\n"
116+
+ " ClientConfiguration clientConfiguration = new ClientConfiguration();\n"
117+
+ " clientConfiguration.setRequestTimeout(Duration.ofSeconds(timeout));\n"
118+
+ " }\n"
119+
+ "}"
120+
)
121+
);
122+
}
90123
}

0 commit comments

Comments
 (0)