Skip to content

Commit cc459b0

Browse files
committed
Remove variance modifier rendering if it absent
1 parent 3fc052e commit cc459b0

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/signatures/KotlinSignatureProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public class KotlinSignatureProvider(
434434
}
435435

436436
is Variance<*> -> group(styles = emptySet()) {
437-
keyword("$p ".takeIf { it.isNotBlank() } ?: "")
437+
p.takeIf { it.toString().isNotEmpty() }?.let { keyword("$it ") }
438438
signatureForProjection(p.inner, showFullyQualifiedName)
439439
}
440440

dokka-subprojects/plugin-base/src/test/kotlin/signatures/SignatureTest.kt

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,27 @@ class SignatureTest : BaseAbstractTest() {
197197
}
198198
}
199199

200+
@Test
201+
fun `fun with use site variance modifier in`() {
202+
val source = source("fun simpleFun(params: Array<in String>): Unit")
203+
val writerPlugin = TestOutputWriterPlugin()
204+
205+
testInline(
206+
source,
207+
configuration,
208+
pluginOverrides = listOf(writerPlugin)
209+
) {
210+
renderingStage = { _, _ ->
211+
writerPlugin.writer.renderedContent("root/example/simple-fun.html").firstSignature().match(
212+
"fun ", A("simpleFun"), "(", Parameters(
213+
Parameter("params: ", A("Array"), "<in ", A("String"), ">"),
214+
), ")",
215+
ignoreSpanWithTokenStyle = true
216+
)
217+
}
218+
}
219+
}
220+
200221
@Test
201222
fun `fun with definitely non-nullable types`() {
202223
val source = source("fun <T> elvisLike(x: T, y: T & Any): T & Any = x ?: y")
@@ -312,6 +333,28 @@ class SignatureTest : BaseAbstractTest() {
312333
}
313334
}
314335

336+
@Test
337+
fun `class with declaration site variance modifier`() {
338+
val writerPlugin = TestOutputWriterPlugin()
339+
340+
testInline(
341+
"""
342+
|/src/main/kotlin/common/Test.kt
343+
|package example
344+
|
345+
|class PrimaryConstructorClass<out T> { }
346+
""".trimMargin(),
347+
configuration,
348+
pluginOverrides = listOf(writerPlugin)
349+
) {
350+
renderingStage = { _, _ ->
351+
writerPlugin.writer.renderedContent("root/example/-primary-constructor-class/index.html").firstSignature().match(
352+
Span("class "), A("PrimaryConstructorClass"), Span("<"), Span("out "), A("T"), Span(">"),
353+
)
354+
}
355+
}
356+
}
357+
315358
@Test
316359
fun `functional interface`() {
317360
val source = source("fun interface KRunnable")
@@ -896,8 +939,7 @@ class SignatureTest : BaseAbstractTest() {
896939
) {
897940
renderingStage = { _, _ ->
898941
writerPlugin.writer.renderedContent("root/example/-primary-constructor-class/index.html").firstSignature().match(
899-
// In `<T>` expression, an empty `<span class="token keyword"></span>` is present for some reason
900-
Span("class "), A("PrimaryConstructorClass"), Span("<"), Span(), A("T"), Span(">"), Span("("), Parameters(
942+
Span("class "), A("PrimaryConstructorClass"), Span("<"), A("T"), Span(">"), Span("("), Parameters(
901943
Parameter(Span("val "), "x", Span(": "), A("Int"), Span(",")),
902944
Parameter(Span("var "), "s", Span(": "), A("String"))
903945
), Span(")"),

0 commit comments

Comments
 (0)