void (@NotNull Project project, @NotNull List<? extends Module> modules, @NotNull Function<? super Module, String> oldNameProvider) { List<Pair<SmartPsiElementPointer<PsiJavaModule>, String>> suggestions = new ArrayList<>(); for (Module module : modules) { if (ModuleType.get(module) == JavaModuleType.getModuleType()) { PsiJavaModule javaModule = Stream.of(ModuleRootManager.getInstance(module).getSourceRoots(false)) .map(root -> JavaModuleGraphUtil.findDescriptorByFile(root, project)) .filter(Objects::nonNull) .findFirst().orElse(null); if (javaModule != null && javaModule.getName().equals(LightJavaModule.moduleName(oldNameProvider.fun(module)))) { suggestions.add(pair(SmartPointerManager.getInstance(project).createSmartPsiElementPointer(javaModule), LightJavaModule.moduleName(module.getName()))); } } } if (!suggestions.isEmpty()) { AppUIExecutor.onUiThread(ModalityState.nonModal()).later().inSmartMode(project).execute(() -> renameModules(project, suggestions)); } }