aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat@beresnev.me>2021-12-23 14:32:18 +0300
committerGitHub <noreply@github.com>2021-12-23 14:32:18 +0300
commitbfd41ce2a0d43419a671961c19b7d755cffdcfc8 (patch)
tree00d1fcd75ff7c25de20c8b0621e3bfb11cd3f61a /plugins/base/src/main
parent5c98d42ec08ca1413f920e4f5dde28d330e8837a (diff)
downloaddokka-bfd41ce2a0d43419a671961c19b7d755cffdcfc8.tar.gz
dokka-bfd41ce2a0d43419a671961c19b7d755cffdcfc8.tar.bz2
dokka-bfd41ce2a0d43419a671961c19b7d755cffdcfc8.zip
Introduce documentedVisibilities setting (#2270)
* Introduce `documentedVisibilities` setting * Remove hardcoded doc generation for Visibility.PUBLIC, correct tests * Add maven, gradle and cli integration tests for documentedVisibilities * Fix maven plugin configuration overriding the default value * Remove test debug prints * Correct an inconsistency with default values and leave a comment of intentions * Add a test for visibility of private setter
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt28
1 files changed, 24 insertions, 4 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
index bd39b040..4b9da03b 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
@@ -5,6 +5,7 @@ import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
+import org.jetbrains.dokka.DokkaDefaults
class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer {
@@ -20,10 +21,29 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
) {
fun Visibility.isAllowedInPackage(packageName: String?) = when (this) {
is JavaVisibility.Public,
- is KotlinVisibility.Public -> true
- else -> packageName != null
- && packageOptions.firstOrNull { Regex(it.matchingRegex).matches(packageName) }?.includeNonPublic
- ?: globalOptions.includeNonPublic
+ is KotlinVisibility.Public -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PUBLIC)
+ is JavaVisibility.Private,
+ is KotlinVisibility.Private -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PRIVATE)
+ is JavaVisibility.Protected,
+ is KotlinVisibility.Protected -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PROTECTED)
+ is KotlinVisibility.Internal -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.INTERNAL)
+ is JavaVisibility.Default -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PACKAGE)
+ }
+
+ private fun isAllowedInPackage(packageName: String?, visibility: DokkaConfiguration.Visibility): Boolean {
+ val packageOpts = packageName.takeIf { it != null }?.let { name ->
+ packageOptions.firstOrNull { Regex(it.matchingRegex).matches(name) }
+ }
+
+ val (documentedVisibilities, includeNonPublic) = when {
+ packageOpts != null -> packageOpts.documentedVisibilities to packageOpts.includeNonPublic
+ else -> globalOptions.documentedVisibilities to globalOptions.includeNonPublic
+ }
+
+ // if `documentedVisibilities` is explicitly overridden by the user (i.e. not default value by reference),
+ // deprecated `includeNonPublic` should not be taken into account, so that only one setting prevails
+ val isDocumentedVisibilitiesOverridden = documentedVisibilities !== DokkaDefaults.documentedVisibilities
+ return documentedVisibilities.contains(visibility) || (!isDocumentedVisibilitiesOverridden && includeNonPublic)
}
fun processModule(original: DModule) =