Skip to content

Commit

Permalink
Suppress inherited members
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinAman committed Mar 30, 2021
1 parent 4ddaafb commit 441ccc8
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 33 deletions.
2 changes: 2 additions & 0 deletions core/src/main/kotlin/configuration.kt
Expand Up @@ -33,6 +33,7 @@ object DokkaDefaults {
val moduleVersion: String? = null
val pluginsConfiguration = mutableListOf<PluginConfigurationImpl>()
const val suppressObviousFunctions = true
const val suppressInheritedMembers = false
}

enum class Platform(val key: String) {
Expand Down Expand Up @@ -101,6 +102,7 @@ interface DokkaConfiguration : Serializable {
val delayTemplateSubstitution: Boolean
val suppressObviousFunctions: Boolean
val includes: Set<File>
val suppressInheritedMembers: Boolean

enum class SerializationFormat : Serializable {
JSON, XML
Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/defaultConfiguration.kt
Expand Up @@ -18,6 +18,7 @@ data class DokkaConfigurationImpl(
override val delayTemplateSubstitution: Boolean = false,
override val suppressObviousFunctions: Boolean = DokkaDefaults.suppressObviousFunctions,
override val includes: Set<File> = emptySet(),
override val suppressInheritedMembers: Boolean = DokkaDefaults.suppressInheritedMembers,
) : DokkaConfiguration

data class PluginConfigurationImpl(
Expand Down
Expand Up @@ -36,6 +36,7 @@ class TestDokkaConfigurationBuilder {
var modules: List<DokkaModuleDescriptionImpl> = emptyList()
var suppressObviousFunctions: Boolean = DokkaDefaults.suppressObviousFunctions
var includes: List<File> = emptyList()
var suppressInheritedMembers: Boolean = DokkaDefaults.suppressInheritedMembers
private val lazySourceSets = mutableListOf<Lazy<DokkaSourceSetImpl>>()

fun build() = DokkaConfigurationImpl(
Expand All @@ -51,6 +52,7 @@ class TestDokkaConfigurationBuilder {
failOnWarning = failOnWarning,
suppressObviousFunctions = suppressObviousFunctions,
includes = includes.toSet(),
suppressInheritedMembers = suppressInheritedMembers,
)

fun sourceSets(block: SourceSetsBuilder.() -> Unit) {
Expand Down Expand Up @@ -194,6 +196,8 @@ fun dPackage(
)

fun documentationNode(vararg texts: String): DocumentationNode {
return DocumentationNode(texts.toList().map { Description(CustomDocTag(listOf(Text(it)), name = MarkdownElementTypes.MARKDOWN_FILE.name)) })
return DocumentationNode(
texts.toList()
.map { Description(CustomDocTag(listOf(Text(it)), name = MarkdownElementTypes.MARKDOWN_FILE.name)) })
}

1 change: 1 addition & 0 deletions docs/src/doc/docs/user_guide/cli/usage.md
Expand Up @@ -21,6 +21,7 @@ Dokka supports the following command line arguments:
* `-globalLinks` - external documentation links added to all source sets
* `-globalSrcLink` - source links added to all source sets
* `-noSuppressObviousFunctions` - don't suppress obvious functions like default `toString` or `equals`
* `-suppressInheritedMembers` - suppress all inherited members that were not overriden in a given class. Eg. using it you can suppress toString or equals functions but you can't suppress componentN or copy on data class
* `-sourceSet` - (repeatable) - configuration for a single source set. Following this argument, you can pass other arguments:
* `-sourceSetName` - source set name as a part of source set ID when declaring dependent source sets
* `-displayName` - source set name displayed in the generated documentation
Expand Down
5 changes: 5 additions & 0 deletions docs/src/doc/docs/user_guide/gradle/usage.md
Expand Up @@ -92,6 +92,11 @@ dokkaHtml {

// Suppress obvious functions like default toString or equals. Defaults to true
suppressObviousFunctions.set(false)

// Suppress all inherited members that were not overriden in a given class.
// Eg. using it you can suppress toString or equals functions but you can't suppress componentN or copy on data class. To do that use with suppressObviousFunctions
// Defaults to false
suppressInheritedMembers.set(true)

dokkaSourceSets {
configureEach { // Or source set name, for single-platform the default source sets are `main` and `test`
Expand Down
5 changes: 5 additions & 0 deletions docs/src/doc/docs/user_guide/maven/usage.md
Expand Up @@ -88,6 +88,11 @@ The available configuration options are shown below:
<!-- Suppress obvious functions like default toString or equals. Defaults to true -->
<suppressObviousFunctions>false</suppressObviousFunctions>

<!-- Suppress all inherited members that were not overriden in a given class. -->
<!-- Eg. using it you can suppress toString or equals functions but you can't suppress componentN or copy on data class. To do that use with suppressObviousFunctions -->
<!-- Defaults to false -->
<suppressInheritedMembers>true</suppressInheritedMembers>

<!-- Used for linking to JDK, default: 6 -->
<jdkVersion>6</jdkVersion>

Expand Down
9 changes: 8 additions & 1 deletion plugins/base/src/main/kotlin/DokkaBase.kt
Expand Up @@ -82,14 +82,21 @@ class DokkaBase : DokkaPlugin() {
preMergeDocumentableTransformer providing ::ObviousFunctionsDocumentableFilterTransformer
}

val inheritedEntriesVisbilityFilter by extending {
preMergeDocumentableTransformer providing ::InheritedEntriesDocumentableFilterTransformer
}



val emptyPackagesFilter by extending {
preMergeDocumentableTransformer providing ::EmptyPackagesFilterTransformer order {
after(
deprecatedDocumentableFilter,
suppressedDocumentableFilter,
documentableVisibilityFilter,
suppressedBySuppressTagDocumentableFilter,
obviousFunctionsVisbilityFilter
obviousFunctionsVisbilityFilter,
inheritedEntriesVisbilityFilter,
)
}
}
Expand Down
@@ -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
}
@@ -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 })
}
}
}
}
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 441ccc8

Please sign in to comment.