TreeModel (final Project project) { Runnable buildingRunnable = () -> { countFiles(project); myFileIndex.iterateContent(new ContentIterator() { PackageDependenciesNode lastParent; VirtualFile dir; @Override public boolean processFile(@NotNull VirtualFile fileOrDir) { if (!fileOrDir.isDirectory()) { if (lastParent != null && !Comparing.equal(dir, fileOrDir.getParent())) { lastParent = null; } lastParent = buildFileNode(fileOrDir, lastParent); dir = fileOrDir.getParent(); } else { lastParent = null; } return true; } }); for (VirtualFile root : LibraryUtil.getLibraryRoots(project)) { processFilesRecursively(root); } }; buildingRunnable.run(); return new TreeModel(myRoot, myTotalFileCount, myMarkedFileCount); }