diff options
3 files changed, 35 insertions, 34 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 67a8beef..778d1458 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -53,7 +53,7 @@ data class PlatformDependent<out T>( } interface WithExpectActual { - val actual: PlatformDependent<DocumentableSource> + val sources: PlatformDependent<DocumentableSource> } interface WithScope { @@ -142,7 +142,7 @@ data class Class( override val functions: List<Function>, override val properties: List<Property>, override val classlikes: List<Classlike>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val visibility: PlatformDependent<Visibility>, override val companion: Object?, override val generics: List<TypeParameter>, @@ -165,7 +165,7 @@ data class Enum( override val name: String, val entries: List<EnumEntry>, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val functions: List<Function>, override val properties: List<Property>, override val classlikes: List<Classlike>, @@ -204,7 +204,7 @@ data class Function( val isConstructor: Boolean, val parameters: List<Parameter>, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val visibility: PlatformDependent<Visibility>, override val type: TypeWrapper, override val generics: List<TypeParameter>, @@ -223,7 +223,7 @@ data class Interface( override val dri: DRI, override val name: String, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val functions: List<Function>, override val properties: List<Property>, override val classlikes: List<Classlike>, @@ -244,7 +244,7 @@ data class Object( override val name: String?, override val dri: DRI, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val functions: List<Function>, override val properties: List<Property>, override val classlikes: List<Classlike>, @@ -263,7 +263,7 @@ data class Annotation( override val name: String, override val dri: DRI, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val functions: List<Function>, override val properties: List<Property>, override val classlikes: List<Classlike>, @@ -283,7 +283,7 @@ data class Property( override val dri: DRI, override val name: String, override val documentation: PlatformDependent<DocumentationNode>, - override val actual: PlatformDependent<DocumentableSource>, + override val sources: PlatformDependent<DocumentableSource>, override val visibility: PlatformDependent<Visibility>, override val type: TypeWrapper, override val receiver: Parameter?, diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 64363078..68ee059d 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -71,8 +71,8 @@ private fun <T> mergeExpectActual( } fun analyzeExpectActual(sameDriElements: List<T>): List<T> { - val (expect, actual) = sameDriElements.partition { it.actual.expect != null } - val mergedExpect = expect.groupBy { it.actual.expect?.path }.values.map { e -> + val (expect, actual) = sameDriElements.partition { it.sources.expect != null } + 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) } @@ -103,7 +103,7 @@ 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), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct(), generics = merge(generics + other.generics, TypeParameter::mergeWith) @@ -112,7 +112,7 @@ fun Function.mergeWith(other: Function) : Function = copy( fun Property.mergeWith(other: Property): Property = copy( receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct(), getter = getter?.let { g -> other.getter?.let { g.mergeWith(it) } ?: g } ?: other.getter, @@ -145,7 +145,7 @@ fun Class.mergeWith(other: Class): Class = copy( generics = merge(generics + other.generics, TypeParameter::mergeWith), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) @@ -159,7 +159,7 @@ fun Enum.mergeWith(other: Enum): Enum = copy( companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) @@ -178,7 +178,7 @@ fun Object.mergeWith(other: Object): Object = copy( classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) @@ -191,7 +191,7 @@ fun Interface.mergeWith(other: Interface): Interface = copy( generics = merge(generics + other.generics, TypeParameter::mergeWith), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) @@ -203,7 +203,7 @@ fun Annotation.mergeWith(other: Annotation): Annotation = copy( classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, documentation = documentation.mergeWith(other.documentation), - actual = actual.mergeWith(other.actual), + sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 895690c2..531537a4 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -96,7 +96,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), - actual = descriptor.actual(platformData, descriptor), + sources = descriptor.createSources(), visibility = PlatformDependent.from(platformData, descriptor.visibility), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, @@ -117,7 +117,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), - actual = descriptor.actual(platformData, descriptor), + sources = descriptor.createSources(), visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, @@ -138,7 +138,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), - actual = descriptor.actual(platformData, descriptor), + sources = descriptor.createSources(), visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), supertypes = PlatformDependent.from(platformData, info.supertypes), documentation = info.docs, @@ -166,7 +166,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val info = descriptor.resolveClassDescriptionData(platformData) - val actual = descriptor.actual(platformData, descriptor) + val actual = descriptor.createSources() return Class( dri = driWithPlatform.dri, @@ -181,7 +181,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), - actual = actual, + sources = actual, visibility = PlatformDependent.from(platformData, descriptor.visibility), generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, documentation = info.docs, @@ -195,14 +195,14 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, parent: DRIWithPlatformInfo): Property { val dri = parent.dri.copy(callable = Callable.from(descriptor)) - val actual = descriptor.actual(platformData, descriptor) + val actual = descriptor.createSources() return Property( dri = dri, name = descriptor.name.asString(), receiver = descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor(it, DRIWithPlatformInfo(dri, actual)) }, - actual = actual, + sources = actual, getter = descriptor.accessors.filterIsInstance<PropertyGetterDescriptor>().singleOrNull()?.let { visitPropertyAccessorDescriptor(it, descriptor, dri) }!!, @@ -220,7 +220,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, parent: DRIWithPlatformInfo): Function { val dri = parent.dri.copy(callable = Callable.from(descriptor)) - val actual = descriptor.actual(platformData, descriptor) + val actual = descriptor.createSources() return Function( dri = dri, name = descriptor.name.asString(), @@ -231,7 +231,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private parameters = descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, - actual = actual, + sources = actual, visibility = PlatformDependent.from(platformData, descriptor.visibility), generics = descriptor.typeParameters.map { it.toTypeParameter() }, documentation = descriptor.resolveDescriptorData(platformData), @@ -243,7 +243,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, parent: DRIWithPlatformInfo): Function { val dri = parent.dri.copy(callable = Callable.from(descriptor)) - val actual = descriptor.actual(platformData, descriptor) + val actual = descriptor.createSources() return Function( dri = dri, name = "<init>", @@ -254,7 +254,7 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private parameters = descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, - actual = actual, + sources = actual, visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)), documentation = descriptor.resolveDescriptorData(platformData), type = KotlinTypeWrapper(descriptor.returnType), @@ -318,10 +318,10 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private receiver = descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor( it, - DRIWithPlatformInfo(dri, descriptor.actual(platformData, descriptor)) + DRIWithPlatformInfo(dri, descriptor.createSources()) ) }, - actual = descriptor.actual(platformData, descriptor), + sources = descriptor.createSources(), platformData = listOf(platformData) ) } @@ -413,10 +413,11 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private else -> WithAbstraction.Modifier.Empty } - fun MemberDescriptor.actual(platformData: PlatformData, expected: DeclarationDescriptor? = null) = - this.takeIf { it.isActual }?.let { DescriptorDocumentableSource(it) }?.let { - PlatformDependent(mapOf(platformData to it), expected?.let { DescriptorDocumentableSource(it) }) - }.orEmpty() + private fun MemberDescriptor.createSources(): PlatformDependent<DocumentableSource> = if(isExpect()) { + PlatformDependent(emptyMap(), DescriptorDocumentableSource(this)) + } else { + PlatformDependent(mapOf(platformData to DescriptorDocumentableSource(this))) + } data class ClassInfo(val supertypes: List<DRI>, val docs: PlatformDependent<DocumentationNode>) } |