void (@NotNull ProjectFileNode parent, boolean hideEmptyMiddle, @NotNull Consumer<? super ProjectFileNode> consumer) { AtomicBoolean empty = new AtomicBoolean(hideEmptyMiddle); AtomicBoolean middle = new AtomicBoolean(); model.getChildren(parent).forEach(child -> { PsiElement element = findFileSystemItem(child.getVirtualFile()); if (element instanceof PsiDirectory) { Icon icon = getFolderIcon(element); if (isPackage(icon)) { if (hideEmptyMiddle) middle.set(true); // contains packages visitPackages(child, hideEmptyMiddle, consumer); } else { if (hideEmptyMiddle) empty.set(false); // contains folders } } else if (element instanceof PsiFile) { if (hideEmptyMiddle) empty.set(false); // contains files } }); if (!empty.get() || !middle.get()) consumer.consume(parent); }