Map Kotlin TYPE target to Java TYPE_USE in bytecode
And TYPE_PARAMETER -> TYPE_PARAMETER similarly #KT-23857 Fixed
This commit is contained in:
@@ -228,6 +228,8 @@ public abstract class AnnotationCodegen {
|
||||
annotationTargetMap.put(KotlinTarget.PROPERTY_SETTER, ElementType.METHOD);
|
||||
annotationTargetMap.put(KotlinTarget.FIELD, ElementType.FIELD);
|
||||
annotationTargetMap.put(KotlinTarget.VALUE_PARAMETER, ElementType.PARAMETER);
|
||||
annotationTargetMap.put(KotlinTarget.TYPE_PARAMETER, ElementType.TYPE_PARAMETER);
|
||||
annotationTargetMap.put(KotlinTarget.TYPE, ElementType.TYPE_USE);
|
||||
}
|
||||
|
||||
private void generateTargetAnnotation(@NotNull ClassDescriptor classDescriptor, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
@kotlin.annotation.Repeatable
|
||||
@java.lang.annotation.Documented
|
||||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
|
||||
@java.lang.annotation.Target({})
|
||||
@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE_PARAMETER})
|
||||
public @interface Anno {
|
||||
int i();
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// FILE: A.java
|
||||
import java.util.List;
|
||||
|
||||
public class A<@Anno(1) T> {}
|
||||
|
||||
// FILE: Anno.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.TYPE_PARAMETER)
|
||||
annotation class Anno(val value: Int = 0)
|
||||
|
||||
fun box(): String {
|
||||
val typeParameter = A::class.java.typeParameters.single()
|
||||
assertEquals("[@Anno(value=1)]", typeParameter.annotations.toList().toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// FILE: A.java
|
||||
import java.util.List;
|
||||
|
||||
public class A {
|
||||
public static @Anno(1) String test(List<@Anno(2) String> list) {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Anno.kt
|
||||
|
||||
import java.lang.reflect.AnnotatedParameterizedType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Anno(val value: Int = 0)
|
||||
|
||||
fun box(): String {
|
||||
val method = A::class.java.declaredMethods.single()
|
||||
assertEquals("[@Anno(value=1)]", method.annotatedReturnType.annotations.toList().toString())
|
||||
|
||||
val parameterType = method.parameters.single().annotatedType as AnnotatedParameterizedType
|
||||
assertEquals("[@Anno(value=2)]", parameterType.annotatedActualTypeArguments.single().annotations.toList().toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Generated
+23
@@ -133,6 +133,29 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
runTest("compiler/testData/codegen/java8/box/useStream.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/box/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Annotations extends AbstractBlackBoxCodegenTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInAnnotations() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/annotations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("useTypeParameterAnnotationFromJava.kt")
|
||||
public void testUseTypeParameterAnnotationFromJava() throws Exception {
|
||||
runTest("compiler/testData/codegen/java8/box/annotations/useTypeParameterAnnotationFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("useTypeUseAnnotationFromJava.kt")
|
||||
public void testUseTypeUseAnnotationFromJava() throws Exception {
|
||||
runTest("compiler/testData/codegen/java8/box/annotations/useTypeUseAnnotationFromJava.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/java8/box/builtinStubMethods")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user