From bc55869d707e5abafbf8544b5f519e003a504ac6 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 4 Mar 2020 13:34:21 +0100 Subject: Hotfix for merging expect/actual Documentables when no actuals are present --- .../documentables/DefaultDocumentableMerger.kt | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 68ee059d..8ae2065b 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -51,7 +51,7 @@ private fun Iterable.platformDependentFor( return PlatformDependent(actuals, expected) } -private fun PlatformDependent.mergeWith(other: PlatformDependent) = PlatformDependent( +private fun PlatformDependent.mergeWith(other: PlatformDependent) = PlatformDependent( map = this + other, expect = expect ?: other.expect ) @@ -62,7 +62,7 @@ private fun mergeExpectActual( platformSetter: T.(List) -> T ): List where T : Documentable, T : WithExpectActual { - fun findExpect(actual: T, expects: List): Expect = + fun findExpect(actual: T, expects: List): Expect = expects.find { it.platformData.containsAll(actual.platformData) }.let { Expect.from(it) } fun reduceExpectActual(entry: Map.Entry, List>): List = when (val expect = entry.key) { @@ -75,7 +75,10 @@ private fun mergeExpectActual( val mergedExpect = expect.groupBy { it.sources.expect?.path }.values.map { e -> e.first().platformSetter(e.flatMap { it.platformData }.distinct()) } - return actual.groupBy { findExpect(it, mergedExpect) }.flatMap { reduceExpectActual(it) } + val groupExpectActual = actual.groupBy { findExpect(it, mergedExpect) } + 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 } } return elements.groupBy { it.dri }.values.flatMap(::analyzeExpectActual) @@ -90,7 +93,7 @@ private sealed class Expect { } } -fun Package.mergeWith(other: Package) : Package = copy( +fun Package.mergeWith(other: Package): Package = copy( functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), @@ -99,7 +102,7 @@ fun Package.mergeWith(other: Package) : Package = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Function.mergeWith(other: Function) : Function = copy( +fun Function.mergeWith(other: Function): Function = copy( parameters = merge(this.parameters + other.parameters, Parameter::mergeWith), receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation.mergeWith(other.documentation), @@ -119,7 +122,7 @@ fun Property.mergeWith(other: Property): Property = copy( setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter ).mergeExtras(this, other) -fun Classlike.setPlatformData(platformData: List): Classlike = when(this) { +fun Classlike.setPlatformData(platformData: List): Classlike = when (this) { is Class -> copy(platformData = platformData) is Enum -> copy(platformData = platformData) is Interface -> copy(platformData = platformData) @@ -137,7 +140,10 @@ fun Classlike.mergeWith(other: Classlike): Classlike = when { } fun Class.mergeWith(other: Class): Class = copy( - constructors = mergeExpectActual(constructors + other.constructors, Function::mergeWith) { copy(platformData = it) }, + constructors = mergeExpectActual( + constructors + other.constructors, + Function::mergeWith + ) { copy(platformData = it) }, functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), @@ -152,7 +158,10 @@ fun Class.mergeWith(other: Class): Class = copy( fun Enum.mergeWith(other: Enum): Enum = copy( entries = merge(entries + other.entries, EnumEntry::mergeWith), - constructors = mergeExpectActual(constructors + other.constructors, Function::mergeWith) { copy(platformData = it) }, + constructors = mergeExpectActual( + constructors + other.constructors, + Function::mergeWith + ) { copy(platformData = it) }, functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), @@ -197,7 +206,10 @@ fun Interface.mergeWith(other: Interface): Interface = copy( ).mergeExtras(this, other) fun Annotation.mergeWith(other: Annotation): Annotation = copy( - constructors = mergeExpectActual(constructors + other.constructors, Function::mergeWith) { copy(platformData = it) }, + constructors = mergeExpectActual( + constructors + other.constructors, + Function::mergeWith + ) { copy(platformData = it) }, functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), -- cgit