PsiDirectory (PsiManager psiManager, VirtualFile[] roots) { return StreamEx.of(roots) .sorted(Comparator.comparingInt((VirtualFile vFile) -> "java".equals(vFile.getName()) ? 0 : 1) .thenComparing(VirtualFile::getName)) .map(psiManager::findDirectory) .nonNull() .findFirst() .orElse(null); }