aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/pages/annotations
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-03-13 12:08:29 +0100
committerPaweł Marks <pmarks@virtuslab.com>2020-03-17 16:31:44 +0100
commit0b6b990d286e22bd86aef3a7e73fbfb38ffa04ef (patch)
tree0dd378bddc635d2fae2a1f91839235a144f530fe /plugins/base/src/main/kotlin/transformers/pages/annotations
parenta01554561ca8d18a1cf3c94df47e4b38fae1c538 (diff)
downloaddokka-0b6b990d286e22bd86aef3a7e73fbfb38ffa04ef.tar.gz
dokka-0b6b990d286e22bd86aef3a7e73fbfb38ffa04ef.tar.bz2
dokka-0b6b990d286e22bd86aef3a7e73fbfb38ffa04ef.zip
Add a rough draft of deprecated signatures formatting
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages/annotations')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt57
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt
new file mode 100644
index 00000000..55f01ad3
--- /dev/null
+++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt
@@ -0,0 +1,57 @@
+package org.jetbrains.dokka.base.transformers.pages.annotations
+
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.properties.WithExtraProperties
+import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.transformers.pages.PageTransformer
+
+class DeprecatedStrikethroughTransformer(val context: DokkaContext) : PageTransformer {
+ override fun invoke(input: RootPageNode): RootPageNode = input.transformContentPagesTree { contentPage ->
+ if (contentPage.documentable?.isDeprecated() == true || contentPage.documentable?.hasDeprecatedChildren() == true) {
+ val deprecatedDRIs =
+ contentPage.dri +
+ contentPage.documentable?.children
+ ?.filter { it.isDeprecated() }
+ ?.map { it.dri }
+ ?.toSet().orEmpty()
+
+ contentPage.modified(content = contentPage.content.addStrikethroughToSignature(deprecatedDRIs))
+ } else {
+ contentPage
+ }
+ }
+
+ private fun ContentNode.addStrikethroughToSignature(deprecatedDRIs: Set<DRI>): ContentNode = when (this) {
+ is ContentGroup -> if (dci.kind == ContentKind.Symbol && deprecatedDRIs.containsAll(dci.dri)) {
+ copy(style = this.style + setOf(TextStyle.Strikethrough))
+ } else {
+ copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) })
+ }
+ is ContentTable -> copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) as ContentGroup })
+ is PlatformHintedContent -> copy(inner = inner.addStrikethroughToSignature(deprecatedDRIs))
+ else -> this
+ }
+
+ private fun Documentable.isDeprecated(): Boolean = when (this) {
+ is DClass -> this.isKotlinOrJavaDeprecated()
+ is DAnnotation -> this.isKotlinOrJavaDeprecated()
+ is DObject -> this.isKotlinOrJavaDeprecated()
+ is DInterface -> this.isKotlinOrJavaDeprecated()
+ is DEnum -> this.isKotlinOrJavaDeprecated()
+ is DFunction -> this.isKotlinOrJavaDeprecated()
+ is DProperty -> this.isKotlinOrJavaDeprecated()
+ is DEnumEntry -> this.isKotlinOrJavaDeprecated()
+
+ else -> false
+ }
+
+ private fun Documentable.hasDeprecatedChildren() = children.any { it.isDeprecated() }
+
+ private fun <T : Documentable> WithExtraProperties<T>.isKotlinOrJavaDeprecated() =
+ extra[Annotations]?.content?.any {
+ it.dri == DRI("kotlin", "Deprecated")
+ || it.dri == DRI("java.lang", "Deprecated")
+ } == true
+} \ No newline at end of file