aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-06-09 16:31:58 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-06-25 14:56:46 +0200
commitcc89f0b74a870303c854fcb892d469d4c8fb17a8 (patch)
treed0affdb4ad029926fedae5d3e0af6fcf150bfde2 /plugins/base/src/main/kotlin/transformers
parent1183e09a7123c8f9665248235c5e33ba28e92780 (diff)
downloaddokka-cc89f0b74a870303c854fcb892d469d4c8fb17a8.tar.gz
dokka-cc89f0b74a870303c854fcb892d469d4c8fb17a8.tar.bz2
dokka-cc89f0b74a870303c854fcb892d469d4c8fb17a8.zip
Gives text presentation for `SinceKotlin` and hides it from rendering. Hides `Deprecated`. #944
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt82
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt
new file mode 100644
index 00000000..7914e88f
--- /dev/null
+++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt
@@ -0,0 +1,82 @@
+package org.jetbrains.dokka.base.transformers.pages.annotations
+
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.doc.CustomTagWrapper
+import org.jetbrains.dokka.model.doc.Text
+import org.jetbrains.dokka.model.properties.WithExtraProperties
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
+import org.jetbrains.kotlin.utils.addToStdlib.safeAs
+
+class SinceKotlinTransformer(val context: DokkaContext) : DocumentableTransformer {
+
+ override fun invoke(original: DModule, context: DokkaContext) = original.transform() as DModule
+
+ private fun <T : Documentable> T.transform(): Documentable =
+ when (this) {
+ is DModule -> copy(
+ packages = packages.map { it.transform() as DPackage }
+ )
+ is DPackage -> copy(
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DClass -> copy(
+ documentation = appendSinceKotlin(),
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DEnum -> copy(
+ documentation = appendSinceKotlin(),
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DInterface -> copy(
+ documentation = appendSinceKotlin(),
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DObject -> copy(
+ documentation = appendSinceKotlin(),
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DAnnotation -> copy(
+ documentation = appendSinceKotlin(),
+ classlikes = classlikes.map { it.transform() as DClasslike },
+ functions = functions.map { it.transform() as DFunction },
+ properties = properties.map { it.transform() as DProperty }
+ )
+ is DFunction -> copy(
+ documentation = appendSinceKotlin()
+ )
+ is DProperty -> copy(
+ documentation = appendSinceKotlin()
+ )
+ is DParameter -> copy(
+ documentation = appendSinceKotlin()
+ )
+ else -> this.also { context.logger.warn("Unrecognized documentable $this while SinceKotlin transformation") }
+ }
+
+ private fun Documentable.appendSinceKotlin() =
+ sourceSets.fold(documentation) { acc, sourceSet ->
+ safeAs<WithExtraProperties<Documentable>>()?.extra?.get(Annotations)?.content?.get(sourceSet)?.find {
+ it.dri == DRI("kotlin", "SinceKotlin")
+ }?.params?.get("version").safeAs<StringValue>()?.value?.let { version ->
+ acc.mapValues {
+ if (it.key == sourceSet) it.value.copy(
+ it.value.children + listOf(
+ CustomTagWrapper(Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' }), "Since Kotlin")
+ )
+ ) else it.value
+ }
+ } ?: acc
+ }
+} \ No newline at end of file