Collection<PsiFileSystemItem> (@Nullable final Module thisModule, boolean includingClasses) { if (thisModule == null) return Collections.emptyList(); ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(thisModule); Set<PsiFileSystemItem> result = new LinkedHashSet<>(); final PsiManager psiManager = PsiManager.getInstance(thisModule.getProject()); if (includingClasses) { VirtualFile[] libraryUrls = moduleRootManager.orderEntries().getAllLibrariesAndSdkClassesRoots(); for (VirtualFile file : libraryUrls) { if (!file.isValid()) continue; PsiDirectory directory = psiManager.findDirectory(file); if (directory != null) { result.add(directory); } } } VirtualFile[] sourceRoots = moduleRootManager.orderEntries().recursively() .withoutSdk().withoutLibraries() .sources().usingCache().getRoots(); for (VirtualFile root : sourceRoots) { if (!root.isValid()) continue; final PsiDirectory directory = psiManager.findDirectory(root); if (directory != null) { final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory); if (aPackage != null && aPackage.getName() != null) { // package prefix result.add(PackagePrefixFileSystemItemImpl.create(directory)); } else { result.add(directory); } } } return result; }