@Override @NotNull public Collection<AbstractTreeNode> getChildren() { Module module = getValue(); if (module == null || module.isDisposed()) { // module has been disposed return Collections.emptyList(); } ModuleRootManager rootManager = ModuleRootManager.getInstance(module); ModuleFileIndex moduleFileIndex = rootManager.getFileIndex(); final VirtualFile[] contentRoots = rootManager.getContentRoots(); final List<AbstractTreeNode> children = new ArrayList<AbstractTreeNode>(contentRoots.length + 1); final PsiManager psiManager = PsiManager.getInstance(module.getProject()); for (final VirtualFile contentRoot : contentRoots) { if (!moduleFileIndex.isInContent(contentRoot)) continue; if (contentRoot.isDirectory()) { PsiDirectory directory = psiManager.findDirectory(contentRoot); if (directory != null) { children.add(new PsiDirectoryNode(getProject(), directory, getSettings())); } } else { PsiFile file = psiManager.findFile(contentRoot); if (file != null) { children.add(new PsiFileNode(getProject(), file, getSettings())); } } } /* if (getSettings().isShowLibraryContents()) { children.add(new LibraryGroupNode(getProject(), new LibraryGroupElement(getValue()), getSettings())); } */ return children; }
@NotNull private RootInfo buildRootInfo(@NotNull Project project) { final RootInfo info = new RootInfo(); for (final Module module : ModuleManager.getInstance(project).getModules()) { final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); for (final VirtualFile contentRoot : moduleRootManager.getContentRoots()) { if (!info.contentRootOf.containsKey(contentRoot)) { info.contentRootOf.put(contentRoot, module); } } for (ContentEntry contentEntry : moduleRootManager.getContentEntries()) { if (!(contentEntry instanceof ContentEntryImpl) || !((ContentEntryImpl) contentEntry).isDisposed()) { for (VirtualFile excludeRoot : contentEntry.getExcludeFolderFiles()) { info.excludedFromModule.put(excludeRoot, module); } } // Init module sources for (final SourceFolder sourceFolder : contentEntry.getSourceFolders()) { final VirtualFile sourceFolderRoot = sourceFolder.getFile(); if (sourceFolderRoot != null) { info.rootTypeId.put(sourceFolderRoot, getRootTypeId(sourceFolder.getRootType())); info.classAndSourceRoots.add(sourceFolderRoot); info.sourceRootOf.putValue(sourceFolderRoot, module); info.packagePrefix.put(sourceFolderRoot, sourceFolder.getPackagePrefix()); } } } for (OrderEntry orderEntry : moduleRootManager.getOrderEntries()) { if (orderEntry instanceof LibraryOrSdkOrderEntry) { final LibraryOrSdkOrderEntry entry = (LibraryOrSdkOrderEntry) orderEntry; final VirtualFile[] sourceRoots = entry.getRootFiles(OrderRootType.SOURCES); final VirtualFile[] classRoots = entry.getRootFiles(OrderRootType.CLASSES); // Init library sources for (final VirtualFile sourceRoot : sourceRoots) { info.classAndSourceRoots.add(sourceRoot); info.libraryOrSdkSources.add(sourceRoot); info.packagePrefix.put(sourceRoot, ""); } // init library classes for (final VirtualFile classRoot : classRoots) { info.classAndSourceRoots.add(classRoot); info.libraryOrSdkClasses.add(classRoot); info.packagePrefix.put(classRoot, ""); } if (orderEntry instanceof LibraryOrderEntry) { Library library = ((LibraryOrderEntry) orderEntry).getLibrary(); if (library != null) { for (VirtualFile root : ((LibraryEx) library).getExcludedRoots()) { info.excludedFromLibraries.putValue(root, library); } for (VirtualFile root : sourceRoots) { info.sourceOfLibraries.putValue(root, library); } for (VirtualFile root : classRoots) { info.classOfLibraries.putValue(root, library); } } } } } } for (DirectoryIndexExcludePolicy policy : Extensions.getExtensions(DirectoryIndexExcludePolicy.EP_NAME, project)) { Collections.addAll(info.excludedFromProject, policy.getExcludeRootsForProject()); } return info; }