private static boolean canConvertSealedTo(@NotNull PsiClass sealedClass,
                                            @NotNull PsiClass psiClass,
                                            @NotNull Set<PsiClass> visited) {
    if (visited.contains(sealedClass)) return true;
    visited.add(sealedClass);
    PsiReferenceList permitsList = sealedClass.getPermitsList();
    List<PsiClass> sealedSubClasses = new SmartList<>();
    boolean hasClassInheritors;
    if (permitsList == null) {
      Set<PsiClass> subClasses = findDirectSubClassesInFile(sealedClass);
      hasClassInheritors = subClasses.stream().anyMatch(subClass -> subClassExtendsClass(subClass, psiClass, sealedSubClasses));
    }
    else {
      hasClassInheritors = Arrays.stream(permitsList.getReferencedTypes())
        .map(t -> t.resolve())
        .anyMatch(subClass -> subClassExtendsClass(subClass, psiClass, sealedSubClasses));
    }
    return hasClassInheritors || sealedSubClasses.stream().anyMatch(subClass -> canConvertSealedTo(subClass, psiClass, visited));
  }
private static boolean canConvertSealedTo(@NotNull PsiClass sealedClass,
                                            @NotNull PsiClass psiClass,
                                            @NotNull Set<PsiClass> visited)