diff options
author | Ignat Beresnev <ignat@beresnev.me> | 2022-01-27 12:56:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 12:56:27 +0300 |
commit | e0a10c24ea7e623137f2ab21522ed0f84bf59814 (patch) | |
tree | c863973a41efccb4ad34858c88b885e5370b2dbd /plugins/kotlin-as-java/src | |
parent | 7c44db1ef0075e2b80a4723e0747bbf57c32e775 (diff) | |
download | dokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.tar.gz dokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.tar.bz2 dokka-e0a10c24ea7e623137f2ab21522ed0f84bf59814.zip |
KT-50292 - Implement vertical alignment of parameters (#2309)
* Implement vertical alignment (wrapping) of parameters for kt
* Add tests for params wrapping and extend matchers to check for classes
* Add distinguishable parameters block to kotlinAsJava, extract common logic
* Create a separate Kind for symbol function parameters
Diffstat (limited to 'plugins/kotlin-as-java/src')
-rw-r--r-- | plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt | 19 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 81 |
2 files changed, 76 insertions, 24 deletions
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 65b34017..fa1f668f 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -8,10 +8,7 @@ import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties -import org.jetbrains.dokka.pages.ContentKind -import org.jetbrains.dokka.pages.ContentNode -import org.jetbrains.dokka.pages.TextStyle -import org.jetbrains.dokka.pages.TokenStyle +import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle @@ -143,12 +140,14 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte +buildSignature(it) } punctuation("(") - list(f.parameters, separatorStyles = mainStyles + TokenStyle.Punctuation) { - annotationsInline(it) - text(it.modifiers()[sourceSet]?.toSignatureString() ?: "", styles = mainStyles + TokenStyle.Keyword) - signatureForProjection(it.type) - text(nbsp.toString()) - text(it.name!!) + if (f.parameters.isNotEmpty()) { + parametersBlock(f) { + annotationsInline(it) + text(it.modifiers()[sourceSet]?.toSignatureString() ?: "", styles = mainStyles + TokenStyle.Keyword) + signatureForProjection(it.type) + text(nbsp.toString()) + text(it.name!!) + } } punctuation(")") } diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 5fcb22aa..b9627f9b 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -1,20 +1,19 @@ package kotlinAsJavaPlugin -import org.jetbrains.dokka.model.dfs -import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.kotlin.utils.addToStdlib.cast -import org.junit.jupiter.api.Test import matchers.content.* import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.jdk +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.pages.* +import org.jetbrains.kotlin.utils.addToStdlib.cast import org.junit.Assert +import org.junit.jupiter.api.Test +import signatures.Parameter +import signatures.Parameters import signatures.renderedContent import signatures.signature -import utils.A -import utils.Span -import utils.TestOutputWriterPlugin -import utils.match +import utils.* import kotlin.test.assertEquals class KotlinAsJavaPluginTest : BaseAbstractTest() { @@ -331,7 +330,9 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { ) { renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( - "final ", A("Integer"), A("someFun"), "(", A("Integer"), "xd)", Span(), ignoreSpanWithTokenStyle = true + "final ", A("Integer"), A("someFun"), "(", Parameters( + Parameter(A("Integer"), "xd") + ), ")", Span(), ignoreSpanWithTokenStyle = true ) } } @@ -368,8 +369,9 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { ) { renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( - "final ", A("Integer"), A("someFun"), "(", A("Map"), "<", A("String"), - ", ", A("Integer"), "> xd)", Span(), ignoreSpanWithTokenStyle = true + "final ", A("Integer"), A("someFun"), "(", Parameters( + Parameter(A("Map"), "<", A("String"), ", ", A("Integer"), "> xd"), + ), ")", Span(), ignoreSpanWithTokenStyle = true ) } } @@ -433,7 +435,9 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { ) { renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test-kt/sample.html").signature().first().match( - "final static ", A("String"), A("sample"), "(", A("Integer"), "a)", Span(), ignoreSpanWithTokenStyle = true + "final static ", A("String"), A("sample"), "(", Parameters( + Parameter(A("Integer"), "a"), + ), ")", Span(), ignoreSpanWithTokenStyle = true ) } } @@ -476,7 +480,56 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() { } renderingStage = { _, _ -> writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test/-test.html").signature().first().match( - A("Test"), A("Test"), "(", A("Integer"), "xd)", Span(), ignoreSpanWithTokenStyle = true + A("Test"), A("Test"), "(", Parameters( + Parameter(A("Integer"), "xd") + ), ")", Span(), ignoreSpanWithTokenStyle = true + ) + } + } + } + + @Test + fun `should add wrapping and indent to parameters if too many`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + externalDocumentationLinks = listOf( + DokkaConfiguration.ExternalDocumentationLink.jdk(8), + stdlibExternalDocumentationLink + ) + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Wrapped.kt + |package kotlinAsJavaPlugin + | + |class Wrapped(val xd: Int, val l: Long, val s: String) + """.trimMargin(), + configuration, + pluginOverrides = listOf(writerPlugin), + cleanupOutput = true + ) { + pagesGenerationStage = { root -> + val content = root.children + .flatMap { it.children<ContentPage>() } + .map { it.content }.single().mainContents + + val text = content.single { it is ContentHeader }.children + .single() as ContentText + + assertEquals("Constructors", text.text) + } + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-wrapped/-wrapped.html").signature().first().match( + A("Wrapped"), A("Wrapped"), "(", Parameters( + Parameter(A("Integer"), "xd,").withClasses("indented"), + Parameter(A("Long"), "l,").withClasses("indented"), + Parameter(A("String"), "s").withClasses("indented"), + ).withClasses("wrapped"), ")", Span(), ignoreSpanWithTokenStyle = true ) } } |