@NotNull
  private static Collection<AbstractTreeNode<?>> getProjectNodeChildren(@NotNull Project project,
                                                                     @NotNull Collection<AbstractTreeNode<?>> children) {
    Collection<AbstractTreeNode<?>> modifiedChildren = new SmartList<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (AbstractTreeNode child : children) {
      Pair<VirtualFile, PsiDirectoryNode> parentNodePair = null;
      if (child instanceof ProjectViewModuleGroupNode groupNode) {
        final Collection<AbstractTreeNode<?>> groupNodeChildren = groupNode.getChildren();
        for (final AbstractTreeNode node : groupNodeChildren) {
          if (node instanceof PsiDirectoryNode psiDirectoryNode) {
            final PsiDirectory psiDirectory = psiDirectoryNode.getValue();
            if (psiDirectory == null) {
              parentNodePair = null;
              break;
            }

            final VirtualFile virtualFile = psiDirectory.getVirtualFile();
            final Module module = fileIndex.getModuleForFile(virtualFile);
            if (!isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) {
              parentNodePair = null;
              break;
            }

            if (parentNodePair == null || VfsUtilCore.isAncestor(virtualFile, parentNodePair.first, false)) {
              parentNodePair = Pair.pair(virtualFile, psiDirectoryNode);
            }
            else if (!VfsUtilCore.isAncestor(parentNodePair.first, virtualFile, false)) {
              parentNodePair = null;
              break;
            }
          }
          else {
            parentNodePair = null;
            break;
          }
        }
      }
      else if (child instanceof PsiDirectoryNode && child.getParent() == null) {
        PsiDirectory psiDirectory = ((PsiDirectoryNode)child).getValue();
        if (psiDirectory != null) {
          VirtualFile directoryFile = psiDirectory.getVirtualFile();
          GradleModuleDirectoryNode gradleModuleNode = getGradleModuleNode(project, (PsiDirectoryNode)child,
                                                                           ((PsiDirectoryNode)child).getSettings());
          if (gradleModuleNode != null) {
            parentNodePair = Pair.pair(directoryFile, gradleModuleNode);
          }
        }
      }
      modifiedChildren.add(parentNodePair != null ? parentNodePair.second : child);
    }
    return modifiedChildren;
  }
@NotNull
  private static Collection<AbstractTreeNode<?>> getProjectNodeChildren(@NotNull Project project,
                                                                     @NotNull Collection<AbstractTreeNode<?>> children)