diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-03-10 15:30:09 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2020-03-11 11:30:50 +0100 |
commit | c3d8894722c20411d56194e7529b52644307731e (patch) | |
tree | cc4003f4c05769758fbe857f30244deb793096fb | |
parent | 6db83944ee6832efcbf3583d2d2b0bde13fd9d89 (diff) | |
download | dokka-c3d8894722c20411d56194e7529b52644307731e.tar.gz dokka-c3d8894722c20411d56194e7529b52644307731e.tar.bz2 dokka-c3d8894722c20411d56194e7529b52644307731e.zip |
Merges documentables with the same source
-rw-r--r-- | core/src/main/kotlin/model/Documentable.kt | 5 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 8ff5969c..94bd624a 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -43,6 +43,11 @@ data class PlatformDependent<out T>( val prevalentValue: T? get() = map.values.distinct().singleOrNull() + val allValues: Sequence<T> = sequence { + expect?.also { yield(it) } + yieldAll(map.values) + } + companion object { fun <T> empty(): PlatformDependent<T> = PlatformDependent(emptyMap()) fun <T> from(platformData: PlatformData, element: T) = PlatformDependent(mapOf(platformData to element)) 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 <T> mergeExpectActual( } fun analyzeExpectActual(sameDriElements: List<T>): List<T> { - val (expect, actual) = sameDriElements.partition { it.sources.expect != null } + val pathGrouped: Collection<T> = mutableMapOf<Set<String>, 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<String> = groupExpectActual.keys.filterIsInstance<Expect.Found<T>>().mapNotNull { it.expect.sources.expect?.path }.toSet() + val pathsToExpects: Set<String> = + groupExpectActual.keys.filterIsInstance<Expect.Found<T>>() + .mapNotNull { it.expect.sources.expect?.path }.toSet() return groupExpectActual.flatMap { reduceExpectActual(it) } + expect.filterNot { it.sources.expect?.path in pathsToExpects } } |