boolean isValidDirectory(PsiDirectory directory, Object owner, ViewSettings settings, PsiFileSystemItemFilter filter) {
    if (directory == null || !directory.isValid()) return false;
    if (settings == null) return true; // unexpected
    if (!(owner instanceof PsiDirectory)) return true;
    if (!settings.isFlattenPackages() && settings.isHideEmptyMiddlePackages()) {
      PsiDirectory parent = directory.getParent();
      if (parent == null || skipDirectory(parent)) return true;
      if (ProjectRootsUtil.isSourceRoot(directory)) return true;
      if (isEmptyMiddleDirectory(directory, true, filter)) return false;
      return processParents(directory, (PsiDirectory)owner, dir -> {
        if (!dir.isValid()) return false;
        PsiDirectory dirParent = dir.getParent();
        if (dirParent == null || skipDirectory(dirParent)) return false;
        return isEmptyMiddleDirectory(dir, true, filter);
      });
    }
    return true;
  }
boolean isValidDirectory(PsiDirectory directory, Object owner, ViewSettings settings, PsiFileSystemItemFilter filter)