Add KFunction.name, support reflection for function references
#KT-7694 Fixed
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("<init>", ::A.name)
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
fun OK() {}
|
||||
|
||||
return ::OK.name
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import kotlin.platform.platformName
|
||||
|
||||
@platformName("Fail")
|
||||
fun OK() {}
|
||||
|
||||
fun box() = ::OK.name
|
||||
@@ -0,0 +1,16 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo() {}
|
||||
|
||||
class A {
|
||||
fun bar() = ""
|
||||
}
|
||||
|
||||
fun Int.baz() = this
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("foo", ::foo.name)
|
||||
assertEquals("bar", A::bar.name)
|
||||
assertEquals("baz", Int::baz.name)
|
||||
return "OK"
|
||||
}
|
||||
+42
@@ -2821,6 +2821,21 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/constructors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Constructors extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInConstructors() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/constructors"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("constructorName.kt")
|
||||
public void testConstructorName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/constructors/constructorName.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -2974,6 +2989,33 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/functions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Functions extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInFunctions() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/functions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("localFunctionName.kt")
|
||||
public void testLocalFunctionName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/functions/localFunctionName.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("platformName.kt")
|
||||
public void testPlatformName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/functions/platformName.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNames.kt")
|
||||
public void testSimpleNames() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/functions/simpleNames.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/genericSignature")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user