Support KClass.constructors in reflection

This commit is contained in:
Alexander Udalov
2015-07-13 18:59:10 +03:00
parent da5cffdb60
commit 81ef1c19d8
12 changed files with 190 additions and 51 deletions
@@ -0,0 +1,19 @@
import kotlin.reflect.*
import kotlin.test.assertTrue
interface Interface
annotation class Anno(val x: Int)
object Obj
class C {
companion object
}
fun box(): String {
assertTrue(Interface::class.constructors.isEmpty())
assertTrue(Anno::class.constructors.isEmpty())
assertTrue(Obj::class.constructors.isEmpty())
assertTrue(C.Companion::class.constructors.isEmpty())
return "OK"
}
@@ -0,0 +1,29 @@
import java.util.Collections
import kotlin.reflect.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
open class A private constructor(x: Int) {
public constructor(s: String): this(s.length())
constructor(): this("")
}
class B : A("")
class C {
class Nested
inner class Inner
}
fun box(): String {
assertEquals(3, A::class.constructors.size())
assertEquals(1, B::class.constructors.size())
assertTrue(Collections.disjoint(A::class.members, A::class.constructors))
assertTrue(Collections.disjoint(B::class.members, B::class.constructors))
assertEquals(1, C.Nested::class.constructors.size())
assertEquals(1, C.Inner::class.constructors.size())
return "OK"
}
@@ -2847,11 +2847,23 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/constructors"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("classesWithoutConstructors.kt")
public void testClassesWithoutConstructors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/constructors/classesWithoutConstructors.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("constructorName.kt")
public void testConstructorName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/constructors/constructorName.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("simpleGetConstructors.kt")
public void testSimpleGetConstructors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/constructors/simpleGetConstructors.kt");
doTestWithStdlib(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing")