From bbe5b00387da8fb8a54f8a8ecd80f2f2dea06830 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 11 Aug 2020 12:52:43 +0200 Subject: Move utility APIs into `PreMergeDocumentationTransformer` --- core/src/main/kotlin/model/Documentable.kt | 2 +- .../PreMergeDocumentableTransformer.kt | 26 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 4f9732c0..3f91e3cb 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -113,7 +113,7 @@ data class DPackage( ) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() override val children: List - get() = (properties + functions + classlikes) + get() = (properties + functions + classlikes + typealiases) override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } diff --git a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt index b67a1d57..dfc7319f 100644 --- a/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt +++ b/core/src/main/kotlin/transformers/documentation/PreMergeDocumentableTransformer.kt @@ -1,8 +1,30 @@ package org.jetbrains.dokka.transformers.documentation +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.plugability.DokkaContext +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): List -} \ No newline at end of file + + /* 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() + + 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) } + } + + val T.source: DocumentableSource where T : Documentable, T : WithExpectActual + get() = checkNotNull(sources[sourceSet]) +} -- cgit