Additional tests on reflection calls

This commit is contained in:
Alexander Udalov
2015-08-07 17:29:02 +03:00
parent ccb58d8601
commit 7dcb690254
7 changed files with 82 additions and 0 deletions
@@ -0,0 +1,11 @@
public class J {
private final String result;
private J(String result) {
this.result = result;
}
private String getResult() {
return result;
}
}
@@ -0,0 +1,20 @@
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.*
fun box(): String {
val c = J::class.constructors.single()
assertFalse(c.isAccessible)
failsWith(javaClass<IllegalCallableAccessException>()) { c.call("") }
c.isAccessible = true
assertTrue(c.isAccessible)
val j = c.call("OK")
val m = J::class.members.single { it.name == "getResult" }
assertFalse(m.isAccessible)
failsWith(javaClass<IllegalCallableAccessException>()) { m.call(j)!! }
m.isAccessible = true
return m.call(j) as String
}
@@ -0,0 +1,10 @@
open class A {
fun foo() = "OK"
}
class B : A()
fun box(): String {
val foo = B::class.members.single { it.name == "foo" }
return foo.call(B()) as String
}
@@ -0,0 +1,10 @@
open class A<T>(val t: T) {
fun foo() = t
}
class B(s: String) : A<String>(s)
fun box(): String {
val foo = B::class.members.single { it.name == "foo" }
return foo.call(B("OK")) as String
}
@@ -0,0 +1,7 @@
fun box(): String {
class Local {
fun result(s: String) = s
}
return Local::result.call(Local(), "OK")
}
@@ -273,6 +273,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava(fileName);
}
@TestMetadata("callPrivateJavaMethod")
public void testCallPrivateJavaMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/");
doTestWithJava(fileName);
}
@TestMetadata("callStaticJavaMethod")
public void testCallStaticJavaMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callStaticJavaMethod/");
@@ -2862,6 +2862,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("fakeOverride.kt")
public void testFakeOverride() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverride.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("fakeOverrideSubstituted.kt")
public void testFakeOverrideSubstituted() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/fakeOverrideSubstituted.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("incorrectNumberOfArguments.kt")
public void testIncorrectNumberOfArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/incorrectNumberOfArguments.kt");
@@ -2874,6 +2886,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("localClassMember.kt")
public void testLocalClassMember() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/localClassMember.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("memberOfGenericClass.kt")
public void testMemberOfGenericClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/memberOfGenericClass.kt");