diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-03-01 13:50:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 13:50:17 +0100 |
commit | 7cf644f064868934fe8dcb46ab150f25fab8e8c8 (patch) | |
tree | 30d97e4cdaa6017401e7780bd86471f93d6f4d08 /plugins/base/src/main/kotlin | |
parent | ab853a866c40771e84a3235f40575efe04c435c5 (diff) | |
download | dokka-7cf644f064868934fe8dcb46ab150f25fab8e8c8.tar.gz dokka-7cf644f064868934fe8dcb46ab150f25fab8e8c8.tar.bz2 dokka-7cf644f064868934fe8dcb46ab150f25fab8e8c8.zip |
Add ability to suppress obvious functions like equals, toString... (#1758)
* Add ability to suppress obvious functions like equals, toString...
* Add ability to suppress obvious functions like equals, toString...
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/DokkaBase.kt | 11 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt | 11 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt | 2 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt (renamed from plugins/base/src/main/kotlin/transformers/documentables/SuppressedByTagDocumentableFilterTransformer.kt) | 2 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt | 4 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 17 |
6 files changed, 36 insertions, 11 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 2dbad3a7..5a7164d1 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -74,17 +74,22 @@ class DokkaBase : DokkaPlugin() { preMergeDocumentableTransformer providing ::SuppressTagDocumentableFilter } - val documentableVisbilityFilter by extending { + val documentableVisibilityFilter by extending { preMergeDocumentableTransformer providing ::DocumentableVisibilityFilterTransformer } + val obviousFunctionsVisbilityFilter by extending { + preMergeDocumentableTransformer providing ::ObviousFunctionsDocumentableFilterTransformer + } + val emptyPackagesFilter by extending { preMergeDocumentableTransformer providing ::EmptyPackagesFilterTransformer order { after( deprecatedDocumentableFilter, suppressedDocumentableFilter, - documentableVisbilityFilter, - suppressedBySuppressTagDocumentableFilter + documentableVisibilityFilter, + suppressedBySuppressTagDocumentableFilter, + obviousFunctionsVisbilityFilter ) } } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt new file mode 100644 index 00000000..57d7268e --- /dev/null +++ b/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt @@ -0,0 +1,11 @@ +package org.jetbrains.dokka.base.transformers.documentables + +import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.Documentable +import org.jetbrains.dokka.model.ObviousMember +import org.jetbrains.dokka.plugability.DokkaContext + +class ObviousFunctionsDocumentableFilterTransformer(context: DokkaContext) : SuppressedByConditionDocumentableFilterTransformer(context) { + override fun shouldBeSuppressed(d: Documentable): Boolean = + context.configuration.suppressObviousFunctions && d is DFunction && d.extra[ObviousMember] != null +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt index 7efb23ab..a297908d 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt @@ -6,7 +6,7 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.model.doc.Suppress class SuppressTagDocumentableFilter(val dokkaContext: DokkaContext) : - SuppressedByTagDocumentableFilterTransformer(dokkaContext) { + SuppressedByConditionDocumentableFilterTransformer(dokkaContext) { override fun shouldBeSuppressed(d: Documentable): Boolean = d.documentation.any { (_, docs) -> docs.dfs { it is Suppress } != null } }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByTagDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt index f40abe70..b0bdd4b7 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByTagDocumentableFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt @@ -4,7 +4,7 @@ import org.jetbrains.dokka.model.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer -abstract class SuppressedByTagDocumentableFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { +abstract class SuppressedByConditionDocumentableFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { override fun invoke(modules: List<DModule>): List<DModule> = modules.map { module -> val (documentable, wasChanged) = processModule(module) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index b08c11b8..bc45337a 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -493,6 +493,7 @@ private class DokkaDescriptorVisitor( descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), (descriptor.getAnnotations() + descriptor.fileLevelAnnotations()).toSourceSetDependent() .toAnnotations(), + ObviousMember.takeIf { descriptor.isFake }, ) ) } @@ -1036,6 +1037,9 @@ private class DokkaDescriptorVisitor( ?.toList() ?.parallelMap { it.toAnnotation(scope = Annotations.AnnotationScope.FILE) } .orEmpty() + + private val FunctionDescriptor.isFake: Boolean + get() = kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE || kind == CallableMemberDescriptor.Kind.SYNTHESIZED } private data class AncestryLevel( diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index c09d1156..14d57df0 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -111,11 +111,12 @@ class DefaultPsiToDocumentableTranslator( private val cachedBounds = hashMapOf<String, Bound>() - private fun PsiModifierListOwner.getVisibility() = modifierList?.children?.toList()?.let { ml -> + private fun PsiModifierListOwner.getVisibility() = modifierList?.let { + val ml = it.children.toList() when { - ml.any { it.text == PsiKeyword.PUBLIC } -> JavaVisibility.Public - ml.any { it.text == PsiKeyword.PROTECTED } -> JavaVisibility.Protected - ml.any { it.text == PsiKeyword.PRIVATE } -> JavaVisibility.Private + ml.any { it.text == PsiKeyword.PUBLIC } || it.hasModifierProperty("public") -> JavaVisibility.Public + ml.any { it.text == PsiKeyword.PROTECTED } || it.hasModifierProperty("protected") -> JavaVisibility.Protected + ml.any { it.text == PsiKeyword.PRIVATE } || it.hasModifierProperty("private") -> JavaVisibility.Private else -> JavaVisibility.Default } } ?: JavaVisibility.Default @@ -126,6 +127,9 @@ class DefaultPsiToDocumentableTranslator( private val PsiClassType.shouldBeIgnored: Boolean get() = isClass("java.lang.Enum") || isClass("java.lang.Object") + private val DRI.isObvious: Boolean + get() = packageName == "java.lang" && (classNames == "Object" || classNames == "Enum") + private fun PsiClassType.isClass(qName: String): Boolean { val shortName = qName.substringAfterLast('.') if (className == shortName) { @@ -184,7 +188,7 @@ class DefaultPsiToDocumentableTranslator( ancestryTree.add(AncestryLevel(level, classes.firstOrNull()?.first, interfaces.map { it.first })) superTypes.forEach { type -> - (type as? PsiClassType)?.takeUnless { type.shouldBeIgnored }?.resolve()?.let { + (type as? PsiClassType)?.resolve()?.let { val definedAt = DRI.from(it) it.methods.forEach { method -> val hash = method.hash @@ -392,7 +396,8 @@ class DefaultPsiToDocumentableTranslator( it.toSourceSetDependent().toAdditionalModifiers(), (psi.annotations.toList() .toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() - .toAnnotations() + .toAnnotations(), + ObviousMember.takeIf { inheritedFrom != null && inheritedFrom.isObvious } ) } ) |