Test kotlin-repeatable annotations on Android
(except for type-use annotations)
This commit is contained in:
+6
@@ -40147,6 +40147,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotation.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kotlinAnnotationOnType.kt")
|
||||||
|
public void testKotlinAnnotationOnType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotationOnType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt49335.kt")
|
@TestMetadata("kt49335.kt")
|
||||||
public void testKt49335() throws Exception {
|
public void testKt49335() throws Exception {
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
// Android doesn't have @Repeatable, so findAnnotations can't unpack repeatable annotations.
|
// Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations.
|
||||||
// IGNORE_BACKEND: ANDROID
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
import kotlin.reflect.full.findAnnotation
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|||||||
+1
-7
@@ -4,9 +4,6 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
// Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Native crash''. Check device logcat for details
|
|
||||||
// IGNORE_BACKEND: ANDROID
|
|
||||||
|
|
||||||
import kotlin.annotation.AnnotationTarget.*
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
import kotlin.reflect.KAnnotatedElement
|
import kotlin.reflect.KAnnotatedElement
|
||||||
import kotlin.reflect.full.findAnnotation
|
import kotlin.reflect.full.findAnnotation
|
||||||
@@ -30,7 +27,7 @@ fun check(element: KAnnotatedElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Repeatable
|
@Repeatable
|
||||||
@Target(CLASS, FUNCTION, PROPERTY, TYPE)
|
@Target(CLASS, FUNCTION, PROPERTY)
|
||||||
annotation class A(val value: String)
|
annotation class A(val value: String)
|
||||||
|
|
||||||
@A("O") @A("") @A("K")
|
@A("O") @A("") @A("K")
|
||||||
@@ -42,12 +39,9 @@ var p = 1
|
|||||||
@A("O") @A("K")
|
@A("O") @A("K")
|
||||||
class Z
|
class Z
|
||||||
|
|
||||||
fun g(): @A("O") @A("K") @A("") Unit {}
|
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
check(::f)
|
check(::f)
|
||||||
check(::p)
|
check(::p)
|
||||||
check(Z::class)
|
check(Z::class)
|
||||||
check(::g.returnType)
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
// !LANGUAGE: +RepeatableAnnotations
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// FULL_JDK
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
// Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Native crash''. Check device logcat for details
|
||||||
|
// Because TYPE_USE is not avaiable before API level 26
|
||||||
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
|
import kotlin.reflect.KAnnotatedElement
|
||||||
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
import kotlin.reflect.full.findAnnotations
|
||||||
|
import kotlin.reflect.full.hasAnnotation
|
||||||
|
|
||||||
|
fun check(element: KAnnotatedElement) {
|
||||||
|
if (!element.hasAnnotation<A>()) throw AssertionError("Fail hasAnnotation $element")
|
||||||
|
|
||||||
|
val find = element.findAnnotation<A>()
|
||||||
|
if (find == null || find.value != "O") throw AssertionError("Fail findAnnotation $element: $find")
|
||||||
|
|
||||||
|
val all = element.annotations
|
||||||
|
val findAll = element.findAnnotations<A>()
|
||||||
|
if (all != findAll) throw AssertionError("Fail findAnnotations $element: $all != $findAll")
|
||||||
|
|
||||||
|
if (all.any { it !is A })
|
||||||
|
throw AssertionError("Fail 1 $element: $all")
|
||||||
|
if (all.fold("") { acc, it -> acc + (it as A).value } != "OK")
|
||||||
|
throw AssertionError("Fail 2 $element: $all")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Repeatable
|
||||||
|
@Target(CLASS, FUNCTION, PROPERTY, TYPE)
|
||||||
|
annotation class A(val value: String)
|
||||||
|
|
||||||
|
fun g(): @A("O") @A("K") @A("") Unit {}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
check(::g.returnType)
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
// Android doesn't have @Repeatable, so findAnnotations can't unpack repeatable annotations.
|
// Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations.
|
||||||
// IGNORE_BACKEND: ANDROID
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
|
|
||||||
// Android doesn't have @Repeatable.
|
// Android doesn't have @Repeatable before API level 24.
|
||||||
// IGNORE_BACKEND: ANDROID
|
// IGNORE_BACKEND: ANDROID
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|||||||
+6
@@ -40147,6 +40147,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotation.kt");
|
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kotlinAnnotationOnType.kt")
|
||||||
|
public void testKotlinAnnotationOnType() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/annotations/repeatable/kotlinAnnotationOnType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt49335.kt")
|
@TestMetadata("kt49335.kt")
|
||||||
public void testKt49335() throws Exception {
|
public void testKt49335() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user