aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/model/Documentable.kt
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-05-05 17:45:12 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-14 13:30:33 +0200
commit3f2a790190da4f40ea6d8a976aa1929b2a1b002b (patch)
tree752ee84451954e9ea5e6d4133e18e41aaee2f7b1 /core/src/main/kotlin/model/Documentable.kt
parenta440f0cb8756019131a2c15389e747aea3c585e7 (diff)
downloaddokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.gz
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.bz2
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.zip
Changing approach from platform-driven to source-set-driven
Diffstat (limited to 'core/src/main/kotlin/model/Documentable.kt')
-rw-r--r--core/src/main/kotlin/model/Documentable.kt168
1 files changed, 74 insertions, 94 deletions
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<Documentable>
- abstract val documentation: PlatformDependent<DocumentationNode>
- abstract val platformData: List<PlatformData>
+ abstract val documentation: SourceSetDependent<DocumentationNode>
+ abstract val sourceSets: List<SourceSetData>
+ 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<out T>(
- val map: Map<PlatformData, T>,
- val expect: T? = null
-) : Map<PlatformData, T> by map {
- val prevalentValue: T?
- get() = map.values.distinct().singleOrNull()
-
- val allValues: Sequence<T> = sequence {
- expect?.also { yield(it) }
- yieldAll(map.values)
- }
-
- val allEntries: Sequence<Pair<PlatformData?, T>> = 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 <T> empty(): PlatformDependent<T> = PlatformDependent(emptyMap())
-
- fun <T> from(platformData: PlatformData, element: T) = PlatformDependent(mapOf(platformData to element))
-
- @Suppress("UNCHECKED_CAST")
- fun <T> from(pairs: Iterable<Pair<PlatformData?, T>>) =
- PlatformDependent(
- pairs.filter { it.first != null }.toMap() as Map<PlatformData, T>,
- pairs.firstOrNull { it.first == null }?.second
- )
-
- fun <T> from(vararg pairs: Pair<PlatformData?, T>) = from(pairs.asIterable())
-
- fun <T> expectFrom(element: T) = PlatformDependent(map = emptyMap(), expect = element)
- }
-}
+typealias SourceSetDependent<T> = Map<SourceSetData, T>
interface WithExpectActual {
- val sources: PlatformDependent<DocumentableSource>
+ val sources: SourceSetDependent<DocumentableSource>
}
interface WithScope {
@@ -73,7 +40,7 @@ interface WithScope {
}
interface WithVisibility {
- val visibility: PlatformDependent<Visibility>
+ val visibility: SourceSetDependent<Visibility>
}
interface WithType {
@@ -81,7 +48,7 @@ interface WithType {
}
interface WithAbstraction {
- val modifier: PlatformDependent<Modifier>
+ val modifier: SourceSetDependent<Modifier>
}
sealed class Modifier(val name: String)
@@ -112,7 +79,7 @@ interface WithGenerics {
}
interface WithSupertypes {
- val supertypes: PlatformDependent<List<DRI>>
+ val supertypes: SourceSetDependent<List<DRI>>
}
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<DPackage>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val platformData: List<PlatformData>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData? = null,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DModule> = PropertyContainer.empty()
) : Documentable(), WithExtraProperties<DModule> {
override val dri: DRI = DRI.topLevel
@@ -141,8 +109,9 @@ data class DPackage(
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
val typealiases: List<DTypeAlias>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val platformData: List<PlatformData>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData? = null,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DPackage> = PropertyContainer.empty()
) : Documentable(), WithScope, WithExtraProperties<DPackage> {
override val name = dri.packageName.orEmpty()
@@ -159,14 +128,15 @@ data class DClass(
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val sources: PlatformDependent<DocumentableSource>,
- override val visibility: PlatformDependent<Visibility>,
+ override val sources: SourceSetDependent<DocumentableSource>,
+ override val visibility: SourceSetDependent<Visibility>,
override val companion: DObject?,
override val generics: List<DTypeParameter>,
- override val supertypes: PlatformDependent<List<DRI>>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val modifier: PlatformDependent<Modifier>,
- override val platformData: List<PlatformData>,
+ override val supertypes: SourceSetDependent<List<DRI>>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val modifier: SourceSetDependent<Modifier>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DClass> = PropertyContainer.empty()
) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes,
WithExtraProperties<DClass> {
@@ -181,16 +151,17 @@ data class DEnum(
override val dri: DRI,
override val name: String,
val entries: List<DEnumEntry>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val visibility: PlatformDependent<Visibility>,
+ override val visibility: SourceSetDependent<Visibility>,
override val companion: DObject?,
override val constructors: List<DFunction>,
- override val supertypes: PlatformDependent<List<DRI>>,
- override val platformData: List<PlatformData>,
+ override val supertypes: SourceSetDependent<List<DRI>>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DEnum> = PropertyContainer.empty()
) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties<DEnum> {
override val children: List<Documentable>
@@ -202,11 +173,12 @@ data class DEnum(
data class DEnumEntry(
override val dri: DRI,
override val name: String,
- override val documentation: PlatformDependent<DocumentationNode>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val platformData: List<PlatformData>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DEnumEntry> = PropertyContainer.empty()
) : Documentable(), WithScope, WithExtraProperties<DEnumEntry> {
override val children: List<Documentable>
@@ -220,14 +192,15 @@ data class DFunction(
override val name: String,
val isConstructor: Boolean,
val parameters: List<DParameter>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
- override val visibility: PlatformDependent<Visibility>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
+ override val visibility: SourceSetDependent<Visibility>,
override val type: Bound,
override val generics: List<DTypeParameter>,
override val receiver: DParameter?,
- override val modifier: PlatformDependent<Modifier>,
- override val platformData: List<PlatformData>,
+ override val modifier: SourceSetDependent<Modifier>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DFunction> = PropertyContainer.empty()
) : Documentable(), Callable, WithGenerics, WithExtraProperties<DFunction> {
override val children: List<Documentable>
@@ -239,16 +212,17 @@ data class DFunction(
data class DInterface(
override val dri: DRI,
override val name: String,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val visibility: PlatformDependent<Visibility>,
+ override val visibility: SourceSetDependent<Visibility>,
override val companion: DObject?,
override val generics: List<DTypeParameter>,
- override val supertypes: PlatformDependent<List<DRI>>,
- override val platformData: List<PlatformData>,
+ override val supertypes: SourceSetDependent<List<DRI>>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DInterface> = PropertyContainer.empty()
) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties<DInterface> {
override val children: List<Documentable>
@@ -260,14 +234,15 @@ data class DInterface(
data class DObject(
override val name: String?,
override val dri: DRI,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val visibility: PlatformDependent<Visibility>,
- override val supertypes: PlatformDependent<List<DRI>>,
- override val platformData: List<PlatformData>,
+ override val visibility: SourceSetDependent<Visibility>,
+ override val supertypes: SourceSetDependent<List<DRI>>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DObject> = PropertyContainer.empty()
) : DClasslike(), WithSupertypes, WithExtraProperties<DObject> {
override val children: List<Documentable>
@@ -279,15 +254,16 @@ data class DObject(
data class DAnnotation(
override val name: String,
override val dri: DRI,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
override val functions: List<DFunction>,
override val properties: List<DProperty>,
override val classlikes: List<DClasslike>,
- override val visibility: PlatformDependent<Visibility>,
+ override val visibility: SourceSetDependent<Visibility>,
override val companion: DObject?,
override val constructors: List<DFunction>,
- override val platformData: List<PlatformData>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DAnnotation> = PropertyContainer.empty()
) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties<DAnnotation> {
override val children: List<Documentable>
@@ -299,15 +275,16 @@ data class DAnnotation(
data class DProperty(
override val dri: DRI,
override val name: String,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val sources: PlatformDependent<DocumentableSource>,
- override val visibility: PlatformDependent<Visibility>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sources: SourceSetDependent<DocumentableSource>,
+ override val visibility: SourceSetDependent<Visibility>,
override val type: Bound,
override val receiver: DParameter?,
val setter: DFunction?,
val getter: DFunction?,
- override val modifier: PlatformDependent<Modifier>,
- override val platformData: List<PlatformData>,
+ override val modifier: SourceSetDependent<Modifier>,
+ override val sourceSets: List<SourceSetData>,
override val generics: List<DTypeParameter>,
override val extra: PropertyContainer<DProperty> = PropertyContainer.empty()
) : Documentable(), Callable, WithExtraProperties<DProperty>, WithGenerics {
@@ -321,9 +298,10 @@ data class DProperty(
data class DParameter(
override val dri: DRI,
override val name: String?,
- override val documentation: PlatformDependent<DocumentationNode>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
val type: Bound,
- override val platformData: List<PlatformData>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DParameter> = PropertyContainer.empty()
) : Documentable(), WithExtraProperties<DParameter> {
override val children: List<Nothing>
@@ -335,9 +313,10 @@ data class DParameter(
data class DTypeParameter(
override val dri: DRI,
override val name: String,
- override val documentation: PlatformDependent<DocumentationNode>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
val bounds: List<Bound>,
- override val platformData: List<PlatformData>,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DTypeParameter> = PropertyContainer.empty()
) : Documentable(), WithExtraProperties<DTypeParameter> {
override val children: List<Nothing>
@@ -350,10 +329,11 @@ data class DTypeAlias(
override val dri: DRI,
override val name: String,
override val type: Bound,
- val underlyingType: PlatformDependent<Bound>,
- override val visibility: PlatformDependent<Visibility>,
- override val documentation: PlatformDependent<DocumentationNode>,
- override val platformData: List<PlatformData>,
+ val underlyingType: SourceSetDependent<Bound>,
+ override val visibility: SourceSetDependent<Visibility>,
+ override val documentation: SourceSetDependent<DocumentationNode>,
+ override val expectPresentInSet: SourceSetData?,
+ override val sourceSets: List<SourceSetData>,
override val extra: PropertyContainer<DTypeAlias> = PropertyContainer.empty()
) : Documentable(), WithType, WithVisibility, WithExtraProperties<DTypeAlias> {
override val children: List<Nothing>
@@ -417,7 +397,7 @@ sealed class JavaVisibility(name: String) : Visibility(name) {
object Default : JavaVisibility("")
}
-fun <T> PlatformDependent<T>?.orEmpty(): PlatformDependent<T> = this ?: PlatformDependent.empty()
+fun <T> SourceSetDependent<T>?.orEmpty(): SourceSetDependent<T> = 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