blob: e88d7353ac9fbd69bbda70ab659ae2c4ea49ecc3 (
plain)
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
|
package model.annotations
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Annotations
import org.jetbrains.dokka.model.DFunction
import org.jetbrains.dokka.model.DProperty
import org.jetbrains.dokka.model.GenericTypeConstructor
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
import kotlin.test.assertEquals
class KotlinAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/annotations/Test.kt", "annotations") {
@Test
fun `generic receiver with annotations`() {
inlineModelTest(
"""
|@Target(AnnotationTarget.TYPE_PARAMETER)
|annotation class Hello(val bar: String)
|fun <@Hello("abc") T> foo(arg: String): List<T> = TODO()
""".trimIndent()
) {
with((this / "annotations" / "foo").cast<DFunction>()) {
val annotations = generics.first().extra[Annotations]?.directAnnotations?.flatMap { it.value }
val driOfHello = DRI("annotations", "Hello")
val annotationsValues = annotations?.flatMap { it.params.values }?.map { it.toString() }?.toList()
assertEquals(listOf(driOfHello), annotations?.map { it.dri })
assertEquals(listOf("abc"), annotationsValues)
}
}
}
@Test
fun `generic receiver with annotated bounds`() {
inlineModelTest(
"""
|@Target(AnnotationTarget.TYPE_PARAMETER)
|annotation class Hello(val bar: String)
|fun <T: @Hello("abc") String> foo(arg: String): List<T> = TODO()
""".trimIndent()
) {
with((this / "annotations" / "foo").cast<DFunction>()) {
val annotations = (generics.first().bounds.first() as GenericTypeConstructor)
.extra[Annotations]?.directAnnotations?.flatMap { it.value }
val driOfHello = DRI("annotations", "Hello")
val annotationsValues = annotations?.flatMap { it.params.values }?.map { it.toString() }?.toList()
assertEquals(listOf(driOfHello), annotations?.map { it.dri })
assertEquals(listOf("abc"), annotationsValues)
}
}
}
}
|