1 package kotlinx.atomicfu.test
2 
3 import org.junit.Test
4 import kotlin.reflect.*
5 import kotlin.reflect.full.*
6 import kotlin.reflect.jvm.*
7 import kotlin.test.*
8 
9 /**
10  * Make sure metadata is intact after transformation.
11  */
12 class ReflectionTest {
13     @Test
testReflectionnull14     fun testReflection() {
15         val f =
16             Class.forName("kotlinx.atomicfu.test.LockTestKt")
17                 .methods
18                 .single { it.name == "reflectionTest" }
19                 .kotlinFunction ?: error("Kotlin function is not found")
20         assertEquals(2, f.typeParameters.size)
21         val tp0 = f.typeParameters[0]
22         assertEquals("AA", tp0.name)
23         val tp1 = f.typeParameters[1]
24         assertEquals("BB", tp1.name)
25         val r = f.extensionReceiverParameter
26             ?: error("extensionReceiverParameter not found")
27         assertEquals("kotlin.String", r.type.toString())
28         assertEquals(2, f.parameters.size)
29         val p = f.parameters[1]
30         assertEquals("mapParam", p.name)
31         assertEquals("class kotlin.collections.Map", p.type.classifier.toString())
32         assertEquals(2, p.type.arguments.size)
33         val ta0 = p.type.arguments[0]
34         assertEquals(KVariance.IN, ta0.variance)
35         val ta0c = ta0.type!!.classifier as KTypeParameter
36         assertEquals("AA", ta0c.name)
37     }
38 }