aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2020-12-29 14:38:19 +0100
committerGitHub <noreply@github.com>2020-12-29 14:38:19 +0100
commitf5e7cffbebb66b989c64bdda61e1f7809ddc6068 (patch)
treeea0ef4b550f9a55681a915d5cb4d9f1beca22041 /core/src/main
parente55f3b015faec3f62e829a2aa5984e4bd6d5037e (diff)
downloaddokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.tar.gz
dokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.tar.bz2
dokka-f5e7cffbebb66b989c64bdda61e1f7809ddc6068.zip
Parsing of JvmName (#1675)
* Parsing of JvmName * Make JvmName processor run after KaJ
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/model/additionalExtras.kt34
-rw-r--r--core/src/main/kotlin/model/jvmName.kt7
2 files changed, 37 insertions, 4 deletions
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<Set<ExtraModifiers>>)
fun SourceSetDependent<Set<ExtraModifiers>>.toAdditionalModifiers() = AdditionalModifiers(this)
-class Annotations(val content: SourceSetDependent<List<Annotation>>) : ExtraProperty<Documentable> {
+data class Annotations(
+ private val myContent: SourceSetDependent<List<Annotation>>
+) : ExtraProperty<Documentable> {
companion object : ExtraProperty.Key<Documentable, Annotations> {
override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy<Documentable> =
- MergeStrategy.Replace(Annotations(left.content + right.content))
+ MergeStrategy.Replace(Annotations(left.myContent + right.myContent))
}
override val key: ExtraProperty.Key<Documentable, *> = Annotations
- data class Annotation(val dri: DRI, val params: Map<String, AnnotationParameterValue>, val mustBeDocumented: Boolean = false) {
+ data class Annotation(
+ val dri: DRI,
+ val params: Map<String, AnnotationParameterValue>,
+ 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<List<Annotation>>) : ExtraProp
override fun hashCode(): Int = dri.hashCode()
}
+
+ @Deprecated("Use directAnnotations or fileLevelAnnotations")
+ val content: SourceSetDependent<List<Annotation>>
+ get() = myContent
+
+ val directAnnotations: SourceSetDependent<List<Annotation>> = annotationsByScope(AnnotationScope.DIRECT)
+
+ val fileLevelAnnotations: SourceSetDependent<List<Annotation>> = annotationsByScope(AnnotationScope.FILE)
+
+ private fun annotationsByScope(scope: AnnotationScope): SourceSetDependent<List<Annotation>> =
+ 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<List<Annotations.Annotation>>.toAnnotations() = Annotations(this)
@@ -65,7 +91,7 @@ data class ActualTypealias(val underlyingType: SourceSetDependent<Bound>) : Extr
override val key: ExtraProperty.Key<DClasslike, ActualTypealias> = ActualTypealias
}
-data class ConstructorValues(val values: SourceSetDependent<List<String>>) : ExtraProperty<DEnumEntry>{
+data class ConstructorValues(val values: SourceSetDependent<List<String>>) : ExtraProperty<DEnumEntry> {
companion object : ExtraProperty.Key<DEnumEntry, ConstructorValues> {
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()