3232import java .util .Arrays ;
3333import java .util .UUID ;
3434
35+ import static java .util .Collections .singletonList ;
36+
3537@ RequiredArgsConstructor
3638public class ExplicitContainerImage extends Recipe {
3739 @ Option (displayName = "Container class" ,
@@ -66,8 +68,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
6668 @ Override
6769 public J .NewClass visitNewClass (J .NewClass newClass , ExecutionContext ctx ) {
6870 J .NewClass nc = super .visitNewClass (newClass , ctx );
69- if (methodMatcher .matches (newClass )) {
70- return nc .withArguments (Arrays .asList (getConstructorArgument (newClass )));
71+ if (methodMatcher .matches (nc )) {
72+ Expression constructorArgument = getConstructorArgument (nc );
73+ return nc .withArguments (Arrays .asList (constructorArgument ))
74+ .withMethodType (nc .getMethodType ()
75+ .withParameterTypes (singletonList (constructorArgument .getType ()))
76+ .withParameterNames (singletonList ("image" )));
7177 }
7278 return nc ;
7379 }
@@ -80,7 +86,7 @@ private Expression getConstructorArgument(J.NewClass newClass) {
8086 .imports ("org.testcontainers.utility.DockerImageName" )
8187 .javaParser (JavaParser .fromJavaVersion ().classpath ("testcontainers" ))
8288 .build ()
83- .apply (getCursor (), newClass .getArguments (). get ( 0 ). getCoordinates ().replace ())
89+ .apply (getCursor (), newClass .getCoordinates ().replace ())
8490 .withPrefix (Space .EMPTY );
8591 }
8692 return new J .Literal (UUID .randomUUID (), Space .EMPTY , Markers .EMPTY , image , "\" " + image + "\" " , null , JavaType .Primitive .String );
0 commit comments