Files
kotlin-fork/compiler/testData/codegen/box/reflection/annotations/findAnnotation.kt
T
Alexander Udalov 0a6d010d1c Support new repeatable annotations in kotlin-reflect
- Unwrap Kotlin-repeatable annotations (with implicit container)
- Introduce `KAnnotatedElement.findAnnotations` to find instances of
  repeated annotations

 #KT-12794
2021-07-30 19:53:33 +02:00

29 lines
695 B
Kotlin
Vendored

// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS_IR_ES6
// IGNORE_BACKEND: JS, NATIVE
// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi
// WITH_REFLECT
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.findAnnotations
import kotlin.test.assertEquals
import kotlin.test.assertNull
annotation class Yes(val value: String)
annotation class No(val value: String)
@Yes("OK")
@No("Fail")
class Foo
class Bar
fun box(): String {
assertNull(Bar::class.findAnnotation<Yes>())
assertNull(Bar::class.findAnnotation<No>())
assertEquals("OK", Foo::class.findAnnotations<Yes>().single().value)
return Foo::class.findAnnotation<Yes>()?.value ?: "Fail: no annotation"
}