Merge boxWithJava testData into box, delete BoxWithJava test
This commit is contained in:
committed by
Alexander Udalov
parent
16a0ddd2fb
commit
f8dfaf4599
+46
@@ -0,0 +1,46 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
|
||||
public static interface ABC {
|
||||
void apply(String x1, String x2);
|
||||
}
|
||||
|
||||
public static Class<?> applyABC(ABC x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(Test.apply(@Ann("OK") fun(){}), "1")
|
||||
|
||||
testClass(Test.applyABC(@Ann("OK") fun(@Ann("OK0") x: String, @Ann("OK1") y: String){}), "2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: Test.java
|
||||
|
||||
class Test {
|
||||
public static Class<?> apply(Runnable x) {
|
||||
return x.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(Test.apply(@Ann("OK") {}), "1")
|
||||
testClass(Test.apply @Ann("OK") {}, "2")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaClass.java
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Foo {
|
||||
int value();
|
||||
}
|
||||
|
||||
@Foo(KotlinClass.FOO_INT)
|
||||
public String test() throws NoSuchMethodException {
|
||||
return KotlinClass.FOO_STRING +
|
||||
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: kotlinClass.kt
|
||||
|
||||
class KotlinClass {
|
||||
companion object {
|
||||
const val FOO_INT: Int = 10
|
||||
@JvmField val FOO_STRING: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = JavaClass().test()
|
||||
return if (test == "OK10") "OK" else "fail : $test"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class JavaClass {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Foo {
|
||||
int value();
|
||||
}
|
||||
|
||||
@Foo(KotlinInterface.FOO_INT)
|
||||
public String test() throws NoSuchMethodException {
|
||||
return KotlinInterface.FOO_STRING +
|
||||
JavaClass.class.getMethod("test").getAnnotation(Foo.class).value();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: KotlinInterface.kt
|
||||
|
||||
interface KotlinInterface {
|
||||
companion object {
|
||||
const val FOO_INT: Int = 10
|
||||
const val FOO_STRING: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = JavaClass().test()
|
||||
return if (test == "OK10") "OK" else "fail : $test"
|
||||
}
|
||||
Reference in New Issue
Block a user