PsiJavaModule (PsiPackage psiPackage) { PsiManager psiManager = psiPackage.getManager(); return StreamEx.of(psiPackage.getDirectories()) .map(PsiDirectory::getVirtualFile) .nonNull() .map(psiManager::findDirectory) .nonNull() .findAny() .map(JavaModuleGraphUtil::findDescriptorByElement) .orElse(null); }