@@ -266,7 +266,6 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
266
266
return cd ;
267
267
}
268
268
269
-
270
269
if (initMethodDeclarationTemplate != null ) {
271
270
cd = initMethodDeclarationTemplate .apply (updateCursor (cd ), cd .getBody ().getCoordinates ().lastStatement ());
272
271
J .Block finalBody = cd .getBody ();
@@ -382,26 +381,20 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
382
381
})
383
382
.collect (Collectors .toSet ());
384
383
getCursor ().dropParentUntil (J .ClassDeclaration .class ::isInstance ).putMessage ("INIT_VARS" , fieldNames );
384
+
385
+ // Remove any potential super call
386
+ m = m .withBody (m .getBody ().withStatements (ListUtils .mapFirst (m .getBody ().getStatements (), stmt -> {
387
+ if (stmt instanceof J .MethodInvocation ) {
388
+ J .MethodInvocation mi = (J .MethodInvocation ) stmt ;
389
+ if (mi .getName ().getSimpleName ().equals ("super" )) {
390
+ return null ;
391
+ }
392
+ }
393
+ return stmt ;
394
+ })));
385
395
}
386
396
}
387
397
return m ;
388
398
}
389
-
390
- @ Override
391
- public J .@ Nullable MethodInvocation visitMethodInvocation (J .MethodInvocation method , ExecutionContext ctx ) {
392
- J .MethodInvocation mi = super .visitMethodInvocation (method , ctx );
393
- J .MethodDeclaration enclosingMethod = getCursor ().firstEnclosing (J .MethodDeclaration .class );
394
- // remove redundant super call, otherwise it will create compilation error when this constructor is converted to regular method.
395
- // TODO: Handle super call with arguments.
396
- if (enclosingMethod != null && enclosingMethod .isConstructor () && mi .getName ().getSimpleName ().equals ("super" ) && isEmptyArgs (mi )) {
397
- return null ;
398
- }
399
- return mi ;
400
- }
401
-
402
- private static boolean isEmptyArgs (J .MethodInvocation mi ) {
403
- return mi .getArguments ().isEmpty () ||
404
- (mi .getArguments ().size () == 1 && mi .getArguments ().get (0 ) instanceof J .Empty );
405
- }
406
399
}
407
400
}
0 commit comments