24
24
import org .openrewrite .java .MethodMatcher ;
25
25
import org .openrewrite .java .tree .Expression ;
26
26
import org .openrewrite .java .tree .J ;
27
+ import org .openrewrite .java .tree .TypedTree ;
27
28
28
29
public class AssertTrueInstanceofToAssertInstanceOf extends Recipe {
29
30
@ Override
@@ -46,7 +47,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
46
47
MethodMatcher junit5Matcher = new MethodMatcher ("org.junit.jupiter.api.Assertions assertTrue(boolean, ..)" );
47
48
MethodMatcher junit4Matcher = new MethodMatcher ("org.junit.Assert assertTrue(.., boolean)" );
48
49
49
- J clazz ;
50
+ TypedTree clazz ;
50
51
Expression expression ;
51
52
Expression reason ;
52
53
@@ -64,7 +65,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
64
65
if (argument instanceof J .InstanceOf ) {
65
66
J .InstanceOf instanceOf = (J .InstanceOf ) argument ;
66
67
expression = instanceOf .getExpression ();
67
- clazz = instanceOf .getClazz ();
68
+ clazz = ( TypedTree ) instanceOf .getClazz ();
68
69
} else {
69
70
return mi ;
70
71
}
@@ -84,7 +85,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
84
85
if (argument instanceof J .InstanceOf ) {
85
86
J .InstanceOf instanceOf = (J .InstanceOf ) argument ;
86
87
expression = instanceOf .getExpression ();
87
- clazz = instanceOf .getClazz ();
88
+ clazz = ( TypedTree ) instanceOf .getClazz ();
88
89
} else {
89
90
return mi ;
90
91
}
@@ -97,6 +98,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
97
98
.builder ("assertInstanceOf(#{}.class, #{any(java.lang.Object)}" + (reason != null ? ", #{any(java.lang.String)})" : ")" ))
98
99
.javaParser (JavaParser .fromJavaVersion ().classpathFromResources (ctx , "junit-jupiter-api-5" , "junit-4" ))
99
100
.staticImports ("org.junit.jupiter.api.Assertions.assertInstanceOf" )
101
+ .imports (String .valueOf (clazz .getType ()))
100
102
.build ();
101
103
102
104
J .MethodInvocation methodd = reason != null ?
0 commit comments