From 6f40db680336e7f3b4b68a8d4ad7b8a7ffe33270 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 13 Aug 2020 19:39:05 +0200 Subject: Moving CompositeSourceSetID and ContentSourceSet into `.dokka.model` --- core/src/main/kotlin/model/CompositeSourceSetID.kt | 30 ++++++++++++++++++++ core/src/main/kotlin/model/ContentSourceSet.kt | 32 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 core/src/main/kotlin/model/CompositeSourceSetID.kt create mode 100644 core/src/main/kotlin/model/ContentSourceSet.kt (limited to 'core/src/main/kotlin/model') diff --git a/core/src/main/kotlin/model/CompositeSourceSetID.kt b/core/src/main/kotlin/model/CompositeSourceSetID.kt new file mode 100644 index 00000000..5eb106bf --- /dev/null +++ b/core/src/main/kotlin/model/CompositeSourceSetID.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka.model + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.DokkaSourceSetID + +data class CompositeSourceSetID( + private val children: Set +) { + constructor(sourceSetIDs: Iterable) : 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: Set = setOf(merged, *children.toTypedArray()) + + operator fun contains(sourceSetId: DokkaSourceSetID): Boolean { + return sourceSetId in all + } + + operator fun contains(sourceSet: DokkaConfiguration.DokkaSourceSet): Boolean { + return sourceSet.sourceSetID in this + } +} diff --git a/core/src/main/kotlin/model/ContentSourceSet.kt b/core/src/main/kotlin/model/ContentSourceSet.kt new file mode 100644 index 00000000..6eee4c94 --- /dev/null +++ b/core/src/main/kotlin/model/ContentSourceSet.kt @@ -0,0 +1,32 @@ +package org.jetbrains.dokka.model + +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 + } +} + + +fun DokkaSourceSet.toContentSourceSet(): ContentSourceSet = ContentSourceSet(this) + +fun Iterable.toContentSourceSets(): Set = map { it.toContentSourceSet() }.toSet() + +val Iterable.sourceSetIDs: List get() = this.flatMap { it.sourceSetIDs.all } -- cgit