diff options
3 files changed, 31 insertions, 24 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)]) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt index 2528b5f0..c901c9aa 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.transformers.documentables import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer +import org.jetbrains.dokka.transformers.documentation.sourceSet class EmptyPackagesFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { override fun invoke(modules: List<DModule>): List<DModule> { @@ -11,7 +12,7 @@ class EmptyPackagesFilterTransformer(val context: DokkaContext) : PreMergeDocume private fun filterModule(module: DModule): DModule? { val nonEmptyPackages = module.packages.filterNot { pkg -> - pkg.sourceSet.skipEmptyPackages && pkg.children.isEmpty() + sourceSet(pkg).skipEmptyPackages && pkg.children.isEmpty() } return when { diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt index f329e9ce..5a2818c7 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt @@ -1,10 +1,11 @@ package org.jetbrains.dokka.base.transformers.documentables -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer +import org.jetbrains.dokka.transformers.documentation.perPackageOptions +import org.jetbrains.dokka.transformers.documentation.source +import org.jetbrains.dokka.transformers.documentation.sourceSet import java.io.File class SuppressedDocumentableFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { @@ -22,7 +23,7 @@ class SuppressedDocumentableFilterTransformer(val context: DokkaContext) : PreMe } private fun filterPackage(pkg: DPackage): DPackage? { - val options = pkg.perPackageOptions + val options = perPackageOptions(pkg) if (options?.suppress == true) { return null } @@ -42,10 +43,9 @@ class SuppressedDocumentableFilterTransformer(val context: DokkaContext) : PreMe private fun isSuppressed(documentable: Documentable): Boolean { if (documentable !is WithExpectActual) return false - val sourceFile = File(documentable.source.path).absoluteFile - return documentable.sourceSet.suppressedFiles.any { suppressedFile -> + val sourceFile = File(source(documentable).path).absoluteFile + return sourceSet(documentable).suppressedFiles.any { suppressedFile -> sourceFile.startsWith(File(suppressedFile).absoluteFile) } } - } |