Files
kotlin/compiler/testData/codegen/box/reflection/createAnnotation/enumKClassAnnotation.kt
Alexander Udalov c357967c2c JVM IR: generate Kotlin metadata
Introduce MetadataSource as a way to store the original descriptor for
any element (before any lowerings) and maintain it until the end of the
codegen where it's used in generating the metadata. Note that JVM
signatures written to the metadata are formed from the _resulting_
generated elements, not by mapping the original descriptors.

Some corner cases are not supported yet, namely properties declared in
companion objects, synthetic methods for property annotations,
JvmPackageName, etc.

 #KT-29119 Fixed
2019-02-19 16:37:47 +01:00

53 lines
1.6 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT
package test
import kotlin.reflect.KClass
import kotlin.test.assertEquals
annotation class Foo(val value: String)
annotation class Anno(
val level: DeprecationLevel,
val klass: KClass<*>,
val foo: Foo,
val levels: Array<DeprecationLevel>,
val klasses: Array<KClass<*>>,
val foos: Array<Foo>
)
@Anno(
DeprecationLevel.WARNING,
Number::class,
Foo("OK"),
arrayOf(DeprecationLevel.WARNING),
arrayOf(Number::class),
arrayOf(Foo("OK"))
)
fun foo() {}
fun box(): String {
// Construct an annotation with exactly the same parameters, check that the proxy created by Kotlin and by Java reflection are the same and have the same hash code
val a1 = Anno::class.constructors.single().call(
DeprecationLevel.WARNING,
Number::class,
Foo::class.constructors.single().call("OK"),
arrayOf(DeprecationLevel.WARNING),
arrayOf(Number::class),
arrayOf(Foo::class.constructors.single().call("OK"))
)
val a2 = ::foo.annotations.single() as Anno
assertEquals(a1, a2)
assertEquals(a2, a1)
assertEquals(a1.hashCode(), a2.hashCode())
assertEquals("@test.Anno(level=WARNING, klass=class java.lang.Number, foo=@test.Foo(value=OK), " +
"levels=[WARNING], klasses=[class java.lang.Number], foos=[@test.Foo(value=OK)])", a1.toString())
return "OK"
}