Collection<Module> (@NotNull 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) || isChild(myGroupPath, group) && (recursively || isUnderGroupWithSameNameAsSomeModule(myGroupPath, group, moduleAsGroupsPaths))) { result.add(module); } } return result; }