diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-13 09:59:39 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-17 11:52:28 +0200 |
commit | f6ac2b0f0a0183171aa2f6806ec67d8d21692a36 (patch) | |
tree | a912d7ba4d7d368b9a3683a6cf290ca135ee231a /core | |
parent | 86fcfb73d2d5124ae7748a80db29bdbb68607be4 (diff) | |
download | dokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.tar.gz dokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.tar.bz2 dokka-f6ac2b0f0a0183171aa2f6806ec67d8d21692a36.zip |
Implement `ContentSourceSet`
Diffstat (limited to 'core')
8 files changed, 233 insertions, 25 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 3f91e3cb..33c29ea3 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -14,6 +14,7 @@ abstract class Documentable : WithChildren<Documentable> { abstract val documentation: SourceSetDependent<DocumentationNode> abstract val sourceSets: Set<DokkaSourceSet> abstract val expectPresentInSet: DokkaSourceSet? + abstract override val children: List<Documentable> override fun toString(): String = "${javaClass.simpleName}($dri)" 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 }) diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt index 3eb4704e..d0570c7a 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt @@ -1,8 +1,9 @@ package org.jetbrains.dokka.transformers.documentation import org.jetbrains.dokka.model.DModule +import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.plugability.DokkaContext interface DocumentableTransformer { operator fun invoke(original: DModule, context: DokkaContext): DModule -}
\ No newline at end of file +} diff --git a/core/src/main/kotlin/transformers/pages/PageTransformer.kt b/core/src/main/kotlin/transformers/pages/PageTransformer.kt index 218d9821..086f6d22 100644 --- a/core/src/main/kotlin/transformers/pages/PageTransformer.kt +++ b/core/src/main/kotlin/transformers/pages/PageTransformer.kt @@ -1,7 +1,19 @@ package org.jetbrains.dokka.transformers.pages +import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.RootPageNode interface PageTransformer { operator fun invoke(input: RootPageNode): RootPageNode -}
\ No newline at end of file +} + +object SourceSetMergePageTransformer : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode { + + return input.transformContentPagesTree { contentPage -> + val content: ContentNode = contentPage.content + TODO() + } + } + +} diff --git a/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt b/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt new file mode 100644 index 00000000..68af259d --- /dev/null +++ b/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt @@ -0,0 +1,58 @@ +package model + +import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.dokka.pages.CompositeSourceSetID +import kotlin.test.* + +class CompositeSourceSetIDTest { + + @Test + fun `constructor fails with empty collection`() { + assertFailsWith<IllegalArgumentException>("Expected no construction of empty `CompositeSourceSetID`") { + CompositeSourceSetID(emptyList()) + } + } + + @Test + fun `merged for single source set`() { + val sourceSetID = DokkaSourceSetID("module", "sourceSet") + val composite = CompositeSourceSetID(sourceSetID) + + assertEquals( + composite.merged, sourceSetID, + "Expected merged source set id to be equal to single child" + ) + } + + @Test + fun `merged with multiple source sets`() { + val composite = CompositeSourceSetID( + listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"), DokkaSourceSetID("m3", "s3")) + ) + + assertEquals( + DokkaSourceSetID("m1+m2+m3", "s1+s2+s3"), composite.merged, + "Expected merged source set id to concatenate source sets" + ) + } + + @Test + fun `contains with child sourceSetID`() { + val composite = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"))) + + assertFalse( + DokkaSourceSetID("m3", "s3") in composite, + "Expected source set id not being contained in composite" + ) + + assertTrue( + DokkaSourceSetID("m1", "s1") in composite, + "Expected child source set id being contained in composite" + ) + + assertTrue( + DokkaSourceSetID("m1+m2", "s1+s2") in composite, + "Expected merged source set id being contained in composite" + ) + } +} diff --git a/core/src/test/kotlin/model/ContentSourceSetTest.kt b/core/src/test/kotlin/model/ContentSourceSetTest.kt new file mode 100644 index 00000000..cb17bcba --- /dev/null +++ b/core/src/test/kotlin/model/ContentSourceSetTest.kt @@ -0,0 +1,61 @@ +package model + +import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.pages.CompositeSourceSetID +import org.jetbrains.dokka.pages.ContentSourceSet +import org.jetbrains.dokka.pages.sourceSetIDs +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class ContentSourceSetTest { + @Test + fun `contains sourceSetId`() { + val contentSourceSet = ContentSourceSet( + sourceSetIDs = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"))), + displayName = "displayName", + analysisPlatform = Platform.common + ) + + assertFalse( + DokkaSourceSetID("m3", "s3") in contentSourceSet, + "Expected source set id not being contained in content source set" + ) + + assertTrue( + DokkaSourceSetID("m1", "s1") in contentSourceSet, + "Expected source set id being contained in content source set" + ) + + assertTrue( + DokkaSourceSetID("m1+m2", "s1+s2") in contentSourceSet, + "Expected merged source set being contained in content source set" + ) + } + + @Test + fun `Iterable contains sourceSetId`() { + + val contentSourceSet = ContentSourceSet( + sourceSetIDs = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"))), + displayName = "displayName", + analysisPlatform = Platform.common + ) + + assertFalse( + DokkaSourceSetID("m3", "s3") in listOf(contentSourceSet).sourceSetIDs, + "Expected source set id not being contained in content source set" + ) + + assertTrue( + DokkaSourceSetID("m1", "s1") in listOf(contentSourceSet).sourceSetIDs, + "Expected source set id being contained in content source set" + ) + + assertTrue( + DokkaSourceSetID("m1+m2", "s1+s2") in listOf(contentSourceSet).sourceSetIDs, + "Expected merged source set being contained in content source set" + ) + } +} |