2727import java .util .ArrayList ;
2828import java .util .Collections ;
2929import java .util .List ;
30+ import java .util .Objects ;
3031import java .util .function .Supplier ;
3132import java .util .stream .Collectors ;
3233import java .util .stream .Stream ;
@@ -35,8 +36,8 @@ public class TemporaryFolderToTempDir extends Recipe {
3536 private static final AnnotationMatcher CLASS_RULE_ANNOTATION_MATCHER = new AnnotationMatcher ("@org.junit.ClassRule" );
3637 private static final AnnotationMatcher RULE_ANNOTATION_MATCHER = new AnnotationMatcher ("@org.junit.Rule" );
3738
38- private static final JavaType .Class FILE_TYPE = JavaType .Class .build ("java.io.File" );
39- private static final JavaType .Class STRING_TYPE = JavaType .Class .build ("java.lang.String" );
39+ private static final JavaType .Class FILE_TYPE = JavaType .ShallowClass .build ("java.io.File" );
40+ private static final JavaType .Class STRING_TYPE = JavaType .ShallowClass .build ("java.lang.String" );
4041 private static final Supplier <JavaParser > TEMPDIR_PARSER = () ->
4142 JavaParser .fromJavaVersion ().dependsOn (Collections .singletonList (
4243 Parser .Input .fromString ("" +
@@ -109,8 +110,8 @@ private boolean isRuleAnnotatedTemporaryFolder(J.VariableDeclarations vd) {
109110 @ Override
110111 public J visitMethodInvocation (J .MethodInvocation method , ExecutionContext executionContext ) {
111112 J .MethodInvocation mi = (J .MethodInvocation ) super .visitMethodInvocation (method , executionContext );
112- String declaringType = mi .getMethodType () != null ? mi .getMethodType (). getDeclaringType (). getFullyQualifiedName () : null ;
113- if ( "org.junit.rules.TemporaryFolder" . equals ( declaringType ) && mi . getSelect () != null ) {
113+ if ( mi .getSelect () != null && mi .getMethodType () != null
114+ && TypeUtils . isOfClassType ( mi . getMethodType (). getDeclaringType (), "org.junit.rules.TemporaryFolder" ) ) {
114115 switch (mi .getSimpleName ()) {
115116 case "newFile" :
116117 return convertToNewFile (mi );
@@ -167,7 +168,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
167168 && params .size () == 2
168169 && params .get (0 ).hasClassType (FILE_TYPE )
169170 && params .get (1 ).hasClassType (STRING_TYPE );
170- }).map (J .MethodDeclaration ::getMethodType ).findAny ().orElse (null );
171+ }).map (J .MethodDeclaration ::getMethodType ).filter ( Objects :: nonNull ). findAny ().orElse (null );
171172
172173 if (newFolderMethodDeclaration == null ) {
173174 cd = cd .withTemplate (JavaTemplate .builder (this ::getCursor ,
0 commit comments