aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-09-30 14:57:10 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-10-02 14:12:05 +0200
commit249556460973007de3d436ddda1df7d100aefab0 (patch)
tree5b5e05f761927f69488c80cf195643cbdae09c33 /plugins
parent8de5296b18083361055d11acf6d522c1eef821a4 (diff)
downloaddokka-249556460973007de3d436ddda1df7d100aefab0.tar.gz
dokka-249556460973007de3d436ddda1df7d100aefab0.tar.bz2
dokka-249556460973007de3d436ddda1df7d100aefab0.zip
Fix typealiases filtering when private
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt23
-rw-r--r--plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt52
2 files changed, 66 insertions, 9 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
index 9b024a0b..57faeefb 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
@@ -57,6 +57,10 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
modified = modified || listModified
list
}
+ val typeAliases = filterTypeAliases(it.typealiases).let { (listModified, list) ->
+ modified = modified || listModified
+ list
+ }
when {
!modified -> it
else -> {
@@ -66,7 +70,7 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
functions,
properties,
classlikes,
- it.typealiases,
+ typeAliases,
it.documentation,
it.expectPresentInSet,
it.sourceSets,
@@ -290,5 +294,22 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
}
return Pair(classlikesListChanged, filteredClasslikes)
}
+
+ private fun filterTypeAliases(
+ typeAliases: List<DTypeAlias>,
+ additionalCondition: (DTypeAlias, DokkaSourceSet) -> Boolean = ::alwaysTrue
+ ) =
+ typeAliases.transform(additionalCondition) { original, filteredPlatforms ->
+ with(original) {
+ copy(
+ documentation = documentation.filtered(filteredPlatforms),
+ expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
+ underlyingType = underlyingType.filtered(filteredPlatforms),
+ visibility = visibility.filtered(filteredPlatforms),
+ generics = generics.mapNotNull { it.filter(filteredPlatforms) },
+ sourceSets = filteredPlatforms,
+ )
+ }
+ }
}
}
diff --git a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
index 192de449..f818cae8 100644
--- a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
+++ b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
@@ -4,8 +4,10 @@ import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
+import kotlin.test.assertEquals
class VisibilityFilterTest : AbstractCoreTest() {
+
@Test
fun `public function with false global includeNonPublic`() {
val configuration = dokkaConfiguration {
@@ -36,6 +38,7 @@ class VisibilityFilterTest : AbstractCoreTest() {
}
}
}
+
@Test
fun `private function with false global includeNonPublic`() {
val configuration = dokkaConfiguration {
@@ -66,6 +69,7 @@ class VisibilityFilterTest : AbstractCoreTest() {
}
}
}
+
@Test
fun `private function with true global includeNonPublic`() {
val configuration = dokkaConfiguration {
@@ -96,6 +100,7 @@ class VisibilityFilterTest : AbstractCoreTest() {
}
}
}
+
@Test
fun `private function with false global true package includeNonPublic`() {
val configuration = dokkaConfiguration {
@@ -104,11 +109,13 @@ class VisibilityFilterTest : AbstractCoreTest() {
sourceRoots = listOf("src/main/kotlin/basic/Test.kt")
includeNonPublic = false
perPackageOptions = mutableListOf(
- PackageOptionsImpl("example",
+ PackageOptionsImpl(
+ "example",
true,
false,
false,
- false)
+ false
+ )
)
}
}
@@ -133,6 +140,7 @@ class VisibilityFilterTest : AbstractCoreTest() {
}
}
}
+
@Test
fun `private function with true global false package includeNonPublic`() {
val configuration = dokkaConfiguration {
@@ -141,11 +149,13 @@ class VisibilityFilterTest : AbstractCoreTest() {
sourceRoots = listOf("src/main/kotlin/basic/Test.kt")
includeNonPublic = true
perPackageOptions = mutableListOf(
- PackageOptionsImpl("example",
+ PackageOptionsImpl(
+ "example",
false,
false,
false,
- false)
+ false
+ )
)
}
}
@@ -164,10 +174,36 @@ class VisibilityFilterTest : AbstractCoreTest() {
configuration
) {
documentablesFirstTransformationStep = {
- Assertions.assertTrue(
- it.component2().packages.first().functions.size == 0
- )
- }
+ Assertions.assertTrue(
+ it.component2().packages.first().functions.size == 0
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `private typealias should be skipped`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ includeNonPublic = false
+ sourceRoots = listOf("src/main/kotlin/basic/Test.kt")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/basic/Test.kt
+ |package example
+ |
+ |private typealias ABC = Int
+ """.trimMargin(),
+ configuration
+ ) {
+ documentablesFirstTransformationStep = {
+ assertEquals(0, it.component2().packages.first().typealiases.size)
+ }
}
}
}