From f5e7cffbebb66b989c64bdda61e1f7809ddc6068 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Tue, 29 Dec 2020 14:38:19 +0100 Subject: Parsing of JvmName (#1675) * Parsing of JvmName * Make JvmName processor run after KaJ --- core/src/main/kotlin/model/additionalExtras.kt | 34 +++++++++++++++++++++++--- core/src/main/kotlin/model/jvmName.kt | 7 ++++++ 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 core/src/main/kotlin/model/jvmName.kt (limited to 'core/src/main') diff --git a/core/src/main/kotlin/model/additionalExtras.kt b/core/src/main/kotlin/model/additionalExtras.kt index 94d0e751..2308b641 100644 --- a/core/src/main/kotlin/model/additionalExtras.kt +++ b/core/src/main/kotlin/model/additionalExtras.kt @@ -21,15 +21,22 @@ class AdditionalModifiers(val content: SourceSetDependent>) fun SourceSetDependent>.toAdditionalModifiers() = AdditionalModifiers(this) -class Annotations(val content: SourceSetDependent>) : ExtraProperty { +data class Annotations( + private val myContent: SourceSetDependent> +) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy = - MergeStrategy.Replace(Annotations(left.content + right.content)) + MergeStrategy.Replace(Annotations(left.myContent + right.myContent)) } override val key: ExtraProperty.Key = Annotations - data class Annotation(val dri: DRI, val params: Map, val mustBeDocumented: Boolean = false) { + data class Annotation( + val dri: DRI, + val params: Map, + val mustBeDocumented: Boolean = false, + val scope: AnnotationScope = AnnotationScope.DIRECT + ) { override fun equals(other: Any?): Boolean = when (other) { is Annotation -> dri == other.dri else -> false @@ -37,6 +44,25 @@ class Annotations(val content: SourceSetDependent>) : ExtraProp override fun hashCode(): Int = dri.hashCode() } + + @Deprecated("Use directAnnotations or fileLevelAnnotations") + val content: SourceSetDependent> + get() = myContent + + val directAnnotations: SourceSetDependent> = annotationsByScope(AnnotationScope.DIRECT) + + val fileLevelAnnotations: SourceSetDependent> = annotationsByScope(AnnotationScope.FILE) + + private fun annotationsByScope(scope: AnnotationScope): SourceSetDependent> = + myContent.entries.mapNotNull { (key, value) -> + val withoutFileLevel = value.filter { it.scope == scope } + if (withoutFileLevel.isEmpty()) null + else Pair(key, withoutFileLevel) + }.toMap() + + enum class AnnotationScope { + DIRECT, FILE + } } fun SourceSetDependent>.toAnnotations() = Annotations(this) @@ -65,7 +91,7 @@ data class ActualTypealias(val underlyingType: SourceSetDependent) : Extr override val key: ExtraProperty.Key = ActualTypealias } -data class ConstructorValues(val values: SourceSetDependent>) : ExtraProperty{ +data class ConstructorValues(val values: SourceSetDependent>) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor(left: ConstructorValues, right: ConstructorValues) = MergeStrategy.Replace(ConstructorValues(left.values + right.values)) diff --git a/core/src/main/kotlin/model/jvmName.kt b/core/src/main/kotlin/model/jvmName.kt new file mode 100644 index 00000000..a9f23bf0 --- /dev/null +++ b/core/src/main/kotlin/model/jvmName.kt @@ -0,0 +1,7 @@ +package org.jetbrains.dokka.model + +import org.jetbrains.dokka.links.DRI + +fun DRI.isJvmName(): Boolean = packageName == "kotlin.jvm" && classNames == "JvmName" + +fun Annotations.Annotation.isJvmName(): Boolean = dri.isJvmName() -- cgit