aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/pages/annotations
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/transformers/pages/annotations
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages/annotations')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt186
1 files changed, 0 insertions, 186 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
deleted file mode 100644
index 9ff5960d..00000000
--- a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.pages.annotations
-
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.Platform
-import org.jetbrains.dokka.analysis.markdown.jb.MARKDOWN_ELEMENT_FILE_NAME
-import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.annotations
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.doc.CustomDocTag
-import org.jetbrains.dokka.model.doc.CustomTagWrapper
-import org.jetbrains.dokka.model.doc.DocumentationNode
-import org.jetbrains.dokka.model.doc.Text
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-import org.jetbrains.dokka.utilities.associateWithNotNull
-
-public class SinceKotlinVersion(str: String) : Comparable<SinceKotlinVersion> {
- private val parts: List<Int> = str.split(".").map { it.toInt() }
-
- /**
- * Corner case: 1.0 == 1.0.0
- */
- override fun compareTo(other: SinceKotlinVersion): Int {
- val i1 = parts.listIterator()
- val i2 = other.parts.listIterator()
-
- while (i1.hasNext() || i2.hasNext()) {
- val diff = (if (i1.hasNext()) i1.next() else 0) - (if (i2.hasNext()) i2.next() else 0)
- if (diff != 0) return diff
- }
-
- return 0
- }
-
- override fun toString(): String = parts.joinToString(".")
-}
-
-public class SinceKotlinTransformer(
- public val context: DokkaContext
-) : DocumentableTransformer {
-
- private val minSinceKotlinVersionOfPlatform = mapOf(
- Platform.common to SinceKotlinVersion("1.0"),
- Platform.jvm to SinceKotlinVersion("1.0"),
- Platform.js to SinceKotlinVersion("1.1"),
- Platform.native to SinceKotlinVersion("1.3"),
- Platform.wasm to SinceKotlinVersion("1.8"),
- )
-
- override fun invoke(original: DModule, context: DokkaContext): DModule = original.transform() as DModule
-
- private fun <T : Documentable> T.transform(parent: SourceSetDependent<SinceKotlinVersion>? = null): Documentable {
- val versions = calculateVersions(parent)
- return 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 },
- typealiases = typealiases.map { it.transform() as DTypeAlias }
- )
-
- is DClass -> copy(
- documentation = appendSinceKotlin(versions),
- classlikes = classlikes.map { it.transform(versions) as DClasslike },
- functions = functions.map { it.transform(versions) as DFunction },
- properties = properties.map { it.transform(versions) as DProperty }
- )
-
- is DEnum -> copy(
- documentation = appendSinceKotlin(versions),
- classlikes = classlikes.map { it.transform(versions) as DClasslike },
- functions = functions.map { it.transform(versions) as DFunction },
- properties = properties.map { it.transform(versions) as DProperty }
- )
-
- is DInterface -> copy(
- documentation = appendSinceKotlin(versions),
- classlikes = classlikes.map { it.transform(versions) as DClasslike },
- functions = functions.map { it.transform(versions) as DFunction },
- properties = properties.map { it.transform(versions) as DProperty }
- )
-
- is DObject -> copy(
- documentation = appendSinceKotlin(versions),
- classlikes = classlikes.map { it.transform(versions) as DClasslike },
- functions = functions.map { it.transform(versions) as DFunction },
- properties = properties.map { it.transform(versions) as DProperty }
- )
-
- is DTypeAlias -> copy(
- documentation = appendSinceKotlin(versions)
- )
-
- is DAnnotation -> copy(
- documentation = appendSinceKotlin(versions),
- classlikes = classlikes.map { it.transform(versions) as DClasslike },
- functions = functions.map { it.transform(versions) as DFunction },
- properties = properties.map { it.transform(versions) as DProperty }
- )
-
- is DFunction -> copy(
- documentation = appendSinceKotlin(versions)
- )
-
- is DProperty -> copy(
- documentation = appendSinceKotlin(versions)
- )
-
- is DParameter -> copy(
- documentation = appendSinceKotlin(versions)
- )
-
- else -> this.also { context.logger.warn("Unrecognized documentable $this while SinceKotlin transformation") }
- }
- }
-
- private fun List<Annotations.Annotation>.findSinceKotlinAnnotation(): Annotations.Annotation? =
- this.find { it.dri.packageName == "kotlin" && it.dri.classNames == "SinceKotlin" }
-
- private fun Documentable.getVersion(sourceSet: DokkaConfiguration.DokkaSourceSet): SinceKotlinVersion {
- val annotatedVersion =
- annotations()[sourceSet]
- ?.findSinceKotlinAnnotation()
- ?.params?.let { it["version"] as? StringValue }?.value
- ?.let { SinceKotlinVersion(it) }
-
- val minSinceKotlin = minSinceKotlinVersionOfPlatform[sourceSet.analysisPlatform]
- ?: throw IllegalStateException("No value for platform: ${sourceSet.analysisPlatform}")
-
- return annotatedVersion?.takeIf { version -> version >= minSinceKotlin } ?: minSinceKotlin
- }
-
-
- private fun Documentable.calculateVersions(parent: SourceSetDependent<SinceKotlinVersion>?): SourceSetDependent<SinceKotlinVersion> {
- return sourceSets.associateWithNotNull { sourceSet ->
- val version = getVersion(sourceSet)
- val parentVersion = parent?.get(sourceSet)
- if (parentVersion != null)
- maxOf(version, parentVersion)
- else
- version
- }
- }
-
- private fun Documentable.appendSinceKotlin(versions: SourceSetDependent<SinceKotlinVersion>) =
- sourceSets.fold(documentation) { acc, sourceSet ->
-
- val version = versions[sourceSet]
-
- val sinceKotlinCustomTag = CustomTagWrapper(
- CustomDocTag(
- listOf(
- Text(
- version.toString()
- )
- ),
- name = MARKDOWN_ELEMENT_FILE_NAME
- ),
- "Since Kotlin"
- )
- if (acc[sourceSet] == null)
- acc + (sourceSet to DocumentationNode(listOf(sinceKotlinCustomTag)))
- else
- acc.mapValues {
- if (it.key == sourceSet) it.value.copy(
- it.value.children + listOf(
- sinceKotlinCustomTag
- )
- ) else it.value
- }
- }
-
- internal companion object {
- internal const val SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP = "dokka.shouldDisplaySinceKotlin"
- internal fun shouldDisplaySinceKotlin() =
- System.getProperty(SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP) in listOf("true", "1")
- }
-}