Support using Java-repeatable annotations in Kotlin

#KT-12794
This commit is contained in:
Alexander Udalov
2021-07-20 16:30:04 +02:00
parent f723389565
commit 87130edfa2
42 changed files with 958 additions and 42 deletions
@@ -0,0 +1,69 @@
// !LANGUAGE: +RepeatableAnnotations
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// FULL_JDK
// JVM_TARGET: 1.8
// FILE: box.kt
package test
import test.A
import test.As
@A("class1") @A("class2")
class Z @A("constructor1") @A("constructor2") constructor() {
@A("nestedClass1") @A("nestedClass2")
annotation class Nested
@A("memberFunction1") @A("memberFunction2")
fun memberFunction() {}
@A("memberProperty1") @A("memberProperty2")
var memberProperty: Int
@A("propertyGetter1") @A("propertyGetter2")
get() = 0
@A("propertySetter1") @A("propertySetter2")
set(value) {}
}
@A("topLevelFunction1") @A("topLevelFunction2")
fun topLevelFunction2(
@A("parameter1") @A("parameter2")
parameter: String
) {}
@A("topLevelProperty1") @A("topLevelProperty2")
var String.z: Z
@A("propertyGetter1") @A("propertyGetter2")
get() = Z()
@A("propertySetter1") @A("propertySetter2")
set(value) {}
@get:A("useSitePropertyGetter1")
@get:A("useSitePropertyGetter2")
@field:A("field1")
@field:A("field2")
val o: String = ""
// FILE: test/A.java
package test;
import java.lang.annotation.*;
@Repeatable(As.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface A {
String value();
}
// FILE: test/As.java
package test;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface As {
A[] value();
}
@@ -0,0 +1,31 @@
@kotlin.Metadata
public final class test/BoxKt {
// source: 'box.kt'
private final static @test.As(value=[test.A(value="field1"), test.A(value="field2")]) @org.jetbrains.annotations.NotNull field o: java.lang.String
static method <clinit>(): void
public final static @test.As(value=[test.A(value="useSitePropertyGetter1"), test.A(value="useSitePropertyGetter2")]) @org.jetbrains.annotations.NotNull method getO(): java.lang.String
public synthetic deprecated static @test.As(value=[test.A(value="topLevelProperty1"), test.A(value="topLevelProperty2")]) method getZ$annotations(p0: java.lang.String): void
public final static @test.As(value=[test.A(value="propertyGetter1"), test.A(value="propertyGetter2")]) @org.jetbrains.annotations.NotNull method getZ(@org.jetbrains.annotations.NotNull p0: java.lang.String): test.Z
public final static @test.As(value=[test.A(value="propertySetter1"), test.A(value="propertySetter2")]) method setZ(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: test.Z): void
public final static @test.As(value=[test.A(value="topLevelFunction1"), test.A(value="topLevelFunction2")]) method topLevelFunction2(@test.As(value=[test.A(value="parameter1"), test.A(value="parameter2")]) @org.jetbrains.annotations.NotNull p0: java.lang.String): void
}
@test.As(value=[test.A(value="nestedClass1"), test.A(value="nestedClass2")])
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class test/Z$Nested {
// source: 'box.kt'
public inner class test/Z$Nested
}
@test.As(value=[test.A(value="class1"), test.A(value="class2")])
@kotlin.Metadata
public final class test/Z {
// source: 'box.kt'
public @test.As(value=[test.A(value="constructor1"), test.A(value="constructor2")]) method <init>(): void
public synthetic deprecated static @test.As(value=[test.A(value="memberProperty1"), test.A(value="memberProperty2")]) method getMemberProperty$annotations(): void
public final @test.As(value=[test.A(value="propertyGetter1"), test.A(value="propertyGetter2")]) method getMemberProperty(): int
public final @test.As(value=[test.A(value="memberFunction1"), test.A(value="memberFunction2")]) method memberFunction(): void
public final @test.As(value=[test.A(value="propertySetter1"), test.A(value="propertySetter2")]) method setMemberProperty(p0: int): void
public inner class test/Z$Nested
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +RepeatableAnnotations
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// FULL_JDK
// JVM_TARGET: 1.8
package test
@java.lang.annotation.Repeatable(As::class)
annotation class A(val value: String)
annotation class As(val value: Array<A>)
@A("1")
@As([A("2"), A("3")])
class Z
@As([A("1"), A("2")])
@A("3")
class ZZ
@@ -0,0 +1,30 @@
@java.lang.annotation.Repeatable(value=test.As::class)
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class test/A {
// source: 'nonRepeatedAnnotationWithItsContainer.kt'
public abstract method value(): java.lang.String
}
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class test/As {
// source: 'nonRepeatedAnnotationWithItsContainer.kt'
public abstract method value(): test.A[]
}
@test.A(value="1")
@test.As(value=[test.A(value="2"), test.A(value="3")])
@kotlin.Metadata
public final class test/Z {
// source: 'nonRepeatedAnnotationWithItsContainer.kt'
public method <init>(): void
}
@test.As(value=[test.A(value="1"), test.A(value="2")])
@test.A(value="3")
@kotlin.Metadata
public final class test/ZZ {
// source: 'nonRepeatedAnnotationWithItsContainer.kt'
public method <init>(): void
}