Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support definitely non-nullable types (#2520)
* Support definitely non-nullable types [Definitely non-nullable types](https://github.com/Kotlin/KEEP/blob/c72601cf35c1e95a541bb4b230edb474a6d1d1a8/proposals/definitely-non-nullable-types.md) are enabled since Kotlin 1.7
- Loading branch information
Showing
12 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaSignatureTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} | ||
} | ||
} | ||
} |