Skip to content

Commit

Permalink
Fix compilation after nested imports where removed
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Feb 5, 2024
1 parent ffeb630 commit f9efd68
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -98,7 +98,7 @@ public ClassDeclaration visitClassDeclaration(ClassDeclaration classDecl, Execut
if (hasTestMethods && !hasPublicNonTestMethods && !hasPublicVariableDeclarations) {
// Remove public modifier and move associated comment
final List<Comment> modifierComments = new ArrayList<>();
List<Modifier> modifiers = ListUtils.map(c.getModifiers(), mod -> {
List<J.Modifier> modifiers = ListUtils.map(c.getModifiers(), mod -> {
if (mod.getType() == J.Modifier.Type.Public) {
modifierComments.addAll(mod.getComments());
return null;
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit f9efd68

Please sign in to comment.