aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-04-14 15:16:27 +0200
committerGitHub <noreply@github.com>2021-04-14 15:16:27 +0200
commitacd9234be6909a69f89600e9c8ddde642d36b1cf (patch)
tree5494b5c6dbcd74c2cee408659fbcfef6d47def7d /plugins/base/src
parent357ee8a2836d96204343ff20cab8d17ad2f09aed (diff)
downloaddokka-acd9234be6909a69f89600e9c8ddde642d36b1cf.tar.gz
dokka-acd9234be6909a69f89600e9c8ddde642d36b1cf.tar.bz2
dokka-acd9234be6909a69f89600e9c8ddde642d36b1cf.zip
Fix visibility on enum entry property (#1828)
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt28
-rw-r--r--plugins/base/src/test/kotlin/enums/EnumsTest.kt2
-rw-r--r--plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt81
3 files changed, 99 insertions, 12 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
index 8ec8c1af..8b3b4304 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
@@ -157,23 +157,26 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
}
}
- private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: Set<DokkaSourceSet>) =
- entries.mapNotNull { entry ->
- if (filteredPlatforms.containsAll(entry.sourceSets)) entry
+ private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: Set<DokkaSourceSet>): Pair<Boolean, List<DEnumEntry>> =
+ entries.foldRight(Pair(false, emptyList())) { entry, acc ->
+ val intersection = filteredPlatforms.intersect(entry.sourceSets)
+ if (intersection.isEmpty()) Pair(true, acc.second)
else {
- val intersection = filteredPlatforms.intersect(entry.sourceSets)
- if (intersection.isEmpty()) null
- else DEnumEntry(
+ val functions = filterFunctions(entry.functions) { _, data -> data in intersection }
+ val properties = filterProperties(entry.properties) { _, data -> data in intersection }
+ val classlikes = filterClasslikes(entry.classlikes) { _, data -> data in intersection }
+
+ DEnumEntry(
entry.dri,
entry.name,
entry.documentation.filtered(intersection),
entry.expectPresentInSet.filtered(filteredPlatforms),
- filterFunctions(entry.functions) { _, data -> data in intersection }.second,
- filterProperties(entry.properties) { _, data -> data in intersection }.second,
- filterClasslikes(entry.classlikes) { _, data -> data in intersection }.second,
+ functions.second,
+ properties.second,
+ classlikes.second,
intersection,
entry.extra
- )
+ ).let { Pair(functions.first || properties.first || classlikes.first, acc.second + it) }
}
}
@@ -218,7 +221,10 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
val generics =
if (this is WithGenerics) generics.mapNotNull { param -> param.filter(filteredPlatforms) } else emptyList()
val enumEntries =
- if (this is DEnum) filterEnumEntries(entries, filteredPlatforms) else emptyList()
+ if (this is DEnum) filterEnumEntries(entries, filteredPlatforms).let { (listModified, list) ->
+ modified = modified || listModified
+ list
+ } else emptyList()
classlikesListChanged = classlikesListChanged || modified
when {
!modified -> this
diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
index eb35085e..2535140c 100644
--- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt
+++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
@@ -115,7 +115,7 @@ class EnumsTest : BaseAbstractTest() {
m.packages.let { p ->
p.first().classlikes.let { c ->
val enum = c.first() as DEnum
- val (first, second) = enum.entries
+ val (first, second) = enum.entries.sortedBy { it.name }
assertEquals(1, first.extra.allOfType<ConstructorValues>().size)
assertEquals(1, second.extra.allOfType<ConstructorValues>().size)
diff --git a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
index 416db52b..ffefaaea 100644
--- a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
+++ b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt
@@ -2,9 +2,12 @@ package filter
import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.jetbrains.dokka.model.DEnum
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
class VisibilityFilterTest : BaseAbstractTest() {
@@ -206,4 +209,82 @@ class VisibilityFilterTest : BaseAbstractTest() {
}
}
}
+
+ @Test
+ fun `internal property from enum 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 enums
+ |
+ |enum class Test(internal val value: Int) {
+ | A(0) {
+ | override fun testFun(): Float = 0.05F
+ | },
+ | B(1) {
+ | override fun testFun(): Float = 0.1F
+ | };
+ |
+ | internal open fun testFun(): Float = 0.5F
+ |}
+ """.trimMargin(),
+ configuration
+ ) {
+ documentablesTransformationStage = { module ->
+ val enum = module.packages.flatMap { it.classlikes }.filterIsInstance<DEnum>().first()
+ val entry = enum.entries.first()
+
+ assertFalse("testFun" in entry.functions.map { it.name })
+ assertFalse("value" in entry.properties.map { it.name })
+ assertFalse("testFun" in enum.functions.map { it.name })
+ }
+ }
+ }
+
+ @Test
+ fun `internal property from enum`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ includeNonPublic = true
+ sourceRoots = listOf("src/main/kotlin/basic/Test.kt")
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/basic/Test.kt
+ |package enums
+ |
+ |enum class Test(internal val value: Int) {
+ | A(0) {
+ | override fun testFun(): Float = 0.05F
+ | },
+ | B(1) {
+ | override fun testFun(): Float = 0.1F
+ | };
+ |
+ | internal open fun testFun(): Float = 0.5F
+ |}
+ """.trimMargin(),
+ configuration
+ ) {
+ documentablesTransformationStage = { module ->
+ val enum = module.packages.flatMap { it.classlikes }.filterIsInstance<DEnum>().first()
+ val entry = enum.entries.first()
+
+ assertTrue("testFun" in entry.functions.map { it.name })
+ assertTrue("value" in entry.properties.map { it.name })
+ assertTrue("testFun" in enum.functions.map { it.name })
+ }
+ }
+ }
}