diff options
Diffstat (limited to 'plugins/kotlin-as-java/src')
3 files changed, 61 insertions, 0 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 8ff35781..4a21aeae 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -305,6 +305,7 @@ private fun Bound.asJava(): Bound = when (this) { inner = inner.asJava() ) is Nullable -> copy(inner.asJava()) + is DefinitelyNonNullable -> copy(inner.asJava()) is PrimitiveJavaType -> this is Void -> this is JavaObject -> this 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 2b56a2bf..50dbc1cb 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -196,6 +196,7 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte is Star -> operator("?") is Nullable -> signatureForProjection(p.inner) + is DefinitelyNonNullable -> signatureForProjection(p.inner) is JavaObject, is Dynamic -> link("Object", DRI("java.lang", "Object")) is Void -> text("void") diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt new file mode 100644 index 00000000..5f755ff3 --- /dev/null +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt @@ -0,0 +1,59 @@ +package kotlinAsJavaPlugin + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.jdk +import org.junit.jupiter.api.Test +import signatures.firstSignature +import signatures.renderedContent +import utils.* + +class KotlinAsJavaSignatureTest : BaseAbstractTest() { + + private val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + externalDocumentationLinks = listOf( + DokkaConfiguration.ExternalDocumentationLink.jdk(8), + stdlibExternalDocumentationLink + ) + } + } + } + + @Suppress("SameParameterValue") + private fun source(signature: String) = + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + | $signature + """.trimIndent() + + @Test + fun `fun with definitely non-nullable types as java`() { + val source = source("fun <T> elvisLike(x: T, y: T & Any): T & Any = x ?: y") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val signature = writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-test-kt/elvis-like.html").firstSignature() + signature.match( + "public final static ", Span("T"), A("elvisLike"), + "<T extends ", A("Any"), ">(", + Span( + Span(Span(), " x, "), + Span(Span(), " y") + ), + ")", Span(), + ignoreSpanWithTokenStyle = true + ) + } + } + } +}
\ No newline at end of file |