Annotations on type aliases: generate synthetic method for type alias annotations.

This commit is contained in:
Dmitry Petrov
2016-10-10 17:13:48 +03:00
parent d2d8f72ffc
commit 3d0288ffed
11 changed files with 144 additions and 31 deletions
@@ -0,0 +1,31 @@
// WITH_RUNTIME
// FULL_JDK
import kotlin.annotation.AnnotationTarget.*
import kotlin.annotation.AnnotationRetention.*
import java.lang.Class
@Target(TYPEALIAS)
@Retention(RUNTIME)
annotation class Ann(val x: Int)
class C {
@Ann(1)
typealias TA = Any
}
@Ann(2)
typealias TA = Any
fun Class<*>.assertHasDeclaredMethodWithAnn() {
if (!declaredMethods.any { it.isSynthetic && it.getAnnotation(Ann::class.java) != null }) {
throw java.lang.AssertionError("Class ${this.simpleName} has no declared method with annotation @Ann")
}
}
fun box(): String {
Class.forName("AnnotationsOnTypeAliasesKt").assertHasDeclaredMethodWithAnn()
Class.forName("C").assertHasDeclaredMethodWithAnn()
return "OK"
}