PsiDirectory[] (Module module) { List<VirtualFile> roots = new ArrayList<>(); JavaProjectRootsUtil.collectSuitableDestinationSourceRoots(module, roots); PsiManager psiManager = PsiManager.getInstance(module.getProject()); return roots.stream() .map(psiManager::findDirectory) .filter(Objects::nonNull) .sorted(Comparator.comparing(psiDir -> psiDir.getVirtualFile().getPresentableUrl())) .toArray(PsiDirectory[]::new); }