d99ffbd120
Create a supertype for all Kotlin annotations, jet.Annotation. Map java.lang.annotation.Annotation to jet.Annotation and vice versa. Add extension function "annotationType()" to every annotation, similar to java.lang.annotation.Annotation.annotationType() #KT-1620 Fixed
37 lines
842 B
Kotlin
37 lines
842 B
Kotlin
package test.annotations
|
|
|
|
import kotlin.*
|
|
import kotlin.test.assertTrue
|
|
import org.junit.Test as test
|
|
import java.lang.annotation.*
|
|
|
|
|
|
Retention(RetentionPolicy.RUNTIME)
|
|
annotation class MyAnno
|
|
|
|
MyAnno
|
|
Deprecated
|
|
class AnnotatedClass
|
|
|
|
|
|
class AnnotationTest {
|
|
test fun annotationType() {
|
|
val annotations = javaClass<AnnotatedClass>().getAnnotations()!!
|
|
|
|
var foundMyAnno = false
|
|
var foundDeprecated = false
|
|
|
|
for (annotation in annotations) {
|
|
val clazz = annotation!!.annotationType()
|
|
when {
|
|
clazz == javaClass<MyAnno>() -> foundMyAnno = true
|
|
clazz == javaClass<Deprecated>() -> foundDeprecated = true
|
|
else -> {}
|
|
}
|
|
}
|
|
|
|
assertTrue(foundMyAnno)
|
|
assertTrue(foundDeprecated)
|
|
}
|
|
}
|