Skip to content

Commit

Permalink
Remove hardcoded doc generation for Visibility.PUBLIC, correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Dec 16, 2021
1 parent 8366959 commit 398fe2d
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 51 deletions.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object DokkaDefaults {
const val delayTemplateSubstitution: Boolean = false

const val includeNonPublic: Boolean = false
val documentedVisibilities: Set<DokkaConfiguration.Visibility> = setOf()
val documentedVisibilities: Set<DokkaConfiguration.Visibility> = setOf(DokkaConfiguration.Visibility.PUBLIC)
const val reportUndocumented: Boolean = false
const val skipEmptyPackages: Boolean = true
const val skipDeprecated: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DokkaSourceSetBuilder(
var includes: List<String> = emptyList(),
@Deprecated(message = "Use [documentedVisibilities] property for a more flexible control over documented visibilities")
var includeNonPublic: Boolean = false,
var documentedVisibilities: Set<DokkaConfiguration.Visibility> = emptySet(),
var documentedVisibilities: Set<DokkaConfiguration.Visibility> = DokkaDefaults.documentedVisibilities,
var reportUndocumented: Boolean = false,
var skipEmptyPackages: Boolean = false,
var skipDeprecated: Boolean = false,
Expand Down Expand Up @@ -140,7 +140,7 @@ val defaultSourceSet = DokkaSourceSetImpl(
samples = emptySet(),
includes = emptySet(),
includeNonPublic = false,
documentedVisibilities = emptySet(),
documentedVisibilities = DokkaDefaults.documentedVisibilities,
reportUndocumented = false,
skipEmptyPackages = true,
skipDeprecated = false,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/doc/docs/user_guide/cli/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Dokka supports the following command line arguments:
* `-samples` - list of directories containing sample code (documentation for those directories is not generated but declarations from them can be referenced using the `@sample` tag) separated by `;`
* `-includes` - list of files containing the documentation for the module and individual packages separated by `;`
* `-includeNonPublic` - **Deprecated**, prefer using `documentedVisibilities`. Include protected and private code
* `-documentedVisibilities` - a list of visibility modifiers (separated by `;`) that should be documented. Possible values: `PUBLIC` (by default, can be omitted), `PRIVATE`, `PROTECTED`, `INTERNAL` (Kotlin-specific), `PACKAGE` (Java-specific package-private)
* `-documentedVisibilities` - a list of visibility modifiers (separated by `;`) that should be documented. Possible values: `PUBLIC`, `PRIVATE`, `PROTECTED`, `INTERNAL` (Kotlin-specific), `PACKAGE` (Java-specific package-private)
* `-skipDeprecated` - if set, deprecated elements are not included in the generated documentation
* `-reportUndocumented` - warn about undocumented members
* `-noSkipEmptyPackages` - create index pages for empty packages
Expand Down
4 changes: 2 additions & 2 deletions docs/src/doc/docs/user_guide/gradle/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ val dokkaHtml by getting(DokkaTask::class) {
// A set of visibility modifiers that should be documented
documentedVisibilities.set(
setOf(
Visibility.PUBLIC, // Included by default, can be omitted
Visibility.PUBLIC, // Same for both Kotlin and Java
Visibility.PRIVATE, // Same for both Kotlin and Java
Visibility.PROTECTED, // Same for both Kotlin and Java
Visibility.INTERNAL, // Kotlin-specific internal modifier
Expand Down Expand Up @@ -193,7 +193,7 @@ val dokkaHtml by getting(DokkaTask::class) {
includeNonPublic.set(false) // Deprecated, prefer using documentedVisibilities
documentedVisibilities.set( // Visibilities that should be included in the documentation
setOf(
Visibility.PUBLIC, // Included by default, can be omitted
Visibility.PUBLIC, // Same for both Kotlin and Java
Visibility.PRIVATE, // Same for both Kotlin and Java
Visibility.PROTECTED, // Same for both Kotlin and Java
Visibility.INTERNAL, // Kotlin-specific internal modifier
Expand Down
4 changes: 2 additions & 2 deletions docs/src/doc/docs/user_guide/maven/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The available configuration options are shown below:

<!-- A list of visibility modifiers that should be documented -->
<documentedVisibilities>
<visibility>PUBLIC</visibility> <!-- Default, can be omitted -->
<visibility>PUBLIC</visibility> <!-- Same for both kotlin and java -->
<visibility>PRIVATE</visibility> <!-- Same for both kotlin and java -->
<visibility>PROTECTED</visibility> <!-- Same for both kotlin and java -->
<visibility>INTERNAL</visibility> <!-- Kotlin-specific internal modifier -->
Expand Down Expand Up @@ -166,7 +166,7 @@ The available configuration options are shown below:

<!-- A list of visibility modifiers that should be documented -->
<documentedVisibilities>
<visibility>PUBLIC</visibility> <!-- Included by default, can be omitted -->
<visibility>PUBLIC</visibility> <!-- Same for both kotlin and java -->
<visibility>PRIVATE</visibility> <!-- Same for both kotlin and java -->
<visibility>PROTECTED</visibility> <!-- Same for both kotlin and java -->
<visibility>INTERNAL</visibility> <!-- Kotlin-specific internal modifier -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -20,7 +21,7 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
) {
fun Visibility.isAllowedInPackage(packageName: String?) = when (this) {
is JavaVisibility.Public,
is KotlinVisibility.Public -> true
is KotlinVisibility.Public -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PUBLIC)
is JavaVisibility.Private,
is KotlinVisibility.Private -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PRIVATE)
is JavaVisibility.Protected,
Expand All @@ -39,7 +40,12 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe
else -> globalOptions.documentedVisibilities to globalOptions.includeNonPublic
}

return documentedVisibilities.takeIf { it.isNotEmpty() }?.contains(visibility) ?: includeNonPublic
val isDocumentedVisibilitiesOverridden = documentedVisibilities !== DokkaDefaults.documentedVisibilities
return if (isDocumentedVisibilitiesOverridden) {
documentedVisibilities.contains(visibility)
} else {
visibility == DokkaConfiguration.Visibility.PUBLIC || includeNonPublic
}
}

fun processModule(original: DModule) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ContentForSignaturesTest : BaseAbstractTest() {
sourceRoots = listOf("src/")
analysisPlatform = "jvm"
documentedVisibilities = setOf(
DokkaConfiguration.Visibility.PUBLIC,
DokkaConfiguration.Visibility.PRIVATE,
DokkaConfiguration.Visibility.PROTECTED,
DokkaConfiguration.Visibility.INTERNAL,
Expand Down
5 changes: 3 additions & 2 deletions plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package filter

import org.jetbrains.dokka.DokkaDefaults
import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.jupiter.api.Assertions
Expand Down Expand Up @@ -110,7 +111,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
false,
true,
false,
emptySet()
DokkaDefaults.documentedVisibilities
)
)
}
Expand Down Expand Up @@ -149,7 +150,7 @@ class DeprecationFilterTest : BaseAbstractTest() {
false,
false,
false,
emptySet()
DokkaDefaults.documentedVisibilities
)
)
}
Expand Down
22 changes: 12 additions & 10 deletions plugins/base/src/test/kotlin/filter/JavaVisibilityFilterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package filter

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.DokkaDefaults
import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DClass
Expand All @@ -15,7 +16,7 @@ import kotlin.test.assertEquals
class JavaVisibilityFilterTest : BaseAbstractTest() {

@Test
fun `should include nothing private if no visibilities are included`() {
fun `should document nothing private if no visibilities are included`() {
testVisibility(
"""
| public class JavaVisibilityTest {
Expand All @@ -26,7 +27,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
| private void privateFunction() { }
| }
""".trimIndent(),
includedVisibility = setOf()
includedVisibility = DokkaDefaults.documentedVisibilities
) { module ->
val clazz = module.first().packages.first().classlikes.filterIsInstance<DClass>().first()
clazz.properties.also {
Expand All @@ -41,7 +42,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
}

@Test
fun `should include private`() {
fun `should document private within public class`() {
testVisibility(
"""
| public class JavaVisibilityTest {
Expand All @@ -54,7 +55,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
| private void privateFunction() { }
| }
""".trimIndent(),
includedVisibility = setOf(DokkaConfiguration.Visibility.PRIVATE)
includedVisibility = setOf(DokkaConfiguration.Visibility.PUBLIC, DokkaConfiguration.Visibility.PRIVATE)
) { module ->
val clazz = module.first().packages.first().classlikes.filterIsInstance<DClass>().first()
clazz.properties.also {
Expand All @@ -71,7 +72,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
}

@Test
fun `should include package private`() {
fun `should document package private within private class`() {
testVisibility(
"""
| public class JavaVisibilityTest {
Expand All @@ -84,7 +85,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
| void packagePrivateFunction() { }
| }
""".trimIndent(),
includedVisibility = setOf(DokkaConfiguration.Visibility.PACKAGE)
includedVisibility = setOf(DokkaConfiguration.Visibility.PUBLIC, DokkaConfiguration.Visibility.PACKAGE)
) { module ->
val clazz = module.first().packages.first().classlikes.filterIsInstance<DClass>().first()
clazz.properties.also {
Expand All @@ -101,7 +102,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
}

@Test
fun `should include protected`() {
fun `should document protected within public class`() {
testVisibility(
"""
| public class JavaVisibilityTest {
Expand All @@ -114,7 +115,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
| protected void protectedFunction() { }
| }
""".trimIndent(),
includedVisibility = setOf(DokkaConfiguration.Visibility.PROTECTED)
includedVisibility = setOf(DokkaConfiguration.Visibility.PUBLIC, DokkaConfiguration.Visibility.PROTECTED)
) { module ->
val clazz = module.first().packages.first().classlikes.filterIsInstance<DClass>().first()
clazz.properties.also {
Expand Down Expand Up @@ -147,6 +148,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
| }
""".trimIndent(),
includedVisibility = setOf(
DokkaConfiguration.Visibility.PUBLIC,
DokkaConfiguration.Visibility.PRIVATE,
DokkaConfiguration.Visibility.PROTECTED,
DokkaConfiguration.Visibility.PACKAGE,
Expand Down Expand Up @@ -253,7 +255,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
false,
false,
false,
emptySet()
DokkaDefaults.documentedVisibilities
)
)
}
Expand All @@ -272,7 +274,7 @@ class JavaVisibilityFilterTest : BaseAbstractTest() {
false,
false,
false,
emptySet()
DokkaDefaults.documentedVisibilities
)
)
}
Expand Down
Loading

0 comments on commit 398fe2d

Please sign in to comment.