diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-06-22 17:14:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-22 17:14:58 +0200 |
commit | fb589740213286cc5c2f240f248a10752187a9d7 (patch) | |
tree | 7e4d0e6b2568a4f001a3aa1aab608f5c60368c1b /plugins | |
parent | 3f4336d5dfc2dbeee3d4f51b576cfa7c8568b759 (diff) | |
download | dokka-fb589740213286cc5c2f240f248a10752187a9d7.tar.gz dokka-fb589740213286cc5c2f240f248a10752187a9d7.tar.bz2 dokka-fb589740213286cc5c2f240f248a10752187a9d7.zip |
Render annotations for KaJ signatures (#2549)
Fixes #2527
Diffstat (limited to 'plugins')
3 files changed, 83 insertions, 3 deletions
diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt index 3562fb8e..e1ae5029 100644 --- a/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt +++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt @@ -67,4 +67,4 @@ private fun List<Node>.uniteConsecutiveTextNodes(): MutableList<Node> { } else resList.add(item) } return resList - }
\ No newline at end of file + } diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt index cff5b182..b21745a9 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -64,6 +64,7 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte setOf(TextStyle.Monospace) + deprecationStyles, sourceSets = setOf(sourceSet) ) { + annotationsBlock(c) c.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.plus(" ")?.let { keyword(it) } if (c is DClass) { @@ -161,6 +162,7 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte private fun signature(t: DTypeParameter) = t.sourceSets.map { contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) { + annotationsInline(t) text(t.name.substringAfterLast(".")) list(t.bounds, prefix = " extends ", separatorStyles = mainStyles + TokenStyle.Punctuation, @@ -172,9 +174,13 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte } private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) { - is TypeParameter -> link(p.name, p.dri) + is TypeParameter -> { + annotationsInline(p) + link(p.name, p.dri) + } is TypeConstructor -> group(styles = emptySet()) { + annotationsInline(p) link(p.dri.classNames.orEmpty(), p.dri) list(p.projections, prefix = "<", suffix = ">", separatorStyles = mainStyles + TokenStyle.Punctuation, diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt index 5f755ff3..5ce3ac41 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.dokka.jdk import org.junit.jupiter.api.Test import signatures.firstSignature import signatures.renderedContent +import signatures.signature import utils.* class KotlinAsJavaSignatureTest : BaseAbstractTest() { @@ -56,4 +57,77 @@ class KotlinAsJavaSignatureTest : BaseAbstractTest() { } } } -}
\ No newline at end of file + + @Test + fun `should display annotations`() { + val writerPlugin = TestOutputWriterPlugin() + + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |@MustBeDocumented + |annotation class OnClass + | + |@MustBeDocumented + |annotation class OnMethod + | + |@MustBeDocumented + |annotation class OnParameter + | + |@Target(AnnotationTarget.TYPE) + |@MustBeDocumented + |annotation class OnType + | + |@Target(AnnotationTarget.TYPE_PARAMETER) + |@MustBeDocumented + |annotation class OnTypeParameter + | + |@OnClass + |class Clazz<@OnTypeParameter T : @OnType Any> { + | @OnMethod + | fun <@OnTypeParameter T : @OnType Any> withParams(@OnParameter str1: String, str2: String): Boolean { + | return str1 == str2 + | } + |} + """.trimIndent(), + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val signatures = writerPlugin.writer + .renderedContent("root/kotlinAsJavaPlugin/-clazz/index.html") + .signature() + + val classSignature = signatures[0] + classSignature.match( + Div(Div("@", A("OnClass"), "()")), + "public final class ", A("Clazz"), + // <@OnTypeParameter() T extends @OnType() Object> + "<", Span("@", A("OnTypeParameter"), "() "), "T extends ", Span("@", A("OnType"), "() "), A("Object"), ">", + Span(), + ignoreSpanWithTokenStyle = true + ) + + val functionSignature = signatures[2] + functionSignature.match( + Div(Div("@", A("OnMethod"), "()")), + "public final ", A("Boolean"), A("withParams"), + // <@OnTypeParameter() T extends @OnType() Object> + "<", Span("@", A("OnTypeParameter"), "() "), "T extends ", Span("@", A("OnType"), "() "), A("Any"), ">(", + Span( + Span( + Span("@", A("OnParameter"), "() "), + A("String"), "str1, " + ), + Span( + A("String"), "str2" + ) + ), ")", Span(), + ignoreSpanWithTokenStyle = true + ) + } + } + } +} |