diff options
Diffstat (limited to 'plugins/base/src')
-rw-r--r-- | plugins/base/src/main/kotlin/DokkaBase.kt | 11 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt | 13 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt | 112 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/transformers/ObviousAndInheritedFunctionsDocumentableFilterTest.kt (renamed from plugins/base/src/test/kotlin/transformers/ObviousFunctionsDocumentableFilterTest.kt) | 101 |
4 files changed, 203 insertions, 34 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index d84207a5..0a18c3b1 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -82,6 +82,10 @@ class DokkaBase : DokkaPlugin() { preMergeDocumentableTransformer providing ::ObviousFunctionsDocumentableFilterTransformer } + val inheritedEntriesVisbilityFilter by extending { + preMergeDocumentableTransformer providing ::InheritedEntriesDocumentableFilterTransformer + } + val emptyPackagesFilter by extending { preMergeDocumentableTransformer providing ::EmptyPackagesFilterTransformer order { after( @@ -89,7 +93,8 @@ class DokkaBase : DokkaPlugin() { suppressedDocumentableFilter, documentableVisibilityFilter, suppressedBySuppressTagDocumentableFilter, - obviousFunctionsVisbilityFilter + obviousFunctionsVisbilityFilter, + inheritedEntriesVisbilityFilter, ) } } @@ -120,7 +125,6 @@ class DokkaBase : DokkaPlugin() { CoreExtensions.documentableTransformer with InheritorsExtractorTransformer() } - val undocumentedCodeReporter by extending { CoreExtensions.documentableTransformer with ReportUndocumentedTransformer() } @@ -163,7 +167,6 @@ class DokkaBase : DokkaPlugin() { CoreExtensions.renderer providing ::HtmlRenderer } - val defaultKotlinAnalysis by extending { kotlinAnalysis providing { ctx -> KotlinAnalysis(ctx.configuration.sourceSets, ctx.logger) } } @@ -246,4 +249,4 @@ class DokkaBase : DokkaPlugin() { val baseSearchbarDataInstaller by extending { htmlPreprocessors providing ::SearchbarDataInstaller order { after(sourceLinksTransformer) } } -}
\ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt new file mode 100644 index 00000000..a1b5052d --- /dev/null +++ b/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt @@ -0,0 +1,13 @@ +package org.jetbrains.dokka.base.transformers.documentables + +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.properties.WithExtraProperties +import org.jetbrains.dokka.plugability.DokkaContext + +class InheritedEntriesDocumentableFilterTransformer(context: DokkaContext) : + SuppressedByConditionDocumentableFilterTransformer(context) { + override fun shouldBeSuppressed(d: Documentable): Boolean = + context.configuration.suppressInheritedMembers && (d as? WithExtraProperties<Documentable>)?.extra?.get( + InheritedMember + )?.inheritedFrom?.any { entry -> entry.value != null } ?: false +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt b/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt new file mode 100644 index 00000000..9cb956ba --- /dev/null +++ b/plugins/base/src/test/kotlin/transformers/InheritedEntriesDocumentableFilterTransfromerTest.kt @@ -0,0 +1,112 @@ +package transformers + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class InheritedEntriesDocumentableFilterTransformerTest : BaseAbstractTest() { + val suppressingInheritedConfiguration = dokkaConfiguration { + suppressInheritedMembers = true + suppressObviousFunctions = false + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } + } + } + + val nonSuppressingInheritedConfiguration = dokkaConfiguration { + suppressObviousFunctions = false + suppressInheritedMembers = false + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } + } + } + + + @Test + fun `should suppress toString, equals and hashcode but keep custom ones`() { + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + data class Suppressed(val x: String) { + override fun toString(): String { + return "custom" + } + } + """.trimIndent(), + suppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val functions = modules.flatMap { it.packages }.flatMap { it.classlikes }.flatMap { it.functions } + assertEquals(listOf("toString", "copy", "component1").sorted(), functions.map { it.name }.sorted()) + } + } + } + + @Test + fun `should suppress toString, equals and hashcode`() { + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + data class Suppressed(val x: String) + """.trimIndent(), + suppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val functions = modules.flatMap { it.packages }.flatMap { it.classlikes }.flatMap { it.functions } + assertEquals(listOf("copy", "component1").sorted(), functions.map { it.name }.sorted()) + } + } + } + + @Test + fun `should also suppress properites`(){ + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + open class Parent { + val parentValue = "String" + } + + class Child : Parent { + + } + """.trimIndent(), + suppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val properties = modules.flatMap { it.packages }.flatMap { it.classlikes }.first { it.name == "Child" }.properties + assertEquals(0, properties.size) + } + } + } + + @Test + fun `should not suppress properites if config says so`(){ + testInline( + """ + /src/suppressed/Suppressed.kt + package suppressed + open class Parent { + val parentValue = "String" + } + + class Child : Parent { + + } + """.trimIndent(), + nonSuppressingInheritedConfiguration + ) { + preMergeDocumentablesTransformationStage = { modules -> + val properties = modules.flatMap { it.packages }.flatMap { it.classlikes }.first { it.name == "Child" }.properties + assertEquals(listOf("parentValue"), properties.map { it.name }) + } + } + } +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/transformers/ObviousFunctionsDocumentableFilterTest.kt b/plugins/base/src/test/kotlin/transformers/ObviousAndInheritedFunctionsDocumentableFilterTest.kt index d666b8a7..3618c8fb 100644 --- a/plugins/base/src/test/kotlin/transformers/ObviousFunctionsDocumentableFilterTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ObviousAndInheritedFunctionsDocumentableFilterTest.kt @@ -1,29 +1,63 @@ package transformers +import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource +import testApi.testRunner.dokkaConfiguration import kotlin.test.assertEquals -class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { - val suppressingConfiguration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src") +class ObviousAndInheritedFunctionsDocumentableFilterTest : BaseAbstractTest() { + companion object { + @JvmStatic + fun suppressingObviousConfiguration() = listOf(dokkaConfiguration { + suppressInheritedMembers = false + suppressObviousFunctions = true + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } } - } - } + }) - val nonSuppressingConfiguration = dokkaConfiguration { - suppressObviousFunctions = false - sourceSets { - sourceSet { - sourceRoots = listOf("src") + @JvmStatic + fun nonSuppressingObviousConfiguration() = listOf(dokkaConfiguration { + suppressObviousFunctions = false + suppressInheritedMembers = false + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } } - } + }) + + @JvmStatic + fun suppressingInheritedConfiguration() = listOf(dokkaConfiguration { + suppressInheritedMembers = true + suppressObviousFunctions = false + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } + } + }) + + @JvmStatic + fun nonSuppressingInheritedConfiguration() = listOf(dokkaConfiguration { + suppressObviousFunctions = false + suppressInheritedMembers = false + sourceSets { + sourceSet { + sourceRoots = listOf("src") + } + } + }) } - @Test - fun `should suppress toString, equals and hashcode`() { + + @ParameterizedTest + @MethodSource(value = ["suppressingObviousConfiguration"]) + fun `should suppress toString, equals and hashcode`(suppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.kt @@ -39,8 +73,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should suppress toString, equals and hashcode for interface`() { + @ParameterizedTest + @MethodSource(value = ["suppressingObviousConfiguration", "suppressingInheritedConfiguration"]) + fun `should suppress toString, equals and hashcode for interface`(suppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.kt @@ -56,8 +91,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should suppress toString, equals and hashcode in Java`() { + @ParameterizedTest + @MethodSource(value = ["suppressingObviousConfiguration", "suppressingInheritedConfiguration"]) + fun `should suppress toString, equals and hashcode in Java`(suppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.java @@ -74,8 +110,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should suppress toString, equals and hashcode but keep custom ones`() { + @ParameterizedTest + @MethodSource(value = ["suppressingObviousConfiguration"]) + fun `should suppress toString, equals and hashcode but keep custom ones`(suppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.kt @@ -95,8 +132,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should suppress toString, equals and hashcode but keep custom ones in Java`() { + @ParameterizedTest + @MethodSource(value = ["suppressingObviousConfiguration", "suppressingInheritedConfiguration"]) + fun `should suppress toString, equals and hashcode but keep custom ones in Java`(suppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.java @@ -117,8 +155,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should not suppress toString, equals and hashcode if custom config is provided`() { + @ParameterizedTest + @MethodSource(value = ["nonSuppressingObviousConfiguration", "nonSuppressingInheritedConfiguration"]) + fun `should not suppress toString, equals and hashcode if custom config is provided`(nonSuppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.kt @@ -137,8 +176,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `not should suppress toString, equals and hashcode for interface if custom config is provided`() { + @ParameterizedTest + @MethodSource(value = ["nonSuppressingObviousConfiguration", "nonSuppressingInheritedConfiguration"]) + fun `not should suppress toString, equals and hashcode for interface if custom config is provided`(nonSuppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.kt @@ -154,8 +194,9 @@ class ObviousFunctionsDocumentableFilterTest : BaseAbstractTest() { } } - @Test - fun `should not suppress toString, equals and hashcode if custom config is provided in Java`() { + @ParameterizedTest + @MethodSource(value = ["nonSuppressingObviousConfiguration", "nonSuppressingInheritedConfiguration"]) + fun `should not suppress toString, equals and hashcode if custom config is provided in Java`(nonSuppressingConfiguration: DokkaConfigurationImpl) { testInline( """ /src/suppressed/Suppressed.java |