Files
kotlin-fork/compiler/testData/codegen/box/jvmStatic/annotations.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

61 lines
1.2 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
// FILE: Test.java
import java.lang.annotation.Annotation;
class Test {
public static String test1() throws NoSuchMethodException {
Annotation[] test1s = A.class.getMethod("test1").getAnnotations();
for (Annotation test : test1s) {
String name = test.toString();
if (name.contains("testAnnotation")) {
return "OK";
}
}
return "fail";
}
public static String test2() throws NoSuchMethodException {
Annotation[] test2s = B.class.getMethod("test1").getAnnotations();
for (Annotation test : test2s) {
String name = test.toString();
if (name.contains("testAnnotation")) {
return "OK";
}
}
return "fail";
}
}
// FILE: test.kt
@Retention(AnnotationRetention.RUNTIME)
annotation class testAnnotation
class A {
companion object {
val b: String = "OK"
@JvmStatic @testAnnotation fun test1() = b
}
}
object B {
val b: String = "OK"
@JvmStatic @testAnnotation fun test1() = b
}
fun box(): String {
if (Test.test1() != "OK") return "fail 1"
if (Test.test2() != "OK") return "fail 2"
return "OK"
}