From f861b3738a75a5acc112d98b760bd1ada1023882 Mon Sep 17 00:00:00 2001 From: Filip ZybaƂa Date: Wed, 13 May 2020 16:05:42 +0200 Subject: Added support for includeNonPublic option in top-level and package-level. Added tests for it. --- .../documentables/DocumentableVisibilityFilter.kt | 19 ++- .../test/kotlin/visibility/VisibilityFilterTest.kt | 173 +++++++++++++++++++++ 2 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 plugins/base/src/test/kotlin/visibility/VisibilityFilterTest.kt (limited to 'plugins') diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt index d3fc65fb..66c917c5 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt @@ -14,17 +14,25 @@ internal class DocumentableVisibilityFilter(val context: DokkaContext) : PreMerg val packageOptions = context.configuration.passesConfigurations.first { original.sourceSets.contains(context.sourceSet(it)) } .perPackageOptions + val passOptions = context.configuration.passesConfigurations.first { + original.platformData.contains(it.platformData) + } - DocumentableFilter(packageOptions).processModule(original) + DocumentableFilter(packageOptions, passOptions).processModule(original) } - private class DocumentableFilter(val packageOptions: List) { + private class DocumentableFilter( + val packageOptions: List, + val globalOptions: DokkaConfiguration.PassConfiguration + ) { fun Visibility.isAllowedInPackage(packageName: String?) = when (this) { is JavaVisibility.Public, is JavaVisibility.Default, is KotlinVisibility.Public -> true - else -> packageName != null && packageOptions.firstOrNull { packageName.startsWith(it.prefix) }?.includeNonPublic == true + else -> packageName != null + && packageOptions.firstOrNull { packageName.startsWith(it.prefix) }?.includeNonPublic + ?: globalOptions.includeNonPublic } fun processModule(original: DModule) = @@ -58,7 +66,10 @@ internal class DocumentableVisibilityFilter(val context: DokkaContext) : PreMerg } when { !modified -> it - functions.isEmpty() && properties.isEmpty() && classlikes.isEmpty() -> null + functions.isEmpty() && properties.isEmpty() && classlikes.isEmpty() -> { + packagesListChanged = true + null + } else -> { packagesListChanged = true DPackage( diff --git a/plugins/base/src/test/kotlin/visibility/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/visibility/VisibilityFilterTest.kt new file mode 100644 index 00000000..1ce567c6 --- /dev/null +++ b/plugins/base/src/test/kotlin/visibility/VisibilityFilterTest.kt @@ -0,0 +1,173 @@ +package visibility + +import org.jetbrains.dokka.PackageOptionsImpl +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class VisibilityFilterTest : AbstractCoreTest() { + @Test + fun `public function with false global includeNonPublic`() { + val configuration = dokkaConfiguration { + passes { + pass { + includeNonPublic = false + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |fun testFunction() { } + | + | + | + """.trimMargin(), + configuration + ) { + documentablesFirstTransformationStep = { + Assertions.assertTrue( + it.component2().packages.first().functions.size == 1 + ) + } + } + } + @Test + fun `private function with false global includeNonPublic`() { + val configuration = dokkaConfiguration { + passes { + pass { + includeNonPublic = false + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |private fun testFunction() { } + | + | + | + """.trimMargin(), + configuration + ) { + documentablesFirstTransformationStep = { + Assertions.assertTrue( + it.component2().packages.isEmpty() + ) + } + } + } + @Test + fun `private function with true global includeNonPublic`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + includeNonPublic = true + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |private fun testFunction() { } + | + | + | + """.trimMargin(), + configuration + ) { + documentablesFirstTransformationStep = { + Assertions.assertTrue( + it.component2().packages.first().functions.size == 1 + ) + } + } + } + @Test + fun `private function with false global true package includeNonPublic`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + includeNonPublic = false + perPackageOptions = mutableListOf( + PackageOptionsImpl("example", + true, + false, + false, + false) + ) + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |private fun testFunction() { } + | + | + | + """.trimMargin(), + configuration + ) { + documentablesFirstTransformationStep = { + Assertions.assertTrue( + it.component2().packages.first().functions.size == 1 + ) + } + } + } + @Test + fun `private function with true global false package includeNonPublic`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + includeNonPublic = true + perPackageOptions = mutableListOf( + PackageOptionsImpl("example", + false, + false, + false, + false) + ) + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |private fun testFunction() { } + | + | + | + """.trimMargin(), + configuration + ) { + documentablesFirstTransformationStep = { + Assertions.assertTrue( + it.component2().packages.isEmpty() + ) + } + } + } +} \ No newline at end of file -- cgit