Module[] (@Nullable Module mainModule, @NotNull Project project) { final Module[] modules; if (mainModule != null) { HashSet<Module> mainModuleWithDependencies = new HashSet<>(); ReadAction.run(() -> ModuleUtilCore.getDependencies(mainModule, mainModuleWithDependencies)); modules = mainModuleWithDependencies.toArray(Module.EMPTY_ARRAY); } else { modules = ModuleManager.getInstance(project).getModules(); } return modules; }