project view: do not create implicit module group nodes if they names duplicate module names

Previously if there are modules 'foo' and 'foo.bar' in the project we will show two 'foo' nodes in 'Project View', one for 'foo' module and another as an implicit module group for 'foo.bar' module (IDEA-183205).
This commit is contained in:
nik
2017-12-21 17:08:36 +03:00
parent 04c357661b
commit fe947fc0a5
3 changed files with 46 additions and 2 deletions
@@ -111,6 +111,25 @@ class ModulesInProjectViewTest : BaseProjectViewTestCase() {
""".trimMargin())
}
fun `test do not show groups duplicating module names`() {
val root = directoryContent {
dir("foo") {}
dir("foo.bar") {}
}.generateInVirtualTempDir()
PsiTestUtil.addContentRoot(createModule("xxx.foo"), root.findChild("foo"))
PsiTestUtil.addContentRoot(createModule("xxx.foo.bar"), root.findChild("foo.bar"))
assertStructureEqual("""
|Project
| Group: xxx
| foo
| foo.bar
| test do not show groups duplicating module names.iml
| xxx.foo.bar.iml
| xxx.foo.iml
|
""".trimMargin())
}
fun `test modules with common parent group`() {
val root = directoryContent {
dir("module1") {
@@ -65,21 +65,32 @@ public class ModuleGroup {
@NotNull
public Collection<Module> modulesInGroup(ModuleGrouper grouper, boolean recursively) {
List<Module> result = new ArrayList<>();
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) || (recursively && isChild(myGroupPath, group))) {
if (myGroupPath.equals(group) || isChild(myGroupPath, group) && (recursively || allIntermediatePathsAreFromSet(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;
}
@NotNull
public Collection<ModuleGroup> childGroups(ModuleGrouper grouper) {
Set<ModuleGroup> result = new THashSet<>();
Set<List<String>> moduleAsGroupsPaths = ContainerUtil.map2Set(grouper.getAllModules(), module -> grouper.getModuleAsGroupPath(module));
for (Module module : grouper.getAllModules()) {
List<String> group = grouper.getGroupPath(module);
if (isChild(myGroupPath, group)) {
if (!moduleAsGroupsPaths.contains(group) && isChild(myGroupPath, group)) {
final List<String> directChild = ContainerUtil.append(myGroupPath, group.get(myGroupPath.size()));
result.add(new ModuleGroup(directChild));
}
@@ -57,6 +57,20 @@ class GroupModulesByQualifiedNamesTest : PlatformTestCase() {
assertEmpty(group.childGroups(grouper))
}
fun `test module as a group`() {
val module1 = createModule("a.foo")
val module2 = createModule("a.foo.bar")
assertEquals("foo", grouper.getShortenedName(module1))
assertEquals("bar", grouper.getShortenedName(module2))
val parentGroup = ModuleGroup(listOf("a"))
assertSameElements(parentGroup.modulesInGroup(grouper, false), module1, module2)
assertSameElements(parentGroup.modulesInGroup(grouper, true), module1, module2)
assertEmpty(parentGroup.childGroups(grouper))
}
private val grouper: ModuleGrouper
get() = getQualifiedNameModuleGrouper(myProject)
}