void (@NotNull Project project, @NotNull List<? extends Module> modules, @NotNull Function<? super Module, String> oldNameProvider) { Map<String, String> moduleMap = modules.stream().collect(Collectors.toMap(oldNameProvider::fun, Module::getName)); for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) { NamedScope[] oldScopes = holder.getEditableScopes(); NamedScope[] newScopes = new NamedScope[oldScopes.length]; for (int i = 0; i < oldScopes.length; i++) { newScopes[i] = renameModulesIn(oldScopes[i], moduleMap); } if (!Arrays.equals(newScopes, oldScopes)) { holder.setScopes(newScopes); } } }