Generate container class for repeatable annotations
#KT-12794
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// !LANGUAGE: +RepeatableAnnotations
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
|
||||
// IGNORE_BACKEND: ANDROID
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
@Repeatable
|
||||
annotation class A(val value: String)
|
||||
|
||||
@A("O")
|
||||
@A("")
|
||||
@A("K")
|
||||
class Z
|
||||
|
||||
fun box(): String {
|
||||
val annotations = Z::class.java.annotations.filter { it.annotationClass != Metadata::class }
|
||||
val aa = annotations.singleOrNull() ?: return "Fail 1: $annotations"
|
||||
|
||||
val a = ContainerSupport.load(aa)
|
||||
if (a.size != 3) return "Fail 2: $a"
|
||||
|
||||
val bytype = Z::class.java.getAnnotationsByType(A::class.java)
|
||||
if (a.toList() != bytype.toList()) return "Fail 3: ${a.toList()} != ${bytype.toList()}"
|
||||
|
||||
return a.fold("") { acc, it -> acc + it.value }
|
||||
}
|
||||
|
||||
// FILE: ContainerSupport.java
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class ContainerSupport {
|
||||
public static A[] load(Annotation container) {
|
||||
return ((A.Container) container).value();
|
||||
}
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// !LANGUAGE: +RepeatableAnnotations
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
|
||||
// IGNORE_BACKEND: ANDROID
|
||||
|
||||
@Repeatable
|
||||
@java.lang.annotation.Repeatable(As::class)
|
||||
annotation class A(val value: String)
|
||||
|
||||
annotation class As(val value: Array<A>)
|
||||
|
||||
@A("O")
|
||||
@A("")
|
||||
@A("K")
|
||||
class Z
|
||||
|
||||
fun box(): String {
|
||||
val annotations = Z::class.java.annotations.filter { it.annotationClass != Metadata::class }
|
||||
val aa = annotations.singleOrNull() ?: return "Fail 1: $annotations"
|
||||
if (aa !is As) return "Fail 2: $aa"
|
||||
|
||||
val a = aa.value.asList()
|
||||
if (a.size != 3) return "Fail 3: $a"
|
||||
|
||||
val bytype = Z::class.java.getAnnotationsByType(A::class.java)
|
||||
if (a.toList() != bytype.toList()) return "Fail 4: ${a.toList()} != ${bytype.toList()}"
|
||||
|
||||
return a.fold("") { acc, it -> acc + it.value }
|
||||
}
|
||||
Reference in New Issue
Block a user