Generate Java @Repeatable on Kotlin-repeatable annotation classes

#KT-12794
This commit is contained in:
Alexander Udalov
2021-07-22 21:41:24 +02:00
parent 92a73d7636
commit 26043f3968
8 changed files with 93 additions and 5 deletions
@@ -0,0 +1,43 @@
// !LANGUAGE: +RepeatableAnnotations
// TARGET_BACKEND: JVM_IR
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
// IGNORE_BACKEND: ANDROID
// FILE: box.kt
@Repeatable
annotation class A(val value: String)
fun box(): String {
val annotations = Z::class.java.annotations
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: Z.java
@A("O")
@A("")
@A("K")
public class Z {}
// FILE: ContainerSupport.java
import java.lang.annotation.Annotation;
public class ContainerSupport {
public static A[] load(Annotation container) {
return ((A.Container) container).value();
}
}
@@ -8,6 +8,7 @@ public annotation class test/A$Container {
@kotlin.annotation.Repeatable
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Repeatable(value=test.A$Container::class)
@kotlin.Metadata
public annotation class test/A {
// source: 'kotlinAnnotation.kt'
@@ -12,6 +12,7 @@ public annotation class test/A$Container {
@kotlin.annotation.Target(allowedTargets=[FILE, TYPEALIAS])
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Target(value=[])
@java.lang.annotation.Repeatable(value=test.A$Container::class)
@kotlin.Metadata
public annotation class test/A {
// source: 'kotlinSpecificTargets.kt'
@@ -8,6 +8,7 @@ public annotation class test/A$Container {
@kotlin.annotation.Repeatable
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Repeatable(value=test.A$Container::class)
@kotlin.Metadata
public annotation class test/A {
// source: 'multipleRepeatableOrder.kt'
@@ -25,6 +26,7 @@ public annotation class test/B$Container {
@kotlin.annotation.Repeatable
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Repeatable(value=test.B$Container::class)
@kotlin.Metadata
public annotation class test/B {
// source: 'multipleRepeatableOrder.kt'
@@ -42,6 +44,7 @@ public annotation class test/C$Container {
@kotlin.annotation.Repeatable
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Repeatable(value=test.C$Container::class)
@kotlin.Metadata
public annotation class test/C {
// source: 'multipleRepeatableOrder.kt'
@@ -10,6 +10,7 @@ public annotation class RetentionBinary$Container {
@kotlin.annotation.Repeatable
@kotlin.annotation.Retention(value=BINARY)
@java.lang.annotation.Retention(value=CLASS)
@java.lang.annotation.Repeatable(value=RetentionBinary$Container::class)
@kotlin.Metadata
public annotation class RetentionBinary {
// source: 'retentionAndTarget.kt'
@@ -26,6 +27,7 @@ public annotation class RetentionRuntime$Container {
@kotlin.annotation.Repeatable
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Repeatable(value=RetentionRuntime$Container::class)
@kotlin.Metadata
public annotation class RetentionRuntime {
// source: 'retentionAndTarget.kt'
@@ -44,6 +46,7 @@ public annotation class RetentionSource$Container {
@kotlin.annotation.Repeatable
@kotlin.annotation.Retention(value=SOURCE)
@java.lang.annotation.Retention(value=SOURCE)
@java.lang.annotation.Repeatable(value=RetentionSource$Container::class)
@kotlin.Metadata
public annotation class RetentionSource {
// source: 'retentionAndTarget.kt'
@@ -64,6 +67,7 @@ public annotation class TargetAnnotationClassAndTypeOnly$Container {
@kotlin.annotation.Target(allowedTargets=[ANNOTATION_CLASS, TYPE])
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Target(value=[ANNOTATION_TYPE, TYPE_USE])
@java.lang.annotation.Repeatable(value=TargetAnnotationClassAndTypeOnly$Container::class)
@kotlin.Metadata
public annotation class TargetAnnotationClassAndTypeOnly {
// source: 'retentionAndTarget.kt'
@@ -84,6 +88,7 @@ public annotation class TargetClassOnly$Container {
@kotlin.annotation.Target(allowedTargets=[CLASS])
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Target(value=[TYPE])
@java.lang.annotation.Repeatable(value=TargetClassOnly$Container::class)
@kotlin.Metadata
public annotation class TargetClassOnly {
// source: 'retentionAndTarget.kt'
@@ -104,6 +109,7 @@ public annotation class TargetEmpty$Container {
@kotlin.annotation.Target(allowedTargets=[])
@java.lang.annotation.Retention(value=RUNTIME)
@java.lang.annotation.Target(value=[])
@java.lang.annotation.Repeatable(value=TargetEmpty$Container::class)
@kotlin.Metadata
public annotation class TargetEmpty {
// source: 'retentionAndTarget.kt'