diff options
Diffstat (limited to 'plugins/base/src')
4 files changed, 110 insertions, 8 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt index 8b3b4304..bd39b040 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt @@ -81,8 +81,12 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe return Pair(packagesListChanged, filteredPackages) } + @Suppress("UNUSED_PARAMETER") private fun <T : WithVisibility> alwaysTrue(a: T, p: DokkaSourceSet) = true + @Suppress("UNUSED_PARAMETER") private fun <T : WithVisibility> alwaysFalse(a: T, p: DokkaSourceSet) = false + @Suppress("UNUSED_PARAMETER") + private fun <T> alwaysNoModify(a: T, sourceSets: Set<DokkaSourceSet>) = false to a private fun WithVisibility.visibilityForPlatform(data: DokkaSourceSet): Visibility? = visibility[data] @@ -99,13 +103,18 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe private fun <T> List<T>.transform( additionalCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysTrue, alternativeCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysFalse, - recreate: (T, Set<DokkaSourceSet>) -> T + modify: (T, Set<DokkaSourceSet>) -> Pair<Boolean, T> = ::alwaysNoModify, + recreate: (T, Set<DokkaSourceSet>) -> T, ): Pair<Boolean, List<T>> where T : Documentable, T : WithVisibility { var changed = false val values = mapNotNull { t -> val filteredPlatforms = t.filterPlatforms(additionalCondition, alternativeCondition) when (filteredPlatforms.size) { - t.visibility.size -> t + t.visibility.size -> { + val (wasChanged, element) = modify(t, filteredPlatforms) + changed = changed || wasChanged + element + } 0 -> { changed = true null @@ -142,9 +151,35 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe private fun filterProperties( properties: List<DProperty>, - additionalCondition: (DProperty, DokkaSourceSet) -> Boolean = ::alwaysTrue - ): Pair<Boolean, List<DProperty>> = - properties.transform(additionalCondition, ::hasVisibleAccessorsForPlatform) { original, filteredPlatforms -> + additionalCondition: (DProperty, DokkaSourceSet) -> Boolean = ::alwaysTrue, + additionalConditionAccessors: (DFunction, DokkaSourceSet) -> Boolean = ::alwaysTrue + ): Pair<Boolean, List<DProperty>> { + + val modifier: (DProperty, Set<DokkaSourceSet>) -> Pair<Boolean, DProperty> = + { original, filteredPlatforms -> + val setter = original.setter?.let { filterFunctions(listOf(it), additionalConditionAccessors) } + val getter = original.getter?.let { filterFunctions(listOf(it), additionalConditionAccessors) } + + val modified = setter?.first == true || getter?.first == true + + val property = + if (modified) + original.copy( + setter = setter?.second?.firstOrNull(), + getter = getter?.second?.firstOrNull() + ) + else original + modified to property + } + + return properties.transform( + additionalCondition, + ::hasVisibleAccessorsForPlatform, + modifier + ) { original, filteredPlatforms -> + val setter = original.setter?.let { filterFunctions(listOf(it), additionalConditionAccessors) } + val getter = original.getter?.let { filterFunctions(listOf(it), additionalConditionAccessors) } + with(original) { copy( documentation = documentation.filtered(filteredPlatforms), @@ -153,9 +188,12 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe visibility = visibility.filtered(filteredPlatforms), sourceSets = filteredPlatforms, generics = generics.mapNotNull { it.filter(filteredPlatforms) }, + setter = setter?.second?.firstOrNull(), + getter = getter?.second?.firstOrNull() ) } } + } private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: Set<DokkaSourceSet>): Pair<Boolean, List<DEnumEntry>> = entries.foldRight(Pair(false, emptyList())) { entry, acc -> diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt index 0bcb6fd5..918ff1bf 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt @@ -27,7 +27,7 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D val classlikes = dPackage.classlikes.map { processClassLike(it) } val typeAliases = dPackage.typealiases.map { processMember(it) } val functions = dPackage.functions.map { processMember(it) } - val properies = dPackage.properties.map { processMember(it) } + val properies = dPackage.properties.map { processProperty(it) } val wasChanged = (classlikes + typeAliases + functions + properies).any { it.changed } return (dPackage.takeIf { !wasChanged } ?: dPackage.copy( @@ -43,7 +43,7 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D val functions = classlike.functions.map { processMember(it) } val classlikes = classlike.classlikes.map { processClassLike(it) } - val properties = classlike.properties.map { processMember(it) } + val properties = classlike.properties.map { processProperty(it) } val companion = (classlike as? WithCompanion)?.companion?.let { processClassLike(it) } val wasClasslikeChanged = (functions + classlikes + properties).any { it.changed } || companion?.changed == true @@ -104,7 +104,7 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D if (shouldBeSuppressed(dEnumEntry)) return DocumentableWithChanges.filteredDocumentable() val functions = dEnumEntry.functions.map { processMember(it) } - val properties = dEnumEntry.properties.map { processMember(it) } + val properties = dEnumEntry.properties.map { processProperty(it) } val classlikes = dEnumEntry.classlikes.map { processClassLike(it) } val wasChanged = (functions + properties + classlikes).any { it.changed } @@ -115,6 +115,19 @@ abstract class SuppressedByConditionDocumentableFilterTransformer(val context: D )).let { DocumentableWithChanges(it, wasChanged) } } + private fun processProperty(dProperty: DProperty): DocumentableWithChanges<DProperty> { + if (shouldBeSuppressed(dProperty)) return DocumentableWithChanges.filteredDocumentable() + + val getter = dProperty.getter?.let { processMember(it) } ?: DocumentableWithChanges(null, false) + val setter = dProperty.setter?.let { processMember(it) } ?: DocumentableWithChanges(null, false) + + val wasChanged = getter.changed || setter.changed + return (dProperty.takeIf { !wasChanged } ?: dProperty.copy( + getter = getter.documentable, + setter = setter.documentable + )).let { DocumentableWithChanges(it, wasChanged) } + } + private fun <T : Documentable> processMember(member: T): DocumentableWithChanges<T> = if (shouldBeSuppressed(member)) DocumentableWithChanges.filteredDocumentable() else DocumentableWithChanges(member, false) diff --git a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt index ffefaaea..1bb2d5d0 100644 --- a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt @@ -105,6 +105,37 @@ class VisibilityFilterTest : BaseAbstractTest() { } @Test + fun `private setter with false global includeNonPublic`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + includeNonPublic = false + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package example + | + |var property: Int = 0 + |private set + | + | + """.trimMargin(), + configuration + ) { + preMergeDocumentablesTransformationStage = { + Assertions.assertNull( + it.first().packages.first().properties.first().setter + ) + } + } + } + + @Test fun `private function with false global true package includeNonPublic`() { val configuration = dokkaConfiguration { sourceSets { diff --git a/plugins/base/src/test/kotlin/transformers/SuppressTagFilterTest.kt b/plugins/base/src/test/kotlin/transformers/SuppressTagFilterTest.kt index fb8f520e..de1ee46c 100644 --- a/plugins/base/src/test/kotlin/transformers/SuppressTagFilterTest.kt +++ b/plugins/base/src/test/kotlin/transformers/SuppressTagFilterTest.kt @@ -89,6 +89,26 @@ class SuppressTagFilterTest : BaseAbstractTest() { } @Test + fun `should filter setter`() { + testInline( + """ + |/src/suppressed/Suppressed.kt + |var property: Int + |/** @suppress */ + |private set + """.trimIndent(), configuration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val prop = modules.flatMap { it.packages }.flatMap { it.properties } + .find { it.name == "property" } + assertNotNull(prop) + assertNotNull(prop.getter) + assertNull(prop.setter) + } + } + } + + @Test fun `should filter top level type aliases`() { testInline( """ |