diff options
Diffstat (limited to 'plugins/base/src')
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt | 22 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/signatures/SignatureTest.kt | 34 |
2 files changed, 55 insertions, 1 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index a2624da0..d17fa276 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -8,6 +8,7 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.drisOfAllNestedBounds import org.jetbrains.dokka.model.AnnotationTarget +import org.jetbrains.dokka.model.doc.DocumentationNode interface JvmSignatureUtils { @@ -23,6 +24,19 @@ interface JvmSignatureUtils { fun <T : AnnotationTarget> WithExtraProperties<T>.annotations(): SourceSetDependent<List<Annotations.Annotation>> = extra[Annotations]?.directAnnotations ?: emptyMap() + @Suppress("UNCHECKED_CAST") + operator fun <T : Iterable<*>> SourceSetDependent<T>.plus(other: SourceSetDependent<T>): SourceSetDependent<T> = + LinkedHashMap(this).apply { + for ((k, v) in other) { + put(k, get(k).let { if (it != null) (it + v) as T else v }) + } + } + + fun DProperty.annotations(): SourceSetDependent<List<Annotations.Annotation>> = + (extra[Annotations]?.directAnnotations ?: emptyMap()) + + (getter?.annotations() ?: emptyMap()).mapValues { it.value.map { it.copy( scope = Annotations.AnnotationScope.GETTER) } } + + (setter?.annotations() ?: emptyMap()).mapValues { it.value.map { it.copy( scope = Annotations.AnnotationScope.SETTER) } } + private fun PageContentBuilder.DocumentableContentBuilder.annotations( d: AnnotationTarget, ignored: Set<Annotations.Annotation>, @@ -65,7 +79,13 @@ interface JvmSignatureUtils { ) { when (renderAtStrategy) { - is All, is OnlyOnce -> text("@") + is All, is OnlyOnce -> { + text("@") + when(a.scope) { + Annotations.AnnotationScope.GETTER -> text("get:") + Annotations.AnnotationScope.SETTER -> text("set:") + } + } is Never -> Unit } link(a.dri.classNames!!, a.dri) diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index 35590d52..a56c408b 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -280,6 +280,40 @@ class SignatureTest : BaseAbstractTest() { } @Test + fun `property with annotation`() { + val source = """ + |/src/main/kotlin/test/Test.kt + |package example + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking + | + | @get:Marking() + | @set:Marking() + | var str: String + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/str.html").firstSignature().match( + Div( + Div("@get:", A("Marking")), + Div("@set:", A("Marking")) + ), + "var ", A("str"), + ": ", A("String"), Span() + ) + } + } + } + + @Test fun `fun with two annotations`() { val source = """ |/src/main/kotlin/test/Test.kt |