static void sealClass(@NotNull Project project, ModPsiUpdater updater, PsiClass psiClass) {
    PsiJavaFile parentFile = (PsiJavaFile)psiClass.getContainingFile();
    if (psiClass.isInterface()) {
      if (FunctionalExpressionSearch.search(psiClass).findFirst() != null) {
        updater.cancel(JavaBundle.message("intention.error.make.sealed.class.is.used.in.functional.expression"));
        return;
      }
    }

    PsiJavaModule module = JavaModuleGraphUtil.findDescriptorByElement(psiClass);

    List<PsiClass> inheritors = new ArrayList<>();
    Ref<String> message = new Ref<>();
    ClassInheritorsSearch.search(psiClass, false).forEach(inheritor -> {
      String errorTitle = SealedUtils.checkInheritor(parentFile, module, inheritor);
      if (errorTitle != null) {
        message.set(errorTitle);
        return false;
      }

      inheritors.add(updater.getWritable(inheritor));
      return true;
    });
    if (!message.isNull()) {
      updater.cancel(JavaBundle.message(message.get()));
      return;
    }
    List<String> names = ContainerUtil.map(inheritors, PsiClass::getQualifiedName);
    @PsiModifier.ModifierConstant String modifier;
    if (!names.isEmpty()) {
      modifier = PsiModifier.SEALED;
      if (shouldCreatePermitsList(inheritors, parentFile)) {
        addPermitsClause(project, psiClass, names);
      }
      setInheritorsModifiers(inheritors);
    }
    else {
      if (psiClass.isInterface()) {
        updater.cancel(JavaBundle.message("intention.error.make.sealed.class.interface.has.no.inheritors"));
        return;
      }
      else {
        modifier = PsiModifier.FINAL;
      }
    }
    PsiModifierList modifierList = Objects.requireNonNull(psiClass.getModifierList());
    modifierList.setModifierProperty(modifier, true);
  }
static void sealClass(@NotNull Project project, ModPsiUpdater updater, PsiClass psiClass)