private static List<ClassAndInheritorCount> findInheritors(@NotNull PsiClass aClass,
                                                             @NotNull CompilerRef.CompilerClassHierarchyElementDef classAsCompilerRef,
                                                             @NotNull GlobalSearchScope searchScope,
                                                             @NotNull PsiElement place,
                                                             int hierarchyCardinality,
                                                             @NotNull Project project,
                                                             @NotNull CompilerReferenceServiceEx compilerRefService) {
    Collection<CompilerRef.CompilerClassHierarchyElementDef> directInheritors = compilerRefService.getDirectInheritors(classAsCompilerRef);

    if (hierarchyCardinality == -1) {
      hierarchyCardinality = compilerRefService.getInheritorCount(classAsCompilerRef);
      if (hierarchyCardinality == -1) {
        return Collections.emptyList();
      }
    }
    int finalHierarchyCardinality = hierarchyCardinality;

    List<ClassAndInheritorCount> directInheritorStats = directInheritors
      .stream()
      .filter(inheritor -> !(inheritor instanceof CompilerRef.CompilerAnonymousClassDef))
      .map(inheritor -> {
        ProgressManager.checkCanceled();
        int count = compilerRefService.getInheritorCount(inheritor);
        if (count != 1 && count * 100 > finalHierarchyCardinality * PERCENT_THRESHOLD) {
          return new Object() {
            final CompilerRef.CompilerClassHierarchyElementDef myDef = inheritor;
            final int inheritorCount = count;
          };
        }
        return null;
      })
      .filter(Objects::nonNull)
      .map(defAndCount -> {
        String name = compilerRefService.getName(defAndCount.myDef.getName());
        PsiClass[] inheritors = JavaPsiFacade.getInstance(project).findClasses(name, searchScope);
        if (inheritors.length == 1) {
          PsiClass inheritor = inheritors[0];
          if (inheritor.isInheritor(aClass, false)) {
            return new ClassAndInheritorCount(inheritor, defAndCount.myDef, defAndCount.inheritorCount);
          }
        }
        return null;
      })
      .filter(Objects::nonNull)
      .toList();

    PsiResolveHelper resolveHelper = PsiResolveHelper.getInstance(project);
    return directInheritorStats
      .stream()
      .filter(c -> resolveHelper.isAccessible(c.psi, place, null))
      .flatMap(c -> StreamEx.of(getClassesIfInterface(c, finalHierarchyCardinality, searchScope, place, project, compilerRefService)).prepend(c))
      .sorted()
      .limit(MAX_RESULT)
      .toList();
  }
private static List<ClassAndInheritorCount> findInheritors(@NotNull PsiClass aClass,
                                                             @NotNull CompilerRef.CompilerClassHierarchyElementDef classAsCompilerRef,
                                                             @NotNull GlobalSearchScope searchScope,
                                                             @NotNull PsiElement place,
                                                             int hierarchyCardinality,
                                                             @NotNull Project project,
                                                             @NotNull CompilerReferenceServiceEx compilerRefService)