mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
project view: improved fix for duplicating module and group names
Treat all modules which names has prefix equal to another module's name as direct children of the parent group to avoid nodes with duplicated names in Project View (IDEA-183205).
This commit is contained in:
@@ -68,20 +68,15 @@ public class ModuleGroup {
|
||||
Set<List<String>> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module));
|
||||
for (final Module module : grouper.getAllModules()) {
|
||||
List<String> group = grouper.getGroupPath(module);
|
||||
if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || allIntermediatePathsAreFromSet(myGroupPath, group, moduleAsGroupsPaths))) {
|
||||
if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || isUnderGroupWithSameNameAsSomeModule(myGroupPath, group, moduleAsGroupsPaths))) {
|
||||
result.add(module);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean allIntermediatePathsAreFromSet(List<String> parent, List<String> descendant, Set<List<String>> set) {
|
||||
for (int i = parent.size() + 1; i < descendant.size() - 1; i++) {
|
||||
if (!set.contains(descendant.subList(0, i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
private static boolean isUnderGroupWithSameNameAsSomeModule(List<String> parent, List<String> descendant, Set<List<String>> moduleNamesAsGroups) {
|
||||
return descendant.size() > parent.size() && moduleNamesAsGroups.contains(descendant.subList(0, parent.size() + 1));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -90,9 +85,11 @@ public class ModuleGroup {
|
||||
Set<List<String>> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module));
|
||||
for (Module module : grouper.getAllModules()) {
|
||||
List<String> group = grouper.getGroupPath(module);
|
||||
if (!moduleAsGroupsPaths.contains(group) && isChild(myGroupPath, group)) {
|
||||
if (isChild(myGroupPath, group)) {
|
||||
final List<String> directChild = ContainerUtil.append(myGroupPath, group.get(myGroupPath.size()));
|
||||
result.add(new ModuleGroup(directChild));
|
||||
if (!moduleAsGroupsPaths.contains(directChild)) {
|
||||
result.add(new ModuleGroup(directChild));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
@@ -60,9 +60,25 @@ class GroupModulesByQualifiedNamesTest : PlatformTestCase() {
|
||||
fun `test module as a group`() {
|
||||
val module1 = createModule("a.foo")
|
||||
val module2 = createModule("a.foo.bar")
|
||||
val module3 = createModule("a.foo.bar.baz")
|
||||
|
||||
assertEquals("foo", grouper.getShortenedName(module1))
|
||||
assertEquals("bar", grouper.getShortenedName(module2))
|
||||
assertEquals("baz", grouper.getShortenedName(module3))
|
||||
|
||||
val parentGroup = ModuleGroup(listOf("a"))
|
||||
assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2, module3)
|
||||
assertSameElements(parentGroup.modulesInGroup(grouper, true), module1, module2, module3)
|
||||
|
||||
assertEmpty(parentGroup.childGroups(grouper))
|
||||
}
|
||||
|
||||
fun `test module as a group with deep ancestor`() {
|
||||
val module1 = createModule("a.foo")
|
||||
val module2 = createModule("a.foo.bar.baz")
|
||||
|
||||
assertEquals("foo", grouper.getShortenedName(module1))
|
||||
assertEquals("baz", grouper.getShortenedName(module2))
|
||||
|
||||
val parentGroup = ModuleGroup(listOf("a"))
|
||||
assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2)
|
||||
|
||||
Reference in New Issue
Block a user