Support type annotations

#KT-35843 Fixed
This commit is contained in:
Mikhael Bogdanov
2019-12-30 09:12:28 +01:00
parent fde9b21a40
commit 2ed0cb2a89
52 changed files with 1728 additions and 10 deletions

View File

@@ -0,0 +1,76 @@
// KOTLIN_CONFIGURATION_FLAGS: +JVM.EMIT_JVM_TYPE_ANNOTATIONS
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
// JVM_TARGET: 1.8
// WITH_REFLECT
// FULL_JDK
// FILE: ImplicitReturn.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public class ImplicitReturn {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @ interface TypeAnn {}
@ImplicitReturn.TypeAnn
public String bar() {
return "OK";
}
}
// FILE: Kotlin.kt
import java.lang.reflect.AnnotatedType
import kotlin.reflect.jvm.javaMethod
import kotlin.reflect.jvm.javaField
import kotlin.test.fail
class Kotlin {
fun foo() = ImplicitReturn().bar()
@JvmField
val field = ImplicitReturn().bar()
}
fun box(): String {
checkTypeAnnotation(
Kotlin::foo.javaMethod!!.annotatedReturnType,
"class java.lang.String",
"@ImplicitReturn\$TypeAnn()",
"foo"
)
checkTypeAnnotation(
Kotlin::field.javaField!!.annotatedType,
"class java.lang.String",
"@ImplicitReturn\$TypeAnn()",
"foo"
)
return Kotlin().foo()
}
fun checkTypeAnnotation(
annotatedType: AnnotatedType,
type: String,
annotations: String,
message: String
) {
if (annotatedType.annotation() != annotations) fail("check $message (1): ${annotatedType.annotation()} != $annotations")
if (annotatedType.type.toString() != type) fail("check $message (2): ${annotatedType.type} != $type")
}
fun AnnotatedType.annotation() = annotations.joinToString()