aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/pages
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-13 09:59:39 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-17 11:52:28 +0200
commitf6ac2b0f0a0183171aa2f6806ec67d8d21692a36 (patch)
treea912d7ba4d7d368b9a3683a6cf290ca135ee231a /core/src/main/kotlin/pages
parent86fcfb73d2d5124ae7748a80db29bdbb68607be4 (diff)
downloaddokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.tar.gz
dokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.tar.bz2
dokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.zip
Implement `ContentSourceSet`
Diffstat (limited to 'core/src/main/kotlin/pages')
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt45
-rw-r--r--core/src/main/kotlin/pages/ContentSourceSet.kt61
-rw-r--r--core/src/main/kotlin/pages/PageNodes.kt15
3 files changed, 98 insertions, 23 deletions
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index 5129dfcf..b82c023f 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -1,6 +1,8 @@
package org.jetbrains.dokka.pages
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.WithChildren
import org.jetbrains.dokka.model.properties.PropertyContainer
@@ -10,9 +12,10 @@ data class DCI(val dri: Set<DRI>, val kind: Kind) {
override fun toString() = "$dri[$kind]"
}
+
interface ContentNode : WithExtraProperties<ContentNode>, WithChildren<ContentNode> {
val dci: DCI
- val sourceSets: Set<DokkaSourceSet>
+ val sourceSets: Set<ContentSourceSet>
val style: Set<Style>
fun hasAnyContent(): Boolean
@@ -25,7 +28,7 @@ interface ContentNode : WithExtraProperties<ContentNode>, WithChildren<ContentNo
data class ContentText(
val text: String,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentNode {
@@ -36,7 +39,7 @@ data class ContentText(
// TODO: Remove
data class ContentBreakLine(
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val dci: DCI = DCI(emptySet(), ContentKind.Empty),
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
@@ -51,7 +54,7 @@ data class ContentHeader(
override val children: List<ContentNode>,
val level: Int,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
@@ -67,7 +70,7 @@ data class ContentCodeBlock(
override val children: List<ContentNode>,
val language: String,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentCode {
@@ -78,7 +81,7 @@ data class ContentCodeInline(
override val children: List<ContentNode>,
val language: String,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentCode {
@@ -93,7 +96,7 @@ data class ContentDRILink(
override val children: List<ContentNode>,
val address: DRI,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentLink {
@@ -105,7 +108,7 @@ data class ContentResolvedLink(
override val children: List<ContentNode>,
val address: String,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentLink {
@@ -119,7 +122,7 @@ data class ContentEmbeddedResource(
val address: String,
val altText: String?,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style> = emptySet(),
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentLink {
@@ -139,7 +142,7 @@ data class ContentTable(
val header: List<ContentGroup>,
override val children: List<ContentGroup>,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
@@ -151,7 +154,7 @@ data class ContentList(
override val children: List<ContentNode>,
val ordered: Boolean,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
@@ -162,7 +165,7 @@ data class ContentList(
data class ContentGroup(
override val children: List<ContentNode>,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
@@ -182,7 +185,7 @@ data class ContentDivergentGroup(
) : ContentComposite {
data class GroupID(val name: String)
- override val sourceSets: Set<DokkaSourceSet>
+ override val sourceSets: Set<ContentSourceSet>
get() = children.flatMap { it.sourceSets }.distinct().toSet()
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentGroup =
@@ -195,7 +198,7 @@ data class ContentDivergentInstance(
val divergent: ContentNode,
val after: ContentNode?,
override val dci: DCI,
- override val sourceSets: Set<DokkaSourceSet>,
+ override val sourceSets: Set<ContentSourceSet>,
override val style: Set<Style>,
override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty()
) : ContentComposite {
@@ -208,7 +211,7 @@ data class ContentDivergentInstance(
data class PlatformHintedContent(
val inner: ContentNode,
- override val sourceSets: Set<DokkaSourceSet>
+ override val sourceSets: Set<ContentSourceSet>
) : ContentComposite {
override val children = listOf(inner)
@@ -235,7 +238,17 @@ enum class ContentKind : Kind {
companion object {
private val platformTagged =
- setOf(Constructors, Functions, Properties, Classlikes, Packages, Source, TypeAliases, Inheritors, Extensions)
+ setOf(
+ Constructors,
+ Functions,
+ Properties,
+ Classlikes,
+ Packages,
+ Source,
+ TypeAliases,
+ Inheritors,
+ Extensions
+ )
fun shouldBePlatformTagged(kind: Kind): Boolean = kind in platformTagged
}
diff --git a/core/src/main/kotlin/pages/ContentSourceSet.kt b/core/src/main/kotlin/pages/ContentSourceSet.kt
new file mode 100644
index 00000000..0ff87edb
--- /dev/null
+++ b/core/src/main/kotlin/pages/ContentSourceSet.kt
@@ -0,0 +1,61 @@
+package org.jetbrains.dokka.pages
+
+import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.Platform
+
+
+data class ContentSourceSet(
+ val sourceSetIDs: CompositeSourceSetID,
+ val displayName: String,
+ val analysisPlatform: Platform
+) {
+ constructor(sourceSet: DokkaSourceSet) : this(
+ sourceSetIDs = CompositeSourceSetID(sourceSet.sourceSetID),
+ displayName = sourceSet.displayName,
+ analysisPlatform = sourceSet.analysisPlatform
+ )
+
+ operator fun contains(sourceSetID: DokkaSourceSetID): Boolean {
+ return sourceSetID in sourceSetIDs
+ }
+
+ operator fun contains(sourceSet: DokkaSourceSet): Boolean {
+ return sourceSet.sourceSetID in this
+ }
+}
+
+
+//TODO NOW: Test
+data class CompositeSourceSetID(
+ private val children: Set<DokkaSourceSetID>
+) {
+ constructor(sourceSetIDs: Iterable<DokkaSourceSetID>) : this(sourceSetIDs.toSet())
+ constructor(sourceSetId: DokkaSourceSetID) : this(setOf(sourceSetId))
+
+ init {
+ require(children.isNotEmpty()) { "Expected at least one source set id" }
+ }
+
+ val merged = DokkaSourceSetID(
+ moduleName = children.map { it.moduleName }.reduce { acc, s -> "$acc+$s" },
+ sourceSetName = children.map { it.sourceSetName }.reduce { acc, s -> "$acc+$s" }
+ )
+
+ val all: List<DokkaSourceSetID> = listOf(merged, *children.toTypedArray())
+
+ operator fun contains(sourceSetId: DokkaSourceSetID): Boolean {
+ return sourceSetId in all
+ }
+
+ operator fun contains(sourceSet: DokkaSourceSet): Boolean {
+ return sourceSet.sourceSetID in this
+ }
+}
+
+
+fun DokkaSourceSet.toContentSourceSet(): ContentSourceSet = ContentSourceSet(this)
+
+fun Iterable<DokkaSourceSet>.toContentSourceSets(): Set<ContentSourceSet> = map { it.toContentSourceSet() }.toSet()
+
+val Iterable<ContentSourceSet>.sourceSetIDs: List<DokkaSourceSetID> get() = this.flatMap { it.sourceSetIDs.all }
diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt
index 71ec8597..d49f9911 100644
--- a/core/src/main/kotlin/pages/PageNodes.kt
+++ b/core/src/main/kotlin/pages/PageNodes.kt
@@ -5,8 +5,9 @@ import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.model.WithChildren
import java.util.*
-interface PageNode: WithChildren<PageNode> {
+interface PageNode : WithChildren<PageNode> {
val name: String
+ override val children: List<PageNode>
fun modified(
name: String = this.name,
@@ -14,7 +15,7 @@ interface PageNode: WithChildren<PageNode> {
): PageNode
}
-interface ContentPage: PageNode {
+interface ContentPage : PageNode {
val content: ContentNode
val dri: Set<DRI>
val documentable: Documentable?
@@ -29,11 +30,11 @@ interface ContentPage: PageNode {
): ContentPage
}
-abstract class RootPageNode: PageNode {
+abstract class RootPageNode : PageNode {
val parentMap: Map<PageNode, PageNode> by lazy {
IdentityHashMap<PageNode, PageNode>().apply {
fun process(parent: PageNode) {
- parent.children.forEach { child ->
+ parent.children.forEach { child ->
put(child, parent)
process(child)
}
@@ -171,11 +172,11 @@ class MultimoduleRootPageNode(
embeddedResources: List<String>,
children: List<PageNode>
) =
- if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
- else MultimoduleRootPageNode(name, dri, content, embeddedResources)
+ if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
+ else MultimoduleRootPageNode(name, dri, content, embeddedResources)
}
-inline fun <reified T: PageNode> PageNode.children() = children.filterIsInstance<T>()
+inline fun <reified T : PageNode> PageNode.children() = children.filterIsInstance<T>()
private infix fun <T> List<T>.shallowEq(other: List<T>) =
this === other || (this.size == other.size && (this zip other).all { (a, b) -> a === b })