From fb749f2ac3fd547bd9f4f8434dd491f14fe756e1 Mon Sep 17 00:00:00 2001 From: Pavel Dolgov Date: Mon, 12 Mar 2018 16:02:51 +0300 Subject: [PATCH] Generate module-info: Use UniqueNameGenerator for module-info names (IDEA-184148) --- .../Java9GenerateModuleDescriptorsAction.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/java19api/Java9GenerateModuleDescriptorsAction.java b/java/java-impl/src/com/intellij/codeInspection/java19api/Java9GenerateModuleDescriptorsAction.java index 4531667f3de4..da1465b2d5e3 100644 --- a/java/java-impl/src/com/intellij/codeInspection/java19api/Java9GenerateModuleDescriptorsAction.java +++ b/java/java-impl/src/com/intellij/codeInspection/java19api/Java9GenerateModuleDescriptorsAction.java @@ -42,7 +42,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.ProjectScope; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.util.CommonRefactoringUtil; -import com.intellij.util.containers.ObjectIntHashMap; +import com.intellij.util.text.UniqueNameGenerator; import gnu.trove.THashMap; import gnu.trove.THashSet; import one.util.streamex.StreamEx; @@ -568,7 +568,7 @@ public class Java9GenerateModuleDescriptorsAction extends AnAction { } private static class UniqueModuleNames { - private final ObjectIntHashMap myCounts = new ObjectIntHashMap<>(); + private final UniqueNameGenerator myNameGenerator; public UniqueModuleNames(@NotNull Project project) { LOG.assertTrue(!DumbService.isDumb(project), "Module name index should be ready"); @@ -576,23 +576,17 @@ public class Java9GenerateModuleDescriptorsAction extends AnAction { JavaModuleNameIndex index = JavaModuleNameIndex.getInstance(); GlobalSearchScope scope = ProjectScope.getAllScope(project); + List modules = new ArrayList<>(); for (String key : index.getAllKeys(project)) { - for (PsiJavaModule module : index.get(key, project, scope)) { - String name = ReadAction.compute(() -> module.getName()); - myCounts.put(name, 1); - } + modules.addAll(index.get(key, project, scope)); } + myNameGenerator = new UniqueNameGenerator(modules, module -> ReadAction.compute(() -> module.getName())); } @NotNull public String getUniqueName(@NotNull Module module) { String name = NameConverter.convertModuleName(module.getName()); - int count = myCounts.get(name, 0); - myCounts.put(name, count + 1); - if (count != 0) { - name += count; - } - return name; + return myNameGenerator.generateUniqueName(name); } }