From c3d8894722c20411d56194e7529b52644307731e Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Tue, 10 Mar 2020 15:30:09 +0100 Subject: Merges documentables with the same source --- .../documentables/DefaultDocumentableMerger.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 654238a8..4d47401b 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -71,12 +71,25 @@ private fun mergeExpectActual( } fun analyzeExpectActual(sameDriElements: List): List { - val (expect, actual) = sameDriElements.partition { it.sources.expect != null } + val pathGrouped: Collection = mutableMapOf, T>().apply { + sameDriElements.forEach { documentable -> + val paths = documentable.sources.allValues.map { it.path }.toSet() + val key = keys.find { it.containsAll(paths) } + if (key == null) { + put(paths, documentable) + } else { + computeIfPresent(key) { _, old -> reducer(old, documentable) } + } + } + }.values + val (expect, actual) = pathGrouped.partition { it.sources.expect != null } val mergedExpect = expect.groupBy { it.sources.expect?.path }.values.map { e -> e.first().platformSetter(e.flatMap { it.platformData }.distinct()) } val groupExpectActual = actual.groupBy { findExpect(it, mergedExpect) } - val pathsToExpects: Set = groupExpectActual.keys.filterIsInstance>().mapNotNull { it.expect.sources.expect?.path }.toSet() + val pathsToExpects: Set = + groupExpectActual.keys.filterIsInstance>() + .mapNotNull { it.expect.sources.expect?.path }.toSet() return groupExpectActual.flatMap { reduceExpectActual(it) } + expect.filterNot { it.sources.expect?.path in pathsToExpects } } -- cgit