aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-12 08:19:26 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-08-12 09:38:06 +0200
commite783eefe0c3b124aa25fdb2b28b9f238d48e293b (patch)
tree0e09fad2c43c91cba40b8be2e0f62abab3d88347 /core
parentbbe5b00387da8fb8a54f8a8ecd80f2f2dea06830 (diff)
downloaddokka-e783eefe0c3b124aa25fdb2b28b9f238d48e293b.tar.gz
dokka-e783eefe0c3b124aa25fdb2b28b9f238d48e293b.tar.bz2
dokka-e783eefe0c3b124aa25fdb2b28b9f238d48e293b.zip
Move PreMergeDocumentableTransformer utils out of the interface
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt40
1 files changed, 23 insertions, 17 deletions
diff --git a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt
index dfc7319f..df568c7e 100644
--- a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt
+++ b/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt
@@ -1,30 +1,36 @@
package org.jetbrains.dokka.transformers.documentation
-import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
+import org.jetbrains.dokka.DokkaConfiguration.PackageOptions
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.DocumentableSource
import org.jetbrains.dokka.model.WithExpectActual
interface PreMergeDocumentableTransformer {
operator fun invoke(modules: List<DModule>): List<DModule>
+}
- /* Convenience functions */
- /**
- * A [PreMergeDocumentableTransformer] can safely assume that documentables are not merged and therefore
- * only belong to a single source set
- */
- val Documentable.sourceSet: DokkaSourceSet get() = sourceSets.single()
+/* Utils */
- val Documentable.perPackageOptions: DokkaConfiguration.PackageOptions?
- get() {
- val packageName = dri.packageName ?: return null
- return sourceSet.perPackageOptions
- .sortedByDescending { packageOptions -> packageOptions.prefix.length }
- .firstOrNull { packageOptions -> packageName.startsWith(packageOptions.prefix) }
- }
+/**
+ * It is fair to assume that a given [Documentable] is not merged when seen by the [PreMergeDocumentableTransformer].
+ * Therefore, it can also be assumed, that there is just a single source set connected to the given [documentable]
+ * @return the single source set associated with this [documentable].
+ */
+@Suppress("unused") // Receiver is used for scoping this function
+fun PreMergeDocumentableTransformer.sourceSet(documentable: Documentable): DokkaSourceSet {
+ return documentable.sourceSets.single()
+}
- val <T> T.source: DocumentableSource where T : Documentable, T : WithExpectActual
- get() = checkNotNull(sources[sourceSet])
+/**
+ * @return The [PackageOptions] associated with this documentable, or null
+ */
+fun PreMergeDocumentableTransformer.perPackageOptions(documentable: Documentable): PackageOptions? {
+ val packageName = documentable.dri.packageName ?: return null
+ return sourceSet(documentable).perPackageOptions
+ .sortedByDescending { packageOptions -> packageOptions.prefix.length }
+ .firstOrNull { packageOptions -> packageName.startsWith(packageOptions.prefix) }
}
+
+fun <T> PreMergeDocumentableTransformer.source(documentable: T) where T : Documentable, T : WithExpectActual =
+ checkNotNull(documentable.sources[sourceSet(documentable)])