@NotNull
  @Override
  public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
                                             @NotNull Collection<AbstractTreeNode<?>> children,
                                            ViewSettings settings) {
    if (!(settings instanceof ProjectViewSettings) || !((ProjectViewSettings)settings).isUseFileNestingRules()) return children;

    ProjectViewNode<?> parentNode = parent instanceof ProjectViewNode ? (ProjectViewNode)parent : null;
    VirtualFile virtualFile = parentNode == null ? null : parentNode.getVirtualFile();
    if (virtualFile == null || !virtualFile.isDirectory()) return children;

    final ArrayList<PsiFileNode> childNodes = new ArrayList<>();
    for (AbstractTreeNode<?> node : children) {
      if (!(node instanceof PsiFileNode)) continue;
      childNodes.add((PsiFileNode)node);
    }

    Function<PsiFileNode, String> fileNameFunc = psiFileNode -> {
      final PsiFile file = psiFileNode.getValue();
      if (file == null) return null;
      return file.getName();
    };
    FileNestingBuilder fileNestingBuilder = FileNestingBuilder.getInstance();
    final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = fileNestingBuilder.mapParentToChildren(childNodes, fileNameFunc);
    if (parentToChildren.isEmpty()) return children;

    // initial ArrayList size may be not exact, not a big problem
    final Collection<AbstractTreeNode<?>> newChildren = new ArrayList<>(children.size() - parentToChildren.size());

    final Set<PsiFileNode> childrenToMoveDown = new HashSet<>(parentToChildren.values());

    for (AbstractTreeNode<?> node : children) {
      if (!(node instanceof PsiFileNode)) {
        newChildren.add(node);
        continue;
      }

      if (childrenToMoveDown.contains(node)) {
        continue;
      }

      final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode)node);
      if (childrenOfThisFile.isEmpty()) {
        newChildren.add(node);
        continue;
      }

      newChildren.add(new NestingTreeNode((PsiFileNode)node, childrenOfThisFile));
    }

    return newChildren;
  }
@NotNull
  @Override
  public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
                                             @NotNull Collection<AbstractTreeNode<?>> children,
                                            ViewSettings settings)