Collection<Module> (@NotNull Project project, @Nullable String className) { if (project.isDefault()) { return Arrays.asList(ModuleManager.getInstance(project).getModules()); } PsiDocumentManager.getInstance(project).commitAllDocuments(); final PsiClass[] possibleClasses = className == null ? PsiClass.EMPTY_ARRAY : JavaPsiFacade.getInstance(project).findClasses(className, GlobalSearchScope.projectScope(project)); final Set<Module> modules = new HashSet<>(); for (PsiClass aClass : possibleClasses) { Module module = ModuleUtilCore.findModuleForPsiElement(aClass); if (module != null) { modules.add(module); } } if (modules.isEmpty()) { return Arrays.asList(ModuleManager.getInstance(project).getModules()); } else { final Set<Module> result = new HashSet<>(); for (Module module : modules) { ModuleUtilCore.collectModulesDependsOn(module, result); } return result; } }