Skip to content

Commit 31d9065

Browse files
committed
Trim how we remove super call
1 parent 59b112d commit 31d9065

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
7676

7777
// Constructor Injected Test
7878
if (parametersMethodName != null && constructorParams != null && constructorParams.stream().anyMatch(org.openrewrite.java.tree.J.VariableDeclarations.class::isInstance)) {
79-
doAfterVisit(new ParameterizedRunnerToParameterizedTestsVisitor(classDecl, parametersMethodName, initMethodName, parametersAnnotationArguments, constructorParams, true, beforeMethodName,ctx));
79+
doAfterVisit(new ParameterizedRunnerToParameterizedTestsVisitor(classDecl, parametersMethodName, initMethodName, parametersAnnotationArguments, constructorParams, true, beforeMethodName, ctx));
8080
}
8181

8282
// Field Injected Test
@@ -290,7 +290,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
290290
if (statement instanceof J.VariableDeclarations) {
291291
J.VariableDeclarations varDecls = (J.VariableDeclarations) statement;
292292
if (varDecls.getVariables().stream().anyMatch(it -> fieldNames.contains(it.getSimpleName())) &&
293-
(varDecls.hasModifier(J.Modifier.Type.Final))) {
293+
(varDecls.hasModifier(J.Modifier.Type.Final))) {
294294
varDecls = varDecls.withModifiers(ListUtils.map(varDecls.getModifiers(), mod -> mod.getType() == J.Modifier.Type.Final ? null : mod));
295295
statement = maybeAutoFormat(statement, varDecls, ctx, new Cursor(getCursor(), finalBody));
296296
}
@@ -383,15 +383,10 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
383383
getCursor().dropParentUntil(J.ClassDeclaration.class::isInstance).putMessage("INIT_VARS", fieldNames);
384384

385385
// 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-
})));
386+
m = m.withBody(m.getBody().withStatements(ListUtils.mapFirst(m.getBody().getStatements(),
387+
stmt -> stmt instanceof J.MethodInvocation &&
388+
"super".equals(((J.MethodInvocation) stmt).getSimpleName()) ?
389+
null : stmt)));
395390
}
396391
}
397392
return m;

0 commit comments

Comments
 (0)