aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-11 12:52:43 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-08-12 09:38:06 +0200
commitbbe5b00387da8fb8a54f8a8ecd80f2f2dea06830 (patch)
tree193349416ab229be3aafe6b9801c1afe66b8b116 /plugins/base/src
parent6a7d1c9aedfb12f309a410c404a830cb9d3972d3 (diff)
downloaddokka-bbe5b00387da8fb8a54f8a8ecd80f2f2dea06830.tar.gz
dokka-bbe5b00387da8fb8a54f8a8ecd80f2f2dea06830.tar.bz2
dokka-bbe5b00387da8fb8a54f8a8ecd80f2f2dea06830.zip
Move utility APIs into `PreMergeDocumentationTransformer`
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt27
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt17
-rw-r--r--plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt10
3 files changed, 17 insertions, 37 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt
index 61abfbd7..2528b5f0 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt
@@ -1,28 +1,23 @@
package org.jetbrains.dokka.base.transformers.documentables
-import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.model.DPackage
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
class EmptyPackagesFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> = modules.map { original ->
- original.let {
- EmptyPackagesFilter(original.sourceSets.single()).processModule(it)
- }
+ override fun invoke(modules: List<DModule>): List<DModule> {
+ return modules.mapNotNull { module -> filterModule(module) }
}
- private class EmptyPackagesFilter(
- val sourceSet: DokkaConfiguration.DokkaSourceSet
- ) {
- fun DPackage.shouldBeSkipped() = sourceSet.skipEmptyPackages &&
- functions.isEmpty() &&
- properties.isEmpty() &&
- classlikes.isEmpty()
+ private fun filterModule(module: DModule): DModule? {
+ val nonEmptyPackages = module.packages.filterNot { pkg ->
+ pkg.sourceSet.skipEmptyPackages && pkg.children.isEmpty()
+ }
- fun processModule(module: DModule) = module.copy(
- packages = module.packages.filter { !it.shouldBeSkipped() }
- )
+ return when {
+ nonEmptyPackages == module.packages -> module
+ nonEmptyPackages.isEmpty() -> null
+ else -> module.copy(packages = nonEmptyPackages)
+ }
}
}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt
index e7a2bf25..f329e9ce 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedDocumentableFilterTransformer.kt
@@ -48,21 +48,4 @@ class SuppressedDocumentableFilterTransformer(val context: DokkaContext) : PreMe
}
}
- /**
- * A [PreMergeDocumentableTransformer] can safely assume that documentables are not merged and therefore
- * only belong to a single source set
- */
- private val Documentable.sourceSet: DokkaSourceSet get() = sourceSets.single()
-
- private 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) }
- }
-
- private val <T> T.source: DocumentableSource where T : Documentable, T : WithExpectActual
- get() = checkNotNull(sources[sourceSet])
-
}
diff --git a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt
index e5b9e9c2..19bbc164 100644
--- a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt
+++ b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt
@@ -53,10 +53,12 @@ class EmptyPackagesFilterTest : AbstractCoreTest() {
""".trimMargin(),
configuration
) {
- documentablesFirstTransformationStep = {
- Assertions.assertTrue(
- it.component2().packages.isEmpty()
- )
+ documentablesFirstTransformationStep = { modules ->
+ modules.forEach { module ->
+ Assertions.assertTrue(
+ module.packages.isEmpty()
+ )
+ }
}
}
}