Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
import org.jetbrains.dokka.links.DriOfUnit

public val jvmNameProvider: JvmNameProvider = JvmNameProvider()
internal const val OBJECT_INSTANCE_NAME = "INSTANCE"
Expand Down Expand Up @@ -206,7 +207,7 @@ public class KotlinToJavaConverter(
return copy(
dri = dri.copy(classNames = containingClassName, callable = dri.callable?.copy(name = newName)),
name = newName,
type = type.asJava(),
type = type.asJava(unitAsVoid = true),
modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Final } && isConstructor)
sourceSets.associateWith { JavaModifier.Empty }
else sourceSets.associateWith { modifier.values.first() },
Expand Down Expand Up @@ -338,12 +339,16 @@ public class KotlinToJavaConverter(
is Bound -> asJava()
}

private fun Bound.asJava(): Bound = when (this) {
private fun Bound.asJava(unitAsVoid: Boolean = false): Bound = when (this) {
is TypeParameter -> copy(dri.possiblyAsJava())
is GenericTypeConstructor -> copy(
dri = dri.possiblyAsJava(),
projections = projections.map { it.asJava() }
)
is GenericTypeConstructor -> if (unitAsVoid && dri == DriOfUnit) {
Void
} else {
copy(
dri = dri.possiblyAsJava(),
projections = projections.map { it.asJava() }
)
}

is FunctionalTypeConstructor -> copy(
dri = dri.possiblyAsJava(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ class KotlinAsJavaSignatureTest : BaseAbstractTest() {
}
}

@Test
fun `unit displayed as void`() {
val source = source("fun returnsUnit(): Unit {}")
val writerPlugin = TestOutputWriterPlugin()

testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
val signature = writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test-kt/returns-unit.html").firstSignature()
signature.match(
"public final static void ", A("returnsUnit"), "()",
ignoreSpanWithTokenStyle = true
)
}
}
}

@Test
fun `should display annotations`() {
val writerPlugin = TestOutputWriterPlugin()
Expand Down