@@ -83,7 +83,7 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
8383
8484 @ SuppressWarnings ("ConstantConditions" )
8585 @ Override
86- public J .@ Nullable MethodInvocation visitMethodInvocation (J .MethodInvocation method , ExecutionContext ctx ) {
86+ public J .MethodInvocation visitMethodInvocation (J .MethodInvocation method , ExecutionContext ctx ) {
8787 J .MethodInvocation mi = super .visitMethodInvocation (method , ctx );
8888 if ((mi .getSelect () != null && TypeUtils .isOfClassType (mi .getSelect ().getType (), "junit.framework.TestCase" )) ||
8989 (mi .getMethodType () != null && TypeUtils .isOfClassType (mi .getMethodType ().getDeclaringType (), "junit.framework.TestCase" ))) {
@@ -103,6 +103,7 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
103103
104104 private static class TestCaseVisitor extends JavaIsoVisitor <ExecutionContext > {
105105 private static final AnnotationMatcher OVERRIDE_ANNOTATION_MATCHER = new AnnotationMatcher ("@java.lang.Override" );
106+ private static final MethodMatcher TEST_CASE_SUPER_MATCHER = new MethodMatcher ("junit.framework.TestCase <constructor>(..)" );
106107
107108 @ Override
108109 public J .ClassDeclaration visitClassDeclaration (J .ClassDeclaration classDecl , ExecutionContext ctx ) {
@@ -134,6 +135,17 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
134135 return md ;
135136 }
136137
138+ @ Override
139+ public J .MethodInvocation visitMethodInvocation (J .MethodInvocation method , ExecutionContext ctx ) {
140+ // If the class no longer extends TestCase there should no longer be calls to TestCase.super()
141+ // Plenty of edge cases around classes which extend classes which extend TestCase this doesn't account for
142+ if (TEST_CASE_SUPER_MATCHER .matches (method )) {
143+ //noinspection DataFlowIssue
144+ return null ;
145+ }
146+ return super .visitMethodInvocation (method , ctx );
147+ }
148+
137149 private J .MethodDeclaration updateMethodDeclarationAnnotationAndModifier (J .MethodDeclaration methodDeclaration , String annotation , String fullyQualifiedAnnotation , ExecutionContext ctx ) {
138150 J .MethodDeclaration md = methodDeclaration ;
139151 if (FindAnnotations .find (methodDeclaration .withBody (null ), "@" + fullyQualifiedAnnotation ).isEmpty ()) {
@@ -162,6 +174,7 @@ private J.MethodDeclaration maybeAddPublicModifier(J.MethodDeclaration md) {
162174 private J .MethodDeclaration maybeRemoveOverrideAnnotation (J .MethodDeclaration md ) {
163175 return md .withLeadingAnnotations (ListUtils .map (md .getLeadingAnnotations (), annotation -> {
164176 if (OVERRIDE_ANNOTATION_MATCHER .matches (annotation )) {
177+ //noinspection DataFlowIssue
165178 return null ;
166179 }
167180 return annotation ;
0 commit comments