From 3f2a790190da4f40ea6d8a976aa1929b2a1b002b Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 May 2020 17:45:12 +0200 Subject: Changing approach from platform-driven to source-set-driven --- core/src/main/kotlin/model/Documentable.kt | 168 +++++++++++++---------------- 1 file changed, 74 insertions(+), 94 deletions(-) (limited to 'core/src/main/kotlin/model/Documentable.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 313f4cd4..85487725 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,11 +1,12 @@ package org.jetbrains.dokka.model import com.intellij.psi.PsiNamedElement +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.load.kotlin.toSourceElement @@ -13,8 +14,9 @@ abstract class Documentable { abstract val name: String? abstract val dri: DRI abstract val children: List - abstract val documentation: PlatformDependent - abstract val platformData: List + abstract val documentation: SourceSetDependent + abstract val sourceSets: List + abstract val expectPresentInSet: SourceSetData? override fun toString(): String = "${javaClass.simpleName}($dri)" @@ -25,45 +27,10 @@ abstract class Documentable { override fun hashCode() = dri.hashCode() } -data class PlatformDependent( - val map: Map, - val expect: T? = null -) : Map by map { - val prevalentValue: T? - get() = map.values.distinct().singleOrNull() - - val allValues: Sequence = sequence { - expect?.also { yield(it) } - yieldAll(map.values) - } - - val allEntries: Sequence> = sequence { - expect?.also { yield(null to it) } - map.forEach { (k, v) -> yield(k to v) } - } - - fun getOrExpect(platform: PlatformData): T? = map[platform] ?: expect - - companion object { - fun empty(): PlatformDependent = PlatformDependent(emptyMap()) - - fun from(platformData: PlatformData, element: T) = PlatformDependent(mapOf(platformData to element)) - - @Suppress("UNCHECKED_CAST") - fun from(pairs: Iterable>) = - PlatformDependent( - pairs.filter { it.first != null }.toMap() as Map, - pairs.firstOrNull { it.first == null }?.second - ) - - fun from(vararg pairs: Pair) = from(pairs.asIterable()) - - fun expectFrom(element: T) = PlatformDependent(map = emptyMap(), expect = element) - } -} +typealias SourceSetDependent = Map interface WithExpectActual { - val sources: PlatformDependent + val sources: SourceSetDependent } interface WithScope { @@ -73,7 +40,7 @@ interface WithScope { } interface WithVisibility { - val visibility: PlatformDependent + val visibility: SourceSetDependent } interface WithType { @@ -81,7 +48,7 @@ interface WithType { } interface WithAbstraction { - val modifier: PlatformDependent + val modifier: SourceSetDependent } sealed class Modifier(val name: String) @@ -112,7 +79,7 @@ interface WithGenerics { } interface WithSupertypes { - val supertypes: PlatformDependent> + val supertypes: SourceSetDependent> } interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual { @@ -124,8 +91,9 @@ sealed class DClasslike : Documentable(), WithScope, WithVisibility, WithExpectA data class DModule( override val name: String, val packages: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val dri: DRI = DRI.topLevel @@ -141,8 +109,9 @@ data class DPackage( override val properties: List, override val classlikes: List, val typealiases: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() @@ -159,14 +128,15 @@ data class DClass( override val functions: List, override val properties: List, override val classlikes: List, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val documentation: PlatformDependent, - override val modifier: PlatformDependent, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, WithExtraProperties { @@ -181,16 +151,17 @@ data class DEnum( override val dri: DRI, override val name: String, val entries: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { override val children: List @@ -202,11 +173,12 @@ data class DEnum( data class DEnumEntry( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, override val functions: List, override val properties: List, override val classlikes: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val children: List @@ -220,14 +192,15 @@ data class DFunction( override val name: String, val isConstructor: Boolean, val parameters: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val generics: List, override val receiver: DParameter?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { override val children: List @@ -239,16 +212,17 @@ data class DFunction( data class DInterface( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { override val children: List @@ -260,14 +234,15 @@ data class DInterface( data class DObject( override val name: String?, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val visibility: SourceSetDependent, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithSupertypes, WithExtraProperties { override val children: List @@ -279,15 +254,16 @@ data class DObject( data class DAnnotation( override val name: String, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties { override val children: List @@ -299,15 +275,16 @@ data class DAnnotation( data class DProperty( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val receiver: DParameter?, val setter: DFunction?, val getter: DFunction?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val generics: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties, WithGenerics { @@ -321,9 +298,10 @@ data class DProperty( data class DParameter( override val dri: DRI, override val name: String?, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val type: Bound, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -335,9 +313,10 @@ data class DParameter( data class DTypeParameter( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val bounds: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -350,10 +329,11 @@ data class DTypeAlias( override val dri: DRI, override val name: String, override val type: Bound, - val underlyingType: PlatformDependent, - override val visibility: PlatformDependent, - override val documentation: PlatformDependent, - override val platformData: List, + val underlyingType: SourceSetDependent, + override val visibility: SourceSetDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithType, WithVisibility, WithExtraProperties { override val children: List @@ -417,7 +397,7 @@ sealed class JavaVisibility(name: String) : Visibility(name) { object Default : JavaVisibility("") } -fun PlatformDependent?.orEmpty(): PlatformDependent = this ?: PlatformDependent.empty() +fun SourceSetDependent?.orEmpty(): SourceSetDependent = this ?: emptyMap() interface DocumentableSource { val path: String @@ -429,4 +409,4 @@ class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : Docu class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource { override val path = psi.containingFile.virtualFile.path -} +} \ No newline at end of file -- cgit