From f9efd68e317ffbae7c8002b014bf6c4df933c6a5 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 5 Feb 2024 13:22:46 +0100 Subject: [PATCH] Fix compilation after nested imports where removed --- .../testing/cleanup/TestsShouldNotBePublic.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java index 00566ed5e..3f2e9f8a0 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java @@ -72,12 +72,12 @@ private TestsNotPublicVisitor(Boolean orProtected) { } @Override - public ClassDeclaration visitClassDeclaration(ClassDeclaration classDecl, ExecutionContext ctx) { - ClassDeclaration c = super.visitClassDeclaration(classDecl, ctx); + public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { + J.ClassDeclaration c = super.visitClassDeclaration(classDecl, ctx); - if (c.getKind() != ClassDeclaration.Kind.Type.Interface + if (c.getKind() != J.ClassDeclaration.Kind.Type.Interface && c.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public) - && c.getModifiers().stream().noneMatch(mod -> mod.getType() == Type.Abstract)) { + && c.getModifiers().stream().noneMatch(mod -> mod.getType() == J.Modifier.Type.Abstract)) { boolean hasTestMethods = c.getBody().getStatements().stream() .filter(org.openrewrite.java.tree.J.MethodDeclaration.class::isInstance) @@ -98,7 +98,7 @@ public ClassDeclaration visitClassDeclaration(ClassDeclaration classDecl, Execut if (hasTestMethods && !hasPublicNonTestMethods && !hasPublicVariableDeclarations) { // Remove public modifier and move associated comment final List modifierComments = new ArrayList<>(); - List modifiers = ListUtils.map(c.getModifiers(), mod -> { + List modifiers = ListUtils.map(c.getModifiers(), mod -> { if (mod.getType() == J.Modifier.Type.Public) { modifierComments.addAll(mod.getComments()); return null; @@ -131,7 +131,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex return m; } - if (m.getModifiers().stream().anyMatch(mod -> (mod.getType() == J.Modifier.Type.Public || (orProtected && mod.getType() == Type.Protected))) + if (m.getModifiers().stream().anyMatch(mod -> (mod.getType() == J.Modifier.Type.Public || (orProtected && mod.getType() == J.Modifier.Type.Protected))) && Boolean.FALSE.equals(TypeUtils.isOverride(method.getMethodType())) && hasJUnit5MethodAnnotation(m)) { // remove public modifier @@ -141,7 +141,7 @@ && hasJUnit5MethodAnnotation(m)) { return m; } - private boolean hasJUnit5MethodAnnotation(MethodDeclaration method) { + private boolean hasJUnit5MethodAnnotation(J.MethodDeclaration method) { for (J.Annotation a : method.getLeadingAnnotations()) { if (TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.Test") || TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.RepeatedTest")