Introduce KAnnotatedElement and val annotations: List<Annotation>
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Anno
|
||||
|
||||
fun box(): String {
|
||||
val a = Anno::class.annotations
|
||||
/*
|
||||
// TODO: support kotlin.annotation.annotation
|
||||
if (a.size() != 1) return "Fail 1: $a"
|
||||
val ann = a.single() as? annotation ?: return "Fail 2: ${a.single()}"
|
||||
assertEquals(AnnotationRetention.RUNTIME, ann.retention)
|
||||
*/
|
||||
assert(a.isEmpty())
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
annotation class Get
|
||||
annotation class Set
|
||||
annotation class SetParam
|
||||
|
||||
var foo: String
|
||||
@Get get() = ""
|
||||
@Set set(@SetParam value) {}
|
||||
|
||||
fun box(): String {
|
||||
assert(::foo.getter.annotations.single() is Get)
|
||||
assert(::foo.setter.annotations.single() is Set)
|
||||
assert(::foo.setter.parameters.single().annotations.single() is SetParam)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
annotation class Ann(val value: String)
|
||||
|
||||
@Ann("OK")
|
||||
val property: String
|
||||
get() = ""
|
||||
|
||||
fun box(): String {
|
||||
return (::property.annotations.single() as Ann).value
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation(retention = AnnotationRetention.SOURCE) class SourceAnno
|
||||
annotation(retention = AnnotationRetention.BINARY) class BinaryAnno
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class RuntimeAnno
|
||||
|
||||
@SourceAnno
|
||||
@BinaryAnno
|
||||
@RuntimeAnno
|
||||
fun box(): String {
|
||||
assertEquals(listOf(javaClass<RuntimeAnno>()), ::box.annotations.map { it.annotationType() })
|
||||
return "OK"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
return (A::class.annotations.single() as Simple).value
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
annotation class Primary
|
||||
annotation class Secondary
|
||||
|
||||
class C @Primary constructor() {
|
||||
@Secondary
|
||||
constructor(s: String): this()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ans = C::class.constructors.map { it.annotations.single().annotationType().simpleName }.toSortedList()
|
||||
if (ans != listOf("Primary", "Secondary")) return "Fail: $ans"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
fun box(): String {
|
||||
return (::box.annotations.single() as Simple).value
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Simple(val value: String)
|
||||
|
||||
fun test(@Simple("OK") x: Int) {}
|
||||
|
||||
fun box(): String {
|
||||
return (::test.parameters.single().annotations.single() as Simple).value
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
val foo: Int = 0
|
||||
|
||||
fun box(): String {
|
||||
return (::foo.annotations.single() as Simple).value
|
||||
}
|
||||
Reference in New Issue
Block a user