Support annotations on class type parameters

#KT-43714
This commit is contained in:
Mikhael Bogdanov
2021-05-21 20:48:21 +02:00
parent 9091ca7b51
commit a8186d19d6
18 changed files with 222 additions and 57 deletions
@@ -3,6 +3,7 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// EMIT_JVM_TYPE_ANNOTATIONS
// !LANGUAGE: +ClassTypeParameterAnnotations
// JVM_TARGET: 1.8
// WITH_REFLECT
// FULL_JDK
@@ -29,41 +30,36 @@ class SimpleClass
interface Generic<G>
class GenericClass<G>
@Suppress("UNSUPPORTED")
class SimpleParameter<@TypeParameterAnn @TypeParameterAnnBinary T> {}
@Suppress("UNSUPPORTED")
class InterfaceBound<@TypeParameterAnn T : @TypeAnn("Simple") Simple> {}
@Suppress("UNSUPPORTED")
class ClassBound<@TypeParameterAnn T : @TypeAnn("Simple") SimpleClass>
class InterfaceBoundGeneric<T : @TypeAnn("Generic") Generic<@TypeAnn("Simple") Simple>> {}
class ClassBoundGeneric<T : @TypeAnn("GenericClass") GenericClass<@TypeAnn("SimpleClass") SimpleClass>>
@Suppress("UNSUPPORTED")
class TypeParameterAsBound<Y, @TypeParameterAnn T : @TypeAnn("Y as Bound") Y>
fun box(): String {
//foo
// checkTypeParameterAnnotation(
// SimpleParameter::class.java.typeParameters.single(),
// "T",
// "@foo.TypeParameterAnn()",
// "foo"
// )
checkTypeParameterAnnotation(
SimpleParameter::class.java.typeParameters.single(),
"T",
"@foo.TypeParameterAnn()",
"foo"
)
//interfaceBound
val interfaceBound = InterfaceBound::class.java
// checkTypeParameterAnnotation(
// InterfaceBound.typeParameters.single(),
// "T",
// "@foo.TypeParameterAnn()",
// "interfaceBound type parameter"
// )
checkTypeParameterAnnotation(
interfaceBound.typeParameters.single(),
"T",
"@foo.TypeParameterAnn()",
"interfaceBound type parameter"
)
checkTypeAnnotation(
interfaceBound.typeParameters.single().annotatedBounds.single(),
@@ -74,12 +70,12 @@ fun box(): String {
//classBound
val classBound = ClassBound::class.java
// checkTypeParameterAnnotation(
// classBound.typeParameters.single(),
// "T",
// "@foo.TypeParameterAnn()",
// "classBound type parameter"
// )
checkTypeParameterAnnotation(
classBound.typeParameters.single(),
"T",
"@foo.TypeParameterAnn()",
"classBound type parameter"
)
checkTypeAnnotation(
classBound.typeParameters.single().annotatedBounds.single(),
@@ -91,12 +87,12 @@ fun box(): String {
//interfaceBoundGeneric
val interfaceBoundGeneric = InterfaceBoundGeneric::class.java
// checkTypeAnnotation(
// interfaceBoundGeneric.typeParameters.single().annotatedBounds.single(),
// "foo.Generic<foo.Simple>",
// "@foo.TypeAnn(name=Generic)",
// "interfaceBoundGeneric bound"
// )
checkTypeAnnotation(
interfaceBoundGeneric.typeParameters.single().annotatedBounds.single(),
"foo.Generic<foo.Simple>",
"@foo.TypeAnn(name=Generic)",
"interfaceBoundGeneric bound"
)
checkTypeAnnotation(
(interfaceBoundGeneric.typeParameters.single().annotatedBounds.single() as AnnotatedParameterizedType).getAnnotatedActualTypeArguments().single(),
@@ -124,12 +120,12 @@ fun box(): String {
//typeParameterTypeParameterBound
val typeParameterTypeParameterBound = TypeParameterAsBound::class.java
// checkTypeParameterAnnotation(
// typeParameterTypeParameterBound.typeParameters[1]!!,
// "T",
// "@foo.TypeParameterAnn()",
// "typeParameterTypeParameterBound type parameter"
// )
checkTypeParameterAnnotation(
typeParameterTypeParameterBound.typeParameters[1]!!,
"T",
"@foo.TypeParameterAnn()",
"typeParameterTypeParameterBound type parameter"
)
// Works on JDK 15
// checkTypeAnnotation(
// typeParameterTypeParameterBound.typeParameters[1]!!.annotatedBounds.single(),
@@ -1,3 +1,4 @@
// !LANGUAGE: -ClassTypeParameterAnnotations
annotation class A1
annotation class A2(val some: Int = 12)
@@ -1,3 +1,4 @@
// !LANGUAGE: -ClassTypeParameterAnnotations
annotation class A1
annotation class A2(val some: Int = 12)
@@ -0,0 +1,24 @@
// !LANGUAGE: +ClassTypeParameterAnnotations
annotation class A1
annotation class A2(val some: Int = 12)
@Target(AnnotationTarget.TYPE)
annotation class TA1
@Target(AnnotationTarget.TYPE_PARAMETER)
annotation class TA2(val some: Int = 12)
class TopLevelClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> {
class InnerClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> {
fun test() {
class InFun<@A1 @A2(3) @A2 @A1(12) @A2("Test") T>
}
}
}
class TTopLevelClass<@TA1 @TA2(3) @TA2 @TA1(12) @TA2("Test") T> {
class TInnerClass<@TA1 @TA2(3) @TA2 @TA1(12) @TA2("Test") T> {
fun test() {
class TInFun<@TA1 @TA2(3) @TA2 @TA1(12) @TA2("Test") T>
}
}
}
@@ -0,0 +1,25 @@
// !LANGUAGE: +ClassTypeParameterAnnotations
annotation class A1
annotation class A2(val some: Int = 12)
@Target(AnnotationTarget.TYPE)
annotation class TA1
@Target(AnnotationTarget.TYPE_PARAMETER)
annotation class TA2(val some: Int = 12)
class TopLevelClass<<!WRONG_ANNOTATION_TARGET!>@A1<!> <!WRONG_ANNOTATION_TARGET!>@A2(3)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2(<!TYPE_MISMATCH!>"Test"<!>)<!> T> {
class InnerClass<<!WRONG_ANNOTATION_TARGET!>@A1<!> <!WRONG_ANNOTATION_TARGET!>@A2(3)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2(<!TYPE_MISMATCH!>"Test"<!>)<!> T> {
fun test() {
class InFun<<!WRONG_ANNOTATION_TARGET!>@A1<!> <!WRONG_ANNOTATION_TARGET!>@A2(3)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@A2(<!TYPE_MISMATCH!>"Test"<!>)<!> T>
}
}
}
class TTopLevelClass<<!WRONG_ANNOTATION_TARGET!>@TA1<!> @TA2(3) <!REPEATED_ANNOTATION!>@TA2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@TA1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION!>@TA2(<!TYPE_MISMATCH!>"Test"<!>)<!> T> {
class TInnerClass<<!WRONG_ANNOTATION_TARGET!>@TA1<!> @TA2(3) <!REPEATED_ANNOTATION!>@TA2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@TA1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION!>@TA2(<!TYPE_MISMATCH!>"Test"<!>)<!> T> {
fun test() {
class TInFun<<!WRONG_ANNOTATION_TARGET!>@TA1<!> @TA2(3) <!REPEATED_ANNOTATION!>@TA2<!> <!REPEATED_ANNOTATION, WRONG_ANNOTATION_TARGET!>@TA1(<!TOO_MANY_ARGUMENTS!>12<!>)<!> <!REPEATED_ANNOTATION!>@TA2(<!TYPE_MISMATCH!>"Test"<!>)<!> T>
}
}
}
@@ -0,0 +1,62 @@
package
public final annotation class A1 : kotlin.Annotation {
public constructor A1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final annotation class A2 : kotlin.Annotation {
public constructor A2(/*0*/ some: kotlin.Int = ...)
public final val some: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class TA1 : kotlin.Annotation {
public constructor TA1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER}) public final annotation class TA2 : kotlin.Annotation {
public constructor TA2(/*0*/ some: kotlin.Int = ...)
public final val some: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class TTopLevelClass</*0*/ @TA1 @TA2(some = 3) @TA2 @TA1 @TA2(some = "Test") T> {
public constructor TTopLevelClass</*0*/ @TA1 @TA2(some = 3) @TA2 @TA1 @TA2(some = "Test") T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final class TInnerClass</*0*/ @TA1 @TA2(some = 3) @TA2 @TA1 @TA2(some = "Test") T> {
public constructor TInnerClass</*0*/ @TA1 @TA2(some = 3) @TA2 @TA1 @TA2(some = "Test") T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class TopLevelClass</*0*/ @A1 @A2(some = 3) @A2 @A1 @A2(some = "Test") T> {
public constructor TopLevelClass</*0*/ @A1 @A2(some = 3) @A2 @A1 @A2(some = "Test") T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final class InnerClass</*0*/ @A1 @A2(some = 3) @A2 @A1 @A2(some = "Test") T> {
public constructor InnerClass</*0*/ @A1 @A2(some = 3) @A2 @A1 @A2(some = "Test") T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}