1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
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 signatures.signature
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")
),
")",
ignoreSpanWithTokenStyle = true
)
}
}
}
@Test
fun `should display annotations`() {
val writerPlugin = TestOutputWriterPlugin()
testInline(
"""
|/src/main/kotlin/kotlinAsJavaPlugin/Test.kt
|package kotlinAsJavaPlugin
|
|@MustBeDocumented
|annotation class OnClass
|
|@MustBeDocumented
|annotation class OnMethod
|
|@MustBeDocumented
|annotation class OnParameter
|
|@Target(AnnotationTarget.TYPE)
|@MustBeDocumented
|annotation class OnType
|
|@Target(AnnotationTarget.TYPE_PARAMETER)
|@MustBeDocumented
|annotation class OnTypeParameter
|
|@OnClass
|class Clazz<@OnTypeParameter T : @OnType Any> {
| @OnMethod
| fun <@OnTypeParameter T : @OnType Any> withParams(@OnParameter str1: String, str2: String): Boolean {
| return str1 == str2
| }
|}
""".trimIndent(),
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
val signatures = writerPlugin.writer
.renderedContent("root/kotlinAsJavaPlugin/-clazz/index.html")
.signature()
val classSignature = signatures[0]
classSignature.match(
Div(Div("@", A("OnClass"), "()")),
"public final class ", A("Clazz"),
// <@OnTypeParameter() T extends @OnType() Object>
"<", Span("@", A("OnTypeParameter"), "() "), "T extends ", Span("@", A("OnType"), "() "), A("Object"), ">",
ignoreSpanWithTokenStyle = true
)
val functionSignature = signatures[2]
functionSignature.match(
Div(Div("@", A("OnMethod"), "()")),
"public final ", A("Boolean"), A("withParams"),
// <@OnTypeParameter() T extends @OnType() Object>
"<", Span("@", A("OnTypeParameter"), "() "), "T extends ", Span("@", A("OnType"), "() "), A("Any"), ">(",
Span(
Span(
Span("@", A("OnParameter"), "() "),
A("String"), "str1, "
),
Span(
A("String"), "str2"
)
), ")",
ignoreSpanWithTokenStyle = true
)
}
}
}
}
|