Additional tests on reflection calls
This commit is contained in:
+11
@@ -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
|
||||||
|
}
|
||||||
+10
@@ -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")
|
||||||
|
}
|
||||||
+6
@@ -273,6 +273,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
|||||||
doTestWithJava(fileName);
|
doTestWithJava(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("callPrivateJavaMethod")
|
||||||
|
public void testCallPrivateJavaMethod() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callPrivateJavaMethod/");
|
||||||
|
doTestWithJava(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("callStaticJavaMethod")
|
@TestMetadata("callStaticJavaMethod")
|
||||||
public void testCallStaticJavaMethod() throws Exception {
|
public void testCallStaticJavaMethod() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callStaticJavaMethod/");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/reflection/callStaticJavaMethod/");
|
||||||
|
|||||||
+18
@@ -2862,6 +2862,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
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")
|
@TestMetadata("incorrectNumberOfArguments.kt")
|
||||||
public void testIncorrectNumberOfArguments() throws Exception {
|
public void testIncorrectNumberOfArguments() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/incorrectNumberOfArguments.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/incorrectNumberOfArguments.kt");
|
||||||
@@ -2874,6 +2886,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
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")
|
@TestMetadata("memberOfGenericClass.kt")
|
||||||
public void testMemberOfGenericClass() throws Exception {
|
public void testMemberOfGenericClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/memberOfGenericClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/call/memberOfGenericClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user