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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package basic
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.*
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.Nullable
import org.jetbrains.dokka.links.TypeConstructor
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.pages.ClasslikePageNode
import org.jetbrains.dokka.pages.ContentPage
import org.jetbrains.dokka.pages.MemberPageNode
import kotlin.test.Test
import kotlin.test.assertEquals
class DRITest : BaseAbstractTest() {
@Test
fun issue634() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|package toplevel
|
|inline fun <T, R : Comparable<R>> Array<out T>.mySortBy(
| crossinline selector: (T) -> R?): Array<out T> = TODO()
|}
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
val expected = TypeConstructor(
"kotlin.Function1", listOf(
TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))),
Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(RecursiveType(0))))))
)
)
val actual = module.packages.single()
.functions.single()
.dri.callable?.params?.single()
assertEquals(expected, actual)
}
}
}
@Test
fun issue634WithImmediateNullableSelf() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|package toplevel
|
|fun <T : Comparable<T>> Array<T>.doSomething(t: T?): Array<T> = TODO()
|}
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(RecursiveType(0))))))
val actual = module.packages.single()
.functions.single()
.dri.callable?.params?.single()
assertEquals(expected, actual)
}
}
}
@Test
fun issue634WithGenericNullableReceiver() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/basic/Test.kt
|package toplevel
|
|fun <T : Comparable<T>> T?.doSomethingWithNullable() = TODO()
|}
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(RecursiveType(0))))))
val actual = module.packages.single()
.functions.single()
.dri.callable?.receiver
assertEquals(expected, actual)
}
}
}
@Test
fun issue642WithStarAndAny() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
analysisPlatform = "js"
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|
|open class Bar<Z>
|class ReBarBar : Bar<StringBuilder>()
|class Foo<out T : Comparable<*>, R : List<Bar<*>>>
|
|fun <T : Comparable<Any?>> Foo<T, *>.qux(): String = TODO()
|fun <T : Comparable<*>> Foo<T, *>.qux(): String = TODO()
|
""".trimMargin(),
configuration
) {
pagesGenerationStage = { module ->
// DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),*]#/PointingToFunctionOrClasslike/)
val expectedDRI = DRI(
"",
null,
Callable(
"qux", TypeConstructor(
"Foo", listOf(
TypeParam(
listOf(
TypeConstructor(
"kotlin.Comparable", listOf(
Nullable(TypeConstructor("kotlin.Any", emptyList()))
)
)
)
),
StarProjection
)
),
emptyList()
)
)
val driCount = module
.withDescendants()
.filterIsInstance<ContentPage>()
.sumBy { it.dri.count { dri -> dri == expectedDRI } }
assertEquals(1, driCount)
}
}
}
@Test
fun driForGenericClass(){
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|package example
|
|class Sample<S>(first: S){ }
|
|
""".trimMargin(),
configuration
) {
pagesGenerationStage = { module ->
val sampleClass = module.dfs { it.name == "Sample" } as ClasslikePageNode
val classDocumentable = sampleClass.documentables.firstOrNull() as DClass
assertEquals( "example/Sample///PointingToDeclaration/", sampleClass.dri.first().toString())
assertEquals("example/Sample///PointingToGenericParameters(0)/", classDocumentable.generics.first().dri.toString())
}
}
}
@Test
fun driForGenericFunction(){
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath = listOfNotNull(jvmStdlibPath)
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|package example
|
|class Sample<S>(first: S){
| fun <T> genericFun(param1: String): Tuple<S,T> = TODO()
|}
|
|
""".trimMargin(),
configuration
) {
pagesGenerationStage = { module ->
val sampleClass = module.dfs { it.name == "Sample" } as ClasslikePageNode
val functionNode = sampleClass.children.first { it.name == "genericFun" } as MemberPageNode
val functionDocumentable = functionNode.documentables.firstOrNull() as DFunction
val parameter = functionDocumentable.parameters.first()
assertEquals("example/Sample/genericFun/#kotlin.String/PointingToDeclaration/", functionNode.dri.first().toString())
assertEquals(1, functionDocumentable.parameters.size)
assertEquals("example/Sample/genericFun/#kotlin.String/PointingToCallableParameters(0)/", parameter.dri.toString())
//1 since from the function's perspective there is only 1 new generic declared
//The other one is 'inherited' from class
assertEquals( 1, functionDocumentable.generics.size)
assertEquals( "T", functionDocumentable.generics.first().name)
assertEquals( "example/Sample/genericFun/#kotlin.String/PointingToGenericParameters(0)/", functionDocumentable.generics.first().dri.toString())
}
}
}
@Test
fun driForFunctionNestedInsideInnerClass() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
classpath = listOfNotNull(jvmStdlibPath)
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|package example
|
|class Sample<S>(first: S){
| inner class SampleInner {
| fun foo(): S = TODO()
| }
|}
|
|
""".trimMargin(),
configuration
) {
pagesGenerationStage = { module ->
val sampleClass = module.dfs { it.name == "Sample" } as ClasslikePageNode
val sampleInner = sampleClass.children.first { it.name == "SampleInner" } as ClasslikePageNode
val foo = sampleInner.children.first { it.name == "foo" } as MemberPageNode
val documentable = foo.documentables.firstOrNull() as DFunction
val generics = (sampleClass.documentables.firstOrNull() as WithGenerics).generics
assertEquals(generics.first().dri.toString(), (documentable.type as TypeParameter).dri.toString())
assertEquals(0, documentable.generics.size)
}
}
}
@Test
fun driForGenericExtensionFunction(){
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|package example
|
| fun <T> List<T>.extensionFunction(): String = ""
|
""".trimMargin(),
configuration
) {
pagesGenerationStage = { module ->
val extensionFunction = module.dfs { it.name == "extensionFunction" } as MemberPageNode
val documentable = extensionFunction.documentables.firstOrNull() as DFunction
assertEquals(
"example//extensionFunction/kotlin.collections.List[TypeParam(bounds=[kotlin.Any?])]#/PointingToDeclaration/",
extensionFunction.dri.first().toString()
)
assertEquals(1, documentable.generics.size)
assertEquals("T", documentable.generics.first().name)
assertEquals(
"example//extensionFunction/kotlin.collections.List[TypeParam(bounds=[kotlin.Any?])]#/PointingToGenericParameters(0)/",
documentable.generics.first().dri.toString()
)
}
}
}
@Test
fun `deep recursive typebound #1342`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
testInline(
"""
|/src/main/kotlin/Test.kt
|package example
|
| fun <T, S, R> recursiveBound(t: T, s: S, r: R) where T: List<S>, S: List<R>, R: List<S> = Unit
|
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
val function = module.dfs { it.name == "recursiveBound" }
assertEquals(
"example//recursiveBound/#TypeParam(bounds=[kotlin.collections.List[TypeParam(bounds=[kotlin.collections.List[TypeParam(bounds=[kotlin.collections.List[^^]])]])]])#TypeParam(bounds=[kotlin.collections.List[TypeParam(bounds=[kotlin.collections.List[^]])]])#TypeParam(bounds=[kotlin.collections.List[TypeParam(bounds=[kotlin.collections.List[^]])]])/PointingToDeclaration/",
function?.dri?.toString(),
)
}
}
}
}
|