mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Save annotations of lambda on SAM's method
Also add tests checking that annotations on 'invoke' methods of common lambdas are saved properly #KT-6932 Fixed
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import java.lang.Runnable;
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import java.lang.annotation.*
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
Retention(RetentionPolicy.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
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(Test.apply(@Ann("OK") {}), "1")
|
||||
testClass(Test.apply @Ann("OK") {}, "2")
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user