mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 15:53:46 +00:00
Delete the old ones in package kotlin.reflect.jvm because otherwise the code using those functions will become red in a lot less meaningful way (overload resolution ambiguity) than if they're deleted (unresolved import) Based on the work originally done by @dnpetrov #KT-8380 Fixed
30 lines
929 B
Kotlin
Vendored
30 lines
929 B
Kotlin
Vendored
import java.lang.reflect.Method
|
|
import kotlin.test.assertEquals
|
|
|
|
target(AnnotationTarget.EXPRESSION)
|
|
annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String)
|
|
|
|
fun foo0(block: () -> Unit) = block.javaClass
|
|
|
|
fun testMethod(method: Method, name: String) {
|
|
assertEquals("OK", method.getAnnotation(javaClass<Ann>()).x, "On method of test named `$name`")
|
|
|
|
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
|
val ann = annotations.filterIsInstance<Ann>().single()
|
|
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
|
}
|
|
}
|
|
|
|
fun testClass(clazz: Class<*>, name: String) {
|
|
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
|
testMethod(invokes, name)
|
|
}
|
|
|
|
fun box(): String {
|
|
testClass(foo0(@Ann("OK") { }), "1")
|
|
testClass(foo0( @Ann("OK") { }), "2")
|
|
|
|
testClass(foo0() @Ann("OK") { }, "3")
|
|
return "OK"
|
|
}
|