Skip to content

Commit 59b112d

Browse files
committed
Remove one additional super call no longer allowed
1 parent 0f3ca54 commit 59b112d

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
266266
return cd;
267267
}
268268

269-
270269
if (initMethodDeclarationTemplate != null) {
271270
cd = initMethodDeclarationTemplate.apply(updateCursor(cd), cd.getBody().getCoordinates().lastStatement());
272271
J.Block finalBody = cd.getBody();
@@ -382,26 +381,20 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
382381
})
383382
.collect(Collectors.toSet());
384383
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+
})));
385395
}
386396
}
387397
return m;
388398
}
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-
}
406399
}
407400
}

src/test/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterizedTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ public static Collection<Object[]> data1() {
497497
}
498498
499499
public void initI1(String path) {
500-
super(path);
501500
}
502501
503502
@MethodSource("data1")

0 commit comments

Comments
 (0)