Merge boxWithStdlib testData into box, delete BoxWithStdlib test
This commit is contained in:
committed by
Alexander Udalov
parent
22bfc9786a
commit
06a67e6602
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Anno
|
||||
|
||||
fun box(): String {
|
||||
val a = Anno::class.annotations
|
||||
|
||||
if (a.size != 1) return "Fail 1: $a"
|
||||
val ann = a.single() as? Retention ?: return "Fail 2: ${a.single()}"
|
||||
assertEquals(AnnotationRetention.RUNTIME, ann.value)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Get
|
||||
annotation class Set
|
||||
annotation class SetParam
|
||||
|
||||
var foo: String
|
||||
@Get get() = ""
|
||||
@Set set(@SetParam value) {}
|
||||
|
||||
fun box(): String {
|
||||
assert(::foo.getter.annotations.single() is Get)
|
||||
assert(::foo.setter.annotations.single() is Set)
|
||||
assert(::foo.setter.parameters.single().annotations.single() is SetParam)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Ann(val value: String)
|
||||
|
||||
@Ann("OK")
|
||||
val property: String
|
||||
get() = ""
|
||||
|
||||
fun box(): String {
|
||||
return (::property.annotations.single() as Ann).value
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class SourceAnno
|
||||
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class BinaryAnno
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class RuntimeAnno
|
||||
|
||||
@SourceAnno
|
||||
@BinaryAnno
|
||||
@RuntimeAnno
|
||||
fun box(): String {
|
||||
assertEquals(listOf(RuntimeAnno::class.java), ::box.annotations.map { it.annotationClass.java })
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
return (A::class.annotations.single() as Simple).value
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Primary
|
||||
annotation class Secondary
|
||||
|
||||
class C @Primary constructor() {
|
||||
@Secondary
|
||||
constructor(s: String): this()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ans = C::class.constructors.map { it.annotations.single().annotationClass.java.simpleName }.sorted()
|
||||
if (ans != listOf("Primary", "Secondary")) return "Fail: $ans"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
fun box(): String {
|
||||
return (::box.annotations.single() as Simple).value
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
fun test(@Simple("OK") x: Int) {}
|
||||
|
||||
fun box(): String {
|
||||
return (::test.parameters.single().annotations.single() as Simple).value
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@property:Simple("OK")
|
||||
val foo: Int = 0
|
||||
|
||||
fun box(): String {
|
||||
return (::foo.annotations.single() as Simple).value
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
enum class E
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val c = E::class.constructors.single()
|
||||
c.isAccessible = true
|
||||
c.call()
|
||||
return "Fail: constructing an enum class should not be allowed"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class A {
|
||||
private var foo: String = ""
|
||||
}
|
||||
|
||||
object O {
|
||||
@JvmStatic
|
||||
private var bar: String = ""
|
||||
}
|
||||
|
||||
class CounterTest<T>(t: T) {
|
||||
private var baz: String? = ""
|
||||
private var generic: T = t
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = A::class.memberProperties.single() as KMutableProperty1<A, String?>
|
||||
p.isAccessible = true
|
||||
try {
|
||||
p.setter.call(A(), null)
|
||||
return "Fail: exception should have been thrown"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
|
||||
val o = O::class.memberProperties.single() as KMutableProperty1<O, String?>
|
||||
o.isAccessible = true
|
||||
try {
|
||||
o.setter.call(O, null)
|
||||
return "Fail: exception should have been thrown"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
|
||||
val c = CounterTest::class.memberProperties.single { it.name == "baz" } as KMutableProperty1<CounterTest<*>, String?>
|
||||
c.isAccessible = true
|
||||
c.setter.call(CounterTest(""), null) // Should not fail, because CounterTest::baz is nullable
|
||||
val d = CounterTest::class.memberProperties.single { it.name == "generic" } as KMutableProperty1<CounterTest<*>, String?>
|
||||
d.isAccessible = true
|
||||
d.setter.call(CounterTest(""), null) // Also should not fail, because we can't be sure about nullability of 'generic'
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A
|
||||
|
||||
data class D(val s: String)
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
assert(A::equals.call(a, a))
|
||||
assert(!A::equals.call(a, 0))
|
||||
assert(A::hashCode.call(a) == A::hashCode.call(a))
|
||||
assert(A::toString.call(a).startsWith("A@"))
|
||||
|
||||
assert(D::equals.call(D("foo"), D("foo")))
|
||||
assert(!D::equals.call(D("foo"), D("bar")))
|
||||
assert(D::hashCode.call(D("foo")) == D::hashCode.call(D("foo")))
|
||||
assert(D::toString.call(D("foo")) == "D(s=foo)")
|
||||
|
||||
assert(Int::equals.call(-1, -1))
|
||||
assert(Int::hashCode.call(0) != Int::hashCode.call(1))
|
||||
assert(Int::toString.call(42) == "42")
|
||||
|
||||
assert(String::equals.call("beer", "beer"))
|
||||
String::hashCode.call("beer")
|
||||
|
||||
return String::toString.call("OK")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
fun fail(message: String) {
|
||||
throw AssertionError(message)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
::fail.call("OK")
|
||||
} catch (e: InvocationTargetException) {
|
||||
return e.getTargetException().message.toString()
|
||||
}
|
||||
|
||||
return "Fail: no exception was thrown"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
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,12 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
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,105 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.KMutableProperty
|
||||
|
||||
var foo: String = ""
|
||||
|
||||
class A(private var bar: String = "") {
|
||||
fun getBar() = A::bar
|
||||
}
|
||||
|
||||
object O {
|
||||
@JvmStatic
|
||||
private var baz: String = ""
|
||||
|
||||
@JvmStatic
|
||||
fun getBaz() = (O::class.members.single { it.name == "baz" } as KMutableProperty<*>).apply { isAccessible = true }
|
||||
|
||||
fun getGetBaz() = O::class.members.single { it.name == "getBaz" } as KFunction<*>
|
||||
}
|
||||
|
||||
fun check(callable: KCallable<*>, vararg args: Any?) {
|
||||
val expected = callable.parameters.size
|
||||
val actual = args.size
|
||||
|
||||
if (expected == actual) {
|
||||
throw AssertionError("Bad test case: expected and actual number of arguments should differ (was $expected vs $actual)")
|
||||
}
|
||||
|
||||
val expectedExceptionMessage = "Callable expects $expected arguments, but $actual were provided."
|
||||
|
||||
try {
|
||||
callable.call(*args)
|
||||
throw AssertionError("Fail: an IllegalArgumentException should have been thrown")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
if (e.message != expectedExceptionMessage) {
|
||||
// This most probably means that we don't check number of passed arguments in reflection
|
||||
// and the default check from Java reflection yields an IllegalArgumentException, but with a not that helpful message
|
||||
throw AssertionError("Fail: an exception with an unrecognized message was thrown: \"${e.message}\"" +
|
||||
"\nExpected message was: $expectedExceptionMessage")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(::box, null)
|
||||
check(::box, "")
|
||||
|
||||
check(::A)
|
||||
check(::A, null, "")
|
||||
|
||||
check(O.getGetBaz())
|
||||
check(O.getGetBaz(), null, "")
|
||||
|
||||
|
||||
val f = ::foo
|
||||
check(f, null)
|
||||
check(f, null, null)
|
||||
check(f, arrayOf<Any?>(null))
|
||||
check(f, "")
|
||||
|
||||
check(f.getter, null)
|
||||
check(f.getter, null, null)
|
||||
check(f.getter, arrayOf<Any?>(null))
|
||||
check(f.getter, "")
|
||||
|
||||
check(f.setter)
|
||||
check(f.setter, null, null)
|
||||
check(f.setter, null, "")
|
||||
|
||||
|
||||
val b = A().getBar()
|
||||
|
||||
check(b)
|
||||
check(b, null, null)
|
||||
check(b, "", "")
|
||||
|
||||
check(b.getter)
|
||||
check(b.getter, null, null)
|
||||
check(b.getter, "", "")
|
||||
|
||||
check(b.setter)
|
||||
check(b.setter, null)
|
||||
check(b.setter, "")
|
||||
|
||||
|
||||
val z = O.getBaz()
|
||||
|
||||
check(z)
|
||||
check(z, null, null)
|
||||
check(z, "", "")
|
||||
|
||||
check(z.getter)
|
||||
check(z.getter, null, null)
|
||||
check(z.getter, "", "")
|
||||
|
||||
check(z.setter)
|
||||
check(z.setter, null)
|
||||
check(z.setter, "")
|
||||
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A {
|
||||
class Nested(val result: String)
|
||||
inner class Inner(val result: String)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return (A::Nested).call("O").result + (A::Inner).call((::A).call(), "K").result
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
object Obj {
|
||||
@JvmStatic
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
(Obj::class.members.single { it.name == "foo" }).call(Obj)
|
||||
(C.Companion::class.members.single { it.name == "bar" }).call(C.Companion)
|
||||
return "OK"
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
object Obj {
|
||||
@JvmStatic
|
||||
fun foo(s: String) {}
|
||||
|
||||
@JvmStatic
|
||||
fun bar() {}
|
||||
|
||||
@JvmStatic
|
||||
fun sly(obj: Obj) {}
|
||||
|
||||
operator fun get(name: String) = Obj::class.members.single { it.name == name }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
// This should succeed
|
||||
(Obj["foo"]).call(Obj, "")
|
||||
(Obj["bar"]).call(Obj)
|
||||
(Obj["sly"]).call(Obj, Obj)
|
||||
|
||||
// This shouldn't: first argument should always be Obj
|
||||
try {
|
||||
(Obj["foo"]).call(null, "")
|
||||
return "Fail foo"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
try {
|
||||
(Obj["bar"]).call("")
|
||||
return "Fail bar"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
try {
|
||||
(Obj["sly"]).call(Obj)
|
||||
return "Fail sly 1"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
try {
|
||||
(Obj["sly"]).call(null, Obj)
|
||||
return "Fail sly 2"
|
||||
} catch (e: IllegalArgumentException) {}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
class Local {
|
||||
fun result(s: String) = s
|
||||
}
|
||||
|
||||
return Local::result.call(Local(), "OK")
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
var result = "Fail"
|
||||
|
||||
class A<T> {
|
||||
fun foo(t: T) {
|
||||
result = t as String
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
(A<String>::foo).call(A<String>(), "OK")
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.*
|
||||
|
||||
class A(private var result: String)
|
||||
|
||||
fun box(): String {
|
||||
val a = A("abc")
|
||||
|
||||
val p = A::class.declaredMemberProperties.single() as KMutableProperty1<A, String>
|
||||
p.isAccessible = true
|
||||
assertEquals("abc", p.call(a))
|
||||
assertEquals(Unit, p.setter.call(a, "def"))
|
||||
assertEquals("def", p.getter.call(a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
val p0 = 1
|
||||
val Int.p1: Int get() = this
|
||||
class A {
|
||||
val Int.p2: Int get() = this
|
||||
}
|
||||
|
||||
var globalCounter = 0
|
||||
|
||||
var mp0 = 1
|
||||
set(value) { globalCounter += value }
|
||||
var Int.mp1: Int
|
||||
get() = this
|
||||
set(value) { globalCounter += value }
|
||||
class B {
|
||||
var Int.mp2: Int
|
||||
get() = this
|
||||
set(value) { globalCounter += value }
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, (::p0).call())
|
||||
assertEquals(1, (::p0).getter.call())
|
||||
assertEquals(2, (Int::p1).call(2))
|
||||
assertEquals(2, (Int::p1).getter.call(2))
|
||||
val p2 = A::class.memberExtensionProperties.single()
|
||||
assertEquals(3, p2.call(A(), 3))
|
||||
assertEquals(3, p2.getter.call(A(), 3))
|
||||
|
||||
assertEquals(1, (::mp0).call())
|
||||
assertEquals(1, (::mp0).getter.call())
|
||||
assertEquals(2, (Int::mp1).call(2))
|
||||
assertEquals(2, (Int::mp1).getter.call(2))
|
||||
val mp2 = B::class.memberExtensionProperties.single() as KMutableProperty2
|
||||
assertEquals(3, mp2.call(B(), 3))
|
||||
assertEquals(3, mp2.getter.call(B(), 3))
|
||||
|
||||
assertEquals(Unit, (::mp0).setter.call(1))
|
||||
assertEquals(Unit, (Int::mp1).setter.call(0, 3))
|
||||
assertEquals(Unit, mp2.setter.call(B(), 0, 5))
|
||||
if (globalCounter != 9) return "Fail: $globalCounter"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo() {}
|
||||
|
||||
class A {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
object O {
|
||||
@JvmStatic fun baz() {}
|
||||
}
|
||||
|
||||
fun nullableUnit(unit: Boolean): Unit? = if (unit) Unit else null
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(Unit, ::foo.call())
|
||||
assertEquals(Unit, A::bar.call(A()))
|
||||
assertEquals(Unit, O::class.members.single { it.name == "baz" }.call(O))
|
||||
|
||||
assertEquals(Unit, (::nullableUnit).call(true))
|
||||
assertEquals(null, (::nullableUnit).call(false))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String)
|
||||
|
||||
fun box(): String {
|
||||
val a = (::A).call("OK")
|
||||
return a.result
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A {
|
||||
fun foo(x: Int, y: Int) = x + y
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = (A::foo).call(A(), 42, 239)
|
||||
if (x != 281) return "Fail: $x"
|
||||
|
||||
try {
|
||||
(A::foo).call()
|
||||
return "Fail: no exception"
|
||||
}
|
||||
catch (e: Exception) {}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun String.foo(): Int = length
|
||||
|
||||
var state = "Fail"
|
||||
|
||||
fun bar(result: String) {
|
||||
state = result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = (String::foo).call("abc")
|
||||
if (f != 3) return "Fail: $f"
|
||||
|
||||
try {
|
||||
(String::foo).call()
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {}
|
||||
|
||||
try {
|
||||
(String::foo).call(42)
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {}
|
||||
|
||||
(::bar).call("OK")
|
||||
return state
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(a: String, b: String = "b", c: String, d: String = "d", e: String) =
|
||||
a + b + c + d + e
|
||||
|
||||
fun box(): String {
|
||||
val p = ::foo.parameters
|
||||
assertEquals("abcde", ::foo.callBy(mapOf(
|
||||
p[0] to "a",
|
||||
p[2] to "c",
|
||||
p[4] to "e"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun String.sum(other: String = "b") = this + other
|
||||
|
||||
fun box(): String {
|
||||
val f = String::sum
|
||||
assertEquals("ab", f.callBy(mapOf(f.parameters.first() to "a")))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object Obj {
|
||||
@JvmStatic
|
||||
fun foo(a: String, b: String = "b") = a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = Obj::class.members.single { it.name == "foo" }
|
||||
|
||||
// Any object method currently requires the object instance passed
|
||||
try {
|
||||
f.callBy(mapOf(
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
))
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
assertEquals("ab", f.callBy(mapOf(
|
||||
f.parameters.first() to Obj,
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
// Generate:
|
||||
// (1..70).map { " p${"%02d".format(it)}: Int," }.joinToString("\n")
|
||||
|
||||
class A {
|
||||
fun foo(
|
||||
p01: Int,
|
||||
p02: Int,
|
||||
p03: Int,
|
||||
p04: Int,
|
||||
p05: Int,
|
||||
p06: Int,
|
||||
p07: Int,
|
||||
p08: Int,
|
||||
p09: Int,
|
||||
p10: Int,
|
||||
p11: Int,
|
||||
p12: Int,
|
||||
p13: Int,
|
||||
p14: Int,
|
||||
p15: Int,
|
||||
p16: Int,
|
||||
p17: Int,
|
||||
p18: Int,
|
||||
p19: Int,
|
||||
p20: Int,
|
||||
p21: Int,
|
||||
p22: Int,
|
||||
p23: Int,
|
||||
p24: Int,
|
||||
p25: Int,
|
||||
p26: Int,
|
||||
p27: Int,
|
||||
p28: Int,
|
||||
p29: Int,
|
||||
p30: Int,
|
||||
p31: Int,
|
||||
p32: Int,
|
||||
p33: Int,
|
||||
p34: Int,
|
||||
p35: Int,
|
||||
p36: Int,
|
||||
p37: Int,
|
||||
p38: Int,
|
||||
p39: Int,
|
||||
p40: Int,
|
||||
p41: Int,
|
||||
p42: Int = 239,
|
||||
p43: Int,
|
||||
p44: Int,
|
||||
p45: Int,
|
||||
p46: Int,
|
||||
p47: Int,
|
||||
p48: Int,
|
||||
p49: Int,
|
||||
p50: Int,
|
||||
p51: Int,
|
||||
p52: Int,
|
||||
p53: Int,
|
||||
p54: Int,
|
||||
p55: Int,
|
||||
p56: Int,
|
||||
p57: Int,
|
||||
p58: Int,
|
||||
p59: Int,
|
||||
p60: Int,
|
||||
p61: Int,
|
||||
p62: Int,
|
||||
p63: Int,
|
||||
p64: Int,
|
||||
p65: Int,
|
||||
p66: Int,
|
||||
p67: Int,
|
||||
p68: Int,
|
||||
p69: Int,
|
||||
p70: Int
|
||||
) {
|
||||
assertEquals(1, p01)
|
||||
assertEquals(41, p41)
|
||||
assertEquals(239, p42)
|
||||
assertEquals(43, p43)
|
||||
assertEquals(70, p70)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = A::class.members.single { it.name == "foo" }
|
||||
val parameters = f.parameters
|
||||
|
||||
f.callBy(mapOf(
|
||||
parameters.first() to A(),
|
||||
*((1..41) + (43..70)).map { i -> parameters[i] to i }.toTypedArray()
|
||||
))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
// Generate:
|
||||
// (1..70).map { " p${"%02d".format(it)}: Int = $it," }.joinToString("\n")
|
||||
|
||||
class A {
|
||||
fun foo(
|
||||
p01: Int = 1,
|
||||
p02: Int = 2,
|
||||
p03: Int = 3,
|
||||
p04: Int = 4,
|
||||
p05: Int = 5,
|
||||
p06: Int = 6,
|
||||
p07: Int = 7,
|
||||
p08: Int = 8,
|
||||
p09: Int = 9,
|
||||
p10: Int = 10,
|
||||
p11: Int = 11,
|
||||
p12: Int = 12,
|
||||
p13: Int = 13,
|
||||
p14: Int = 14,
|
||||
p15: Int = 15,
|
||||
p16: Int = 16,
|
||||
p17: Int = 17,
|
||||
p18: Int = 18,
|
||||
p19: Int = 19,
|
||||
p20: Int = 20,
|
||||
p21: Int = 21,
|
||||
p22: Int = 22,
|
||||
p23: Int = 23,
|
||||
p24: Int = 24,
|
||||
p25: Int = 25,
|
||||
p26: Int = 26,
|
||||
p27: Int = 27,
|
||||
p28: Int = 28,
|
||||
p29: Int = 29,
|
||||
p30: Int = 30,
|
||||
p31: Int = 31,
|
||||
p32: Int = 32,
|
||||
p33: Int = 33,
|
||||
p34: Int = 34,
|
||||
p35: Int = 35,
|
||||
p36: Int = 36,
|
||||
p37: Int = 37,
|
||||
p38: Int = 38,
|
||||
p39: Int = 39,
|
||||
p40: Int = 40,
|
||||
p41: Int = 41,
|
||||
p42: Int,
|
||||
p43: Int = 43,
|
||||
p44: Int = 44,
|
||||
p45: Int = 45,
|
||||
p46: Int = 46,
|
||||
p47: Int = 47,
|
||||
p48: Int = 48,
|
||||
p49: Int = 49,
|
||||
p50: Int = 50,
|
||||
p51: Int = 51,
|
||||
p52: Int = 52,
|
||||
p53: Int = 53,
|
||||
p54: Int = 54,
|
||||
p55: Int = 55,
|
||||
p56: Int = 56,
|
||||
p57: Int = 57,
|
||||
p58: Int = 58,
|
||||
p59: Int = 59,
|
||||
p60: Int = 60,
|
||||
p61: Int = 61,
|
||||
p62: Int = 62,
|
||||
p63: Int = 63,
|
||||
p64: Int = 64,
|
||||
p65: Int = 65,
|
||||
p66: Int = 66,
|
||||
p67: Int = 67,
|
||||
p68: Int = 68,
|
||||
p69: Int = 69,
|
||||
p70: Int = 70
|
||||
) {
|
||||
assertEquals(1, p01)
|
||||
assertEquals(41, p41)
|
||||
assertEquals(239, p42)
|
||||
assertEquals(43, p43)
|
||||
assertEquals(70, p70)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = A::class.members.single { it.name == "foo" }
|
||||
val parameters = f.parameters
|
||||
f.callBy(mapOf(
|
||||
parameters.first() to A(),
|
||||
parameters.single { it.name == "p42" } to 239
|
||||
))
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun foo(x: Int, y: Int = 2) = x + y
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
::foo.callBy(mapOf())
|
||||
return "Fail: IllegalArgumentException must have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
try {
|
||||
::foo.callBy(mapOf(::foo.parameters.last() to 1))
|
||||
return "Fail: IllegalArgumentException must have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertNull
|
||||
|
||||
fun foo(x: String? = "Fail") {
|
||||
assertNull(x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::foo.callBy(mapOf(::foo.parameters.single() to null))
|
||||
return "OK"
|
||||
}
|
||||
compiler/testData/codegen/box/reflection/callBy/ordinaryMethodIsInvokedWhenNoDefaultValuesAreUsed.kt
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(result: String = "foo") {
|
||||
assertEquals("box", result)
|
||||
|
||||
// Check that this function was invoked directly and not through the "foo$default", i.e. there's no "foo$default" in the stack trace
|
||||
val st = Thread.currentThread().stackTrace
|
||||
for (i in 0..5) {
|
||||
if ("foo\$default" in st[i].methodName) {
|
||||
throw AssertionError("KCallable.call should invoke the method directly if all arguments are provided")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::foo.callBy(mapOf(::foo.parameters.single() to "box"))
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun primitives(
|
||||
boolean: Boolean = true,
|
||||
character: Char = 'z',
|
||||
byte: Byte = 5.toByte(),
|
||||
short: Short = (-5).toShort(),
|
||||
int: Int = 2000000000,
|
||||
float: Float = -2.72f,
|
||||
long: Long = 1000000000000000000L,
|
||||
double: Double = 3.14159265359
|
||||
) {
|
||||
assertEquals(true, boolean)
|
||||
assertEquals('z', character)
|
||||
assertEquals(5.toByte(), byte)
|
||||
assertEquals((-5).toShort(), short)
|
||||
assertEquals(2000000000, int)
|
||||
assertEquals(-2.72f, float)
|
||||
assertEquals(1000000000000000000L, long)
|
||||
assertEquals(3.14159265359, double)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::primitives.callBy(emptyMap())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.IllegalCallableAccessException
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
class A {
|
||||
private fun foo(default: Any? = this) {
|
||||
}
|
||||
|
||||
fun f() = A::foo
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val f = a.f()
|
||||
|
||||
try {
|
||||
f.callBy(mapOf(f.parameters.first() to a))
|
||||
return "Fail: IllegalCallableAccessException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalCallableAccessException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
f.isAccessible = true
|
||||
f.callBy(mapOf(f.parameters.first() to a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String = "OK")
|
||||
|
||||
fun box(): String = ::A.callBy(mapOf()).result
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String = "OK") {
|
||||
fun foo(x: Int = 42): String {
|
||||
assert(x == 42) { x }
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = A::foo.callBy(mapOf(A::foo.parameters.first() to A()))
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun foo(result: String = "OK") = result
|
||||
|
||||
fun box(): String = ::foo.callBy(mapOf())
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Deprecated", Deprecated::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun box(): String {
|
||||
val any = Array<Any>::class
|
||||
val string = Array<String>::class
|
||||
|
||||
assertNotEquals<KClass<*>>(any, string)
|
||||
assertNotEquals<Class<*>>(any.java, string.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Any", Any::class.simpleName)
|
||||
assertEquals("String", String::class.simpleName)
|
||||
assertEquals("CharSequence", CharSequence::class.simpleName)
|
||||
assertEquals("Number", Number::class.simpleName)
|
||||
assertEquals("Int", Int::class.simpleName)
|
||||
assertEquals("Long", Long::class.simpleName)
|
||||
|
||||
assertEquals("Array", Array<Any>::class.simpleName)
|
||||
assertEquals("Array", Array<IntArray>::class.simpleName)
|
||||
|
||||
assertEquals("Companion", Int.Companion::class.simpleName)
|
||||
assertEquals("Companion", Double.Companion::class.simpleName)
|
||||
assertEquals("Companion", Char.Companion::class.simpleName)
|
||||
|
||||
assertEquals("IntRange", IntRange::class.simpleName)
|
||||
|
||||
assertEquals("List", List::class.simpleName)
|
||||
|
||||
// TODO: this is wrong but should be fixed
|
||||
assertEquals("List", MutableList::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class Klass
|
||||
|
||||
inline fun <reified T> arrayClass(): KClass<Array<T>> = Array<T>::class
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Array", arrayClass<Int>().simpleName)
|
||||
assertEquals("Array", arrayClass<Int?>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Int>>().simpleName)
|
||||
assertEquals("Array", arrayClass<Klass>().simpleName)
|
||||
assertEquals("Array", arrayClass<Klass?>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Klass>>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Klass?>>().simpleName)
|
||||
|
||||
// Should not be that way. Fix this test when backend is fixed.
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Int>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Int?>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Int>>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Klass>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Klass?>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Klass>>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Klass?>>().jvmName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Generic<K, V>
|
||||
|
||||
fun box(): String {
|
||||
val g = Generic::class
|
||||
assertEquals("Generic", g.simpleName)
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Klass
|
||||
class Other
|
||||
|
||||
inline fun <reified T : Any> simpleName(): String =
|
||||
T::class.simpleName!!
|
||||
|
||||
inline fun <reified T1 : Any, reified T2 : Any> twoReifiedParams(): String =
|
||||
"${T1::class.simpleName!!}, ${T2::class.simpleName!!}"
|
||||
|
||||
inline fun <reified T : Any> myJavaClass(): Class<T> =
|
||||
T::class.java
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", simpleName<Klass>())
|
||||
assertEquals("Int", simpleName<Int>())
|
||||
assertEquals("Array", simpleName<Array<Int>>())
|
||||
assertEquals("Error", simpleName<Error>())
|
||||
assertEquals("Klass, Other", twoReifiedParams<Klass, Other>())
|
||||
|
||||
assertEquals(String::class.java, myJavaClass<String>())
|
||||
assertEquals(IntArray::class.java, myJavaClass<IntArray>())
|
||||
assertEquals(Klass::class.java, myJavaClass<Klass>())
|
||||
assertEquals(Error::class.java, myJavaClass<Error>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
val klass = A::class
|
||||
return if (klass.toString() == "class A") "OK" else "Fail: $klass"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.simpleName)
|
||||
assertEquals("Date", java.util.Date::class.simpleName)
|
||||
assertEquals("ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.simpleName)
|
||||
assertEquals("Void", java.lang.Void::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
companion object C
|
||||
}
|
||||
|
||||
enum class E {
|
||||
ENTRY;
|
||||
companion object {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val obj = A::class.companionObject
|
||||
assertNotNull(obj)
|
||||
assertEquals("C", obj!!.simpleName)
|
||||
|
||||
assertEquals(A.C, A::class.companionObjectInstance)
|
||||
assertEquals(A.C, obj.objectInstance)
|
||||
|
||||
assertNull(A.C::class.companionObject)
|
||||
assertNull(A.C::class.companionObjectInstance)
|
||||
|
||||
assertEquals(E.Companion, E::class.companionObjectInstance)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.defaultType
|
||||
import kotlin.reflect.jvm.javaType
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class Simple
|
||||
class Generic<K, V> {
|
||||
fun thiz() = this
|
||||
}
|
||||
|
||||
fun simple() = Simple()
|
||||
fun genericIntString() = Generic<Int, String>()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(Simple::class.java, Simple::class.defaultType.javaType)
|
||||
assertEquals(::simple.returnType, Simple::class.defaultType)
|
||||
|
||||
assertEquals(Generic::class.java, Generic::class.defaultType.javaType)
|
||||
assertEquals(Generic<*, *>::thiz.returnType, Generic::class.defaultType)
|
||||
|
||||
// Generic<Int, String> != Generic<K, V>
|
||||
assertNotEquals(::genericIntString.returnType, Generic::class.defaultType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.jvmName)
|
||||
assertEquals("Klass\$Nested", Klass.Nested::class.jvmName)
|
||||
assertEquals("Klass\$Companion", Klass.Companion::class.jvmName)
|
||||
|
||||
assertEquals("java.lang.Object", Any::class.jvmName)
|
||||
assertEquals("int", Int::class.jvmName)
|
||||
assertEquals("[I", IntArray::class.jvmName)
|
||||
assertEquals("java.util.List", List::class.jvmName)
|
||||
assertEquals("java.util.List", MutableList::class.jvmName)
|
||||
assertEquals("java.lang.String", String::class.jvmName)
|
||||
assertEquals("java.lang.String", java.lang.String::class.jvmName)
|
||||
|
||||
assertEquals("[Ljava.lang.Object;", Array<Any>::class.jvmName)
|
||||
assertEquals("[Ljava.lang.Integer;", Array<Int>::class.jvmName)
|
||||
assertEquals("[[Ljava.lang.String;", Array<Array<String>>::class.jvmName)
|
||||
|
||||
assertEquals("java.util.Date", java.util.Date::class.jvmName)
|
||||
assertEquals("kotlin.jvm.internal.Ref\$ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.jvmName)
|
||||
assertEquals("java.lang.Void", java.lang.Void::class.jvmName)
|
||||
|
||||
class Local
|
||||
val l = Local::class.jvmName
|
||||
assertTrue(l != null && l.startsWith("JvmNameKt\$") && "\$box\$" in l && l.endsWith("\$Local"))
|
||||
|
||||
val obj = object {}
|
||||
val o = obj.javaClass.kotlin.jvmName
|
||||
assertTrue(o != null && o.startsWith("JvmNameKt\$") && "\$box\$" in o && o.endsWith("\$1"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun check(klass: KClass<*>, expectedName: String) {
|
||||
assertEquals(expectedName, klass.simpleName)
|
||||
}
|
||||
|
||||
fun localInMethod() {
|
||||
fun localInMethod(unused: Any?) {
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
localInMethod(null)
|
||||
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
|
||||
class LocalInConstructor {
|
||||
init {
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
localInMethod()
|
||||
LocalInConstructor()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
companion object {}
|
||||
inner class Inner
|
||||
class Nested
|
||||
private class PrivateNested
|
||||
}
|
||||
|
||||
fun nestedNames(c: KClass<*>) = c.nestedClasses.map { it.simpleName ?: throw AssertionError("Unnamed class: ${it.java}") }.sorted()
|
||||
|
||||
fun box(): String {
|
||||
// Kotlin class without nested classes
|
||||
assertEquals(emptyList<String>(), nestedNames(A.Inner::class))
|
||||
// Kotlin class with nested classes
|
||||
assertEquals(listOf("Companion", "Inner", "Nested", "PrivateNested"), nestedNames(A::class))
|
||||
|
||||
// Java class without nested classes
|
||||
assertEquals(emptyList<String>(), nestedNames(Error::class))
|
||||
// Java class with nested classes
|
||||
assertEquals(listOf("State", "UncaughtExceptionHandler"), nestedNames(Thread::class))
|
||||
|
||||
// Built-ins
|
||||
assertEquals(emptyList<String>(), nestedNames(Array<Any>::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(CharSequence::class))
|
||||
assertEquals(listOf("Companion"), nestedNames(String::class))
|
||||
|
||||
assertEquals(emptyList<String>(), nestedNames(Collection::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableCollection::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(List::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableList::class))
|
||||
assertEquals(listOf("Entry"), nestedNames(Map::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(Map.Entry::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableMap.MutableEntry::class))
|
||||
|
||||
// TODO: should be MutableEntry. Currently we do not distinguish between Map and MutableMap.
|
||||
assertEquals(listOf("Entry"), nestedNames(MutableMap::class))
|
||||
|
||||
// Primitives
|
||||
for (primitive in listOf(Byte::class, Double::class, Float::class, Int::class, Long::class, Short::class, Char::class)) {
|
||||
assertEquals(listOf("Companion"), nestedNames(primitive))
|
||||
}
|
||||
assertEquals(emptyList<String>(), nestedNames(Boolean::class))
|
||||
|
||||
// Primitive arrays
|
||||
for (primitiveArray in listOf(
|
||||
ByteArray::class, DoubleArray::class, FloatArray::class, IntArray::class,
|
||||
LongArray::class, ShortArray::class, CharArray::class, BooleanArray::class
|
||||
)) {
|
||||
assertEquals(emptyList<String>(), nestedNames(primitiveArray))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object Obj {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo() = 2
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object Factory {
|
||||
fun foo() = 3
|
||||
}
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, Obj::class.objectInstance!!.foo())
|
||||
assertEquals(2, A.Companion::class.objectInstance!!.foo())
|
||||
assertEquals(3, B.Factory::class.objectInstance!!.foo())
|
||||
|
||||
assertEquals(null, C::class.objectInstance)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.qualifiedName)
|
||||
assertEquals("Klass.Nested", Klass.Nested::class.qualifiedName)
|
||||
assertEquals("Klass.Companion", Klass.Companion::class.qualifiedName)
|
||||
|
||||
assertEquals("kotlin.Any", Any::class.qualifiedName)
|
||||
assertEquals("kotlin.Int", Int::class.qualifiedName)
|
||||
assertEquals("kotlin.Int.Companion", Int.Companion::class.qualifiedName)
|
||||
assertEquals("kotlin.IntArray", IntArray::class.qualifiedName)
|
||||
assertEquals("kotlin.collections.List", List::class.qualifiedName)
|
||||
assertEquals("kotlin.String", String::class.qualifiedName)
|
||||
assertEquals("kotlin.String", java.lang.String::class.qualifiedName)
|
||||
|
||||
assertEquals("kotlin.Array", Array<Any>::class.qualifiedName)
|
||||
assertEquals("kotlin.Array", Array<Int>::class.qualifiedName)
|
||||
assertEquals("kotlin.Array", Array<Array<String>>::class.qualifiedName)
|
||||
|
||||
assertEquals("java.util.Date", java.util.Date::class.qualifiedName)
|
||||
assertEquals("kotlin.jvm.internal.Ref.ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.qualifiedName)
|
||||
assertEquals("java.lang.Void", java.lang.Void::class.qualifiedName)
|
||||
|
||||
class Local
|
||||
assertEquals(null, Local::class.qualifiedName)
|
||||
|
||||
val o = object {}
|
||||
assertEquals(null, o.javaClass.kotlin.qualifiedName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
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,10 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("<init>", ::A.name)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.reflect.*
|
||||
|
||||
class OnlyPrimary
|
||||
|
||||
class PrimaryWithSecondary(val s: String) {
|
||||
constructor(x: Int) : this(x.toString())
|
||||
|
||||
override fun toString() = s
|
||||
}
|
||||
|
||||
class OnlySecondary {
|
||||
constructor(s: String)
|
||||
}
|
||||
|
||||
class TwoSecondaries {
|
||||
constructor(s: String)
|
||||
constructor(d: Double)
|
||||
}
|
||||
|
||||
enum class En
|
||||
|
||||
interface I
|
||||
object O
|
||||
class C {
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p1 = OnlyPrimary::class.primaryConstructor
|
||||
assertNotNull(p1)
|
||||
assert(p1!!.call() is OnlyPrimary)
|
||||
|
||||
val p2 = PrimaryWithSecondary::class.primaryConstructor
|
||||
assertNotNull(p2)
|
||||
assert(p2!!.call("beer").toString() == "beer")
|
||||
|
||||
val p3 = OnlySecondary::class.primaryConstructor
|
||||
assertNull(p3)
|
||||
|
||||
val p4 = TwoSecondaries::class.primaryConstructor
|
||||
assertNull(p4)
|
||||
|
||||
assertNotNull(En::class.primaryConstructor) // TODO: maybe primaryConstructor should be null for enum classes
|
||||
|
||||
assertNull(I::class.primaryConstructor)
|
||||
assertNull(O::class.primaryConstructor)
|
||||
assertNull(C.Companion::class.primaryConstructor)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
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"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
interface A {
|
||||
fun f(): String
|
||||
}
|
||||
|
||||
inline fun foo(): A {
|
||||
return object : A {
|
||||
override fun f(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val y = foo()
|
||||
|
||||
val enclosing = y.javaClass.getEnclosingMethod()
|
||||
if (enclosing?.getName() != "foo") return "method: $enclosing"
|
||||
|
||||
return y.f()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val classInLambda = {
|
||||
class Z {}
|
||||
Z()
|
||||
}()
|
||||
|
||||
val enclosingMethod = classInLambda.javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = classInLambda.javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "ClassInLambdaKt\$box\$classInLambda\$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = classInLambda.javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "class has a declaring class"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
val property = fun () {}
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = property.javaClass
|
||||
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod != null) return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "FunctionExpressionInPropertyKt") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
interface R {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
val a by lazy {
|
||||
with(HashMap<String, R>()) {
|
||||
put("result", object : R {
|
||||
override fun result(): String = "OK"
|
||||
})
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r = a["result"]!!
|
||||
|
||||
// Check that reflection won't fail
|
||||
r.javaClass.getEnclosingMethod().toString()
|
||||
|
||||
return r.result()
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
var lambda = {}
|
||||
|
||||
class A {
|
||||
val prop = Runnable {
|
||||
lambda = { println("") }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A().prop.run()
|
||||
|
||||
val javaClass = lambda.javaClass
|
||||
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "run") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "A\$prop\$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class O {
|
||||
companion object {
|
||||
// Currently we consider <clinit> in class O as the enclosing method of this lambda,
|
||||
// so we write outer class = O and enclosing method = null
|
||||
val f = {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = O.f.javaClass
|
||||
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod != null) return "method: $enclosingMethod"
|
||||
|
||||
val enclosingConstructor = javaClass.getEnclosingConstructor()
|
||||
if (enclosingConstructor != null) return "constructor: $enclosingConstructor"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()
|
||||
if (enclosingClass?.getName() != "O") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class C {
|
||||
val l: Any = {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = C().l.javaClass
|
||||
val enclosingConstructor = javaClass.getEnclosingConstructor()
|
||||
if (enclosingConstructor?.getDeclaringClass()?.getName() != "C") return "ctor: $enclosingConstructor"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()
|
||||
if (enclosingClass?.getName() != "C") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
val l: Any = {}
|
||||
|
||||
val javaClass = l.javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "box") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInFunctionKt") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
val l = {
|
||||
{}
|
||||
}
|
||||
|
||||
val javaClass = l().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInLambdaKt\$box\$l\$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
open class C
|
||||
|
||||
fun box(): String {
|
||||
class L : C() {
|
||||
val a: Any
|
||||
|
||||
init {
|
||||
a = {}
|
||||
}
|
||||
}
|
||||
val l = L()
|
||||
|
||||
val javaClass = l.a.javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingConstructor()!!.getName()
|
||||
if (enclosingMethod != "LambdaInLocalClassConstructorKt\$box\$L") return "ctor: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInLocalClassConstructorKt\$box\$L") return "enclosing class: $enclosingClass"
|
||||
|
||||
if (enclosingMethod != enclosingClass) return "$enclosingClass != $enclosingMethod"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
open class C(val a: Any)
|
||||
|
||||
fun box(): String {
|
||||
class L : C({}) {
|
||||
}
|
||||
val l = L()
|
||||
|
||||
val javaClass = l.a.javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingConstructor()!!.getName()
|
||||
if (enclosingMethod != "LambdaInLocalClassSuperCallKt\$box\$L") return "ctor: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInLocalClassSuperCallKt\$box\$L") return "enclosing class: $enclosingClass"
|
||||
|
||||
if (enclosingMethod != enclosingClass) return "$enclosingClass != $enclosingMethod"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
fun foo(): Any {
|
||||
return {}
|
||||
}
|
||||
|
||||
val javaClass = foo().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInLocalFunctionKt\$box$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class C {
|
||||
fun foo(): Any {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = C().foo().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "foo") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()
|
||||
if (enclosingClass?.getName() != "C") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
class C {
|
||||
fun foo(): Any {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
val javaClass = C().foo().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "foo") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInMemberFunctionInLocalClassKt\$box\$C") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class C {
|
||||
class D {
|
||||
fun foo(): Any {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = C.D().foo().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "foo") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()
|
||||
if (enclosingClass?.getSimpleName() != "D") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
object O {
|
||||
val f = {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val javaClass = O.f.javaClass
|
||||
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod != null) return "method: $enclosingMethod"
|
||||
|
||||
val enclosingConstructor = javaClass.getEnclosingConstructor()
|
||||
if (enclosingConstructor == null) return "no enclosing constructor"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()
|
||||
if (enclosingClass?.getName() != "O") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
interface C {
|
||||
val a: Any
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val l = object : C {
|
||||
override val a: Any
|
||||
|
||||
init {
|
||||
a = {}
|
||||
}
|
||||
}
|
||||
|
||||
val javaClass = l.a.javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingConstructor()!!.getName()
|
||||
if (enclosingMethod != "LambdaInObjectExpressionKt\$box\$l\$1") return "ctor: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInObjectExpressionKt\$box\$l\$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
if (enclosingMethod != enclosingClass) return "$enclosingClass != $enclosingMethod"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
open class C(val a: Any)
|
||||
|
||||
fun box(): String {
|
||||
val l = object : C({}) {
|
||||
}
|
||||
|
||||
val javaClass = l.a.javaClass
|
||||
if (javaClass.getEnclosingConstructor() != null) return "ctor should be null"
|
||||
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()!!.getName()
|
||||
if (enclosingMethod != "box") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInObjectLiteralSuperCallKt" || enclosingClass != l.javaClass.getEnclosingClass()!!.getName())
|
||||
return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
val l: Any = {}
|
||||
|
||||
fun box(): String {
|
||||
val enclosingClass = l.javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInPackageKt") return "enclosing class: $enclosingClass"
|
||||
|
||||
val enclosingConstructor = l.javaClass.getEnclosingConstructor()
|
||||
if (enclosingConstructor != null) return "enclosing constructor found: $enclosingConstructor"
|
||||
|
||||
val enclosingMethod = l.javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod != null) return "enclosing method found: $enclosingMethod"
|
||||
|
||||
val declaringClass = l.javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
val l: Any
|
||||
get() = {}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val enclosingMethod = l.javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "getL") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = l.javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInPropertyGetterKt") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = l.javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
var _l: Any = ""
|
||||
|
||||
var l: Any
|
||||
get() = _l
|
||||
set(v) {
|
||||
_l = {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
l = "" // to invoke the setter
|
||||
|
||||
val enclosingMethod = l.javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "setL") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = l.javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInPropertySetterKt") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = l.javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_REFLECT
|
||||
// KT-4234
|
||||
|
||||
fun box(): String {
|
||||
class C
|
||||
|
||||
val name = C::class.java.getSimpleName()
|
||||
if (name != "box\$C") return "Fail: $name"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val objectInLambda = {
|
||||
object : Any () {}
|
||||
}()
|
||||
|
||||
val enclosingMethod = objectInLambda.javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = objectInLambda.javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "ObjectInLambdaKt\$box\$objectInLambda\$1") return "enclosing class: $enclosingClass"
|
||||
|
||||
val declaringClass = objectInLambda.javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous object has a declaring class"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
fun doStuff(fn: String.() -> String) = "ok".fn()
|
||||
|
||||
fun box(): String {
|
||||
return doStuff(String::toUpperCase)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
@JvmName("Fail")
|
||||
fun OK() {}
|
||||
|
||||
fun box() = ::OK.name
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
private fun foo() = "A"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = A::class.declaredFunctions.single() as KFunction<String>
|
||||
|
||||
try {
|
||||
f.call(A())
|
||||
return "Fail: no exception was thrown"
|
||||
} catch (e: IllegalCallableAccessException) {}
|
||||
|
||||
f.isAccessible = true
|
||||
|
||||
assertEquals("A", f.call(A()))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
open class A {
|
||||
fun mem() {}
|
||||
fun Int.memExt() {}
|
||||
}
|
||||
|
||||
class B : A()
|
||||
|
||||
fun box(): String {
|
||||
val all = A::class.functions.map { it.name }.sorted()
|
||||
assert(all == listOf("equals", "hashCode", "mem", "memExt", "toString")) { "Fail A functions: ${A::class.functions}" }
|
||||
|
||||
val declared = A::class.declaredFunctions.map { it.name }.sorted()
|
||||
assert(declared == listOf("mem", "memExt")) { "Fail A declaredFunctions: ${A::class.declaredFunctions}" }
|
||||
|
||||
val declaredSubclass = B::class.declaredFunctions.map { it.name }.sorted()
|
||||
assert(declaredSubclass.isEmpty()) { "Fail B declaredFunctions: ${B::class.declaredFunctions}" }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
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"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
interface A {
|
||||
fun foo(): Collection<Any>
|
||||
}
|
||||
|
||||
abstract class B : A {
|
||||
override fun foo(): Collection<String> = null!!
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val clazz = B::class.java
|
||||
if (clazz.declaredMethods.first().genericReturnType.toString() != "java.util.Collection<java.lang.String>") return "fail 1"
|
||||
|
||||
if (clazz.methods.filter { it.name == "foo" }.size != 1) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// WITH_REFLECT
|
||||
//test for KT-3722 Write correct generic type information for generated fields
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class Z<T> {
|
||||
|
||||
}
|
||||
|
||||
class TParam {
|
||||
|
||||
}
|
||||
|
||||
class Zout<out T> {
|
||||
|
||||
}
|
||||
|
||||
class Zin<in T> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Test<T>(val constructorProperty: T) {
|
||||
|
||||
val classField1 : Z<T>? = null
|
||||
|
||||
val classField2 : Z<String>? = null
|
||||
|
||||
val classField3 : Zout<String>? = null
|
||||
|
||||
val classField4 : Zin<TParam>? = null
|
||||
|
||||
val delegateLazy: Z<TParam>? by lazy {Z<TParam>()}
|
||||
|
||||
val delegateNotNull: Z<TParam>? by Delegates.notNull()
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val clz = Test::class.java
|
||||
|
||||
val constructorProperty = clz.getDeclaredField("constructorProperty");
|
||||
|
||||
if (constructorProperty.getGenericType().toString() != "T")
|
||||
return "fail0: " + constructorProperty.getGenericType();
|
||||
|
||||
|
||||
val classField = clz.getDeclaredField("classField1");
|
||||
|
||||
if (classField.getGenericType().toString() != "Z<T>")
|
||||
return "fail1:" + classField.getGenericType();
|
||||
|
||||
|
||||
val classField2 = clz.getDeclaredField("classField2");
|
||||
|
||||
if (classField2.getGenericType().toString() != "Z<java.lang.String>")
|
||||
return "fail2:" + classField2.getGenericType();
|
||||
|
||||
|
||||
val classField3 = clz.getDeclaredField("classField3");
|
||||
|
||||
if (classField3.getGenericType().toString() != "Zout<java.lang.String>")
|
||||
return "fail3:" + classField3.getGenericType();
|
||||
|
||||
|
||||
val classField4 = clz.getDeclaredField("classField4");
|
||||
|
||||
if (classField4.getGenericType().toString() != "Zin<TParam>")
|
||||
return "fail4:" + classField4.getGenericType();
|
||||
|
||||
val classField5 = clz.getDeclaredField("delegateLazy\$delegate");
|
||||
|
||||
if (classField5.getGenericType().toString() != "kotlin.Lazy<Z<TParam>>")
|
||||
return "fail5:" + classField5.getGenericType();
|
||||
|
||||
val classField6 = clz.getDeclaredField("delegateNotNull\$delegate");
|
||||
|
||||
if (classField6.getGenericType().toString() != "kotlin.properties.ReadWriteProperty<java.lang.Object, Z<TParam>>")
|
||||
return "fail6:" + classField6.getGenericType();
|
||||
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class Z<T> {}
|
||||
|
||||
class TParam {}
|
||||
|
||||
class Zout<out T> {}
|
||||
|
||||
class Zin<in T> {}
|
||||
|
||||
class Params(val methodIndex: Int, val paramClass: Class<*>, val expectedReturnType: String, val expecedParamType: String)
|
||||
|
||||
class Test<T, X, in Y>() {
|
||||
|
||||
fun test1(p: T): T? = null
|
||||
|
||||
fun test2(p: Z<T>): Z<T>? = null
|
||||
|
||||
fun test3(p: Z<String>): Z<String>? = null
|
||||
|
||||
fun test4(p: X): Zout<out String>? = null
|
||||
|
||||
fun test5(p: Y): Zin<in TParam>? = null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val clz = Test::class.java
|
||||
|
||||
val params = listOf(
|
||||
Params(1, Any::class.java, "T", "T"),
|
||||
Params(2, Z::class.java, "Z<T>", "Z<T>"),
|
||||
Params(3, Z::class.java, "Z<java.lang.String>", "Z<java.lang.String>"),
|
||||
Params(4, Any::class.java, "Zout<java.lang.String>", "X"),
|
||||
Params(5, Any::class.java, "Zin<TParam>", "Y")
|
||||
)
|
||||
|
||||
|
||||
var result: String = ""
|
||||
for(p in params) {
|
||||
val fail = test(clz, p.methodIndex, p.paramClass, p.expectedReturnType, p.expecedParamType)
|
||||
if (fail != "OK") {
|
||||
result += fail + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return if (result.isEmpty()) "OK" else result;
|
||||
|
||||
}
|
||||
|
||||
fun test(clazz: Class<*>, methodIndex: Int, paramClass: Class<*>, expectedReturn : String, expectedParam : String): String {
|
||||
val method = clazz.getDeclaredMethod("test$methodIndex", paramClass)!!;
|
||||
|
||||
if (method.getGenericReturnType().toString() != expectedReturn)
|
||||
return "fail$methodIndex: " + method.getGenericReturnType();
|
||||
|
||||
val test1Param = method.getGenericParameterTypes()!![0];
|
||||
|
||||
if (test1Param.toString() != expectedParam)
|
||||
return "fail${methodIndex}_param: " + test1Param;
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
class B<M>
|
||||
|
||||
interface A<T, Y : B<T>> {
|
||||
|
||||
fun <T, L> p(p: T): T {
|
||||
return p
|
||||
}
|
||||
|
||||
val <T> T.z : T?
|
||||
get() = null
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val defaultImpls = Class.forName("A\$DefaultImpls")
|
||||
val declaredMethod = defaultImpls.getDeclaredMethod("p", A::class.java, Any::class.java)
|
||||
if (declaredMethod.toGenericString() != "public static <T_I1,Y,T,L> T A\$DefaultImpls.p(A<T_I1, Y>,T)") return "fail 1: ${declaredMethod.toGenericString()}"
|
||||
|
||||
val declaredProperty = defaultImpls.getDeclaredMethod("getZ", A::class.java, Any::class.java)
|
||||
if (declaredProperty.toGenericString() != "public static <T_I1,Y,T> T A\$DefaultImpls.getZ(A<T_I1, Y>,T)") return "fail 2: ${declaredProperty.toGenericString()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
class G<T>(val s: T) {
|
||||
|
||||
}
|
||||
|
||||
public interface ErrorsJvmTrait {
|
||||
companion object {
|
||||
public val param : G<String> = G("STRING")
|
||||
}
|
||||
}
|
||||
|
||||
public class ErrorsJvmClass {
|
||||
companion object {
|
||||
@JvmField public val param : G<String> = G("STRING")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val genericTypeInClassObject = ErrorsJvmTrait.javaClass.getDeclaredField("param").getGenericType()
|
||||
if (genericTypeInClassObject.toString() != "test.G<java.lang.String>") return "fail1: $genericTypeInClassObject"
|
||||
|
||||
val genericTypeInClass = ErrorsJvmClass::class.java.getField("param").getGenericType()
|
||||
if (genericTypeInClass.toString() != "test.G<java.lang.String>") return "fail1: genericTypeInClass"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
open class B
|
||||
|
||||
class A {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun <T: B> a(s: T) : T {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val method = A::class.java.getDeclaredMethod("a", B::class.java)
|
||||
val genericParameterTypes = method.getGenericParameterTypes()
|
||||
|
||||
if (genericParameterTypes.size != 1) return "Wrong number of generic parameters"
|
||||
|
||||
if (genericParameterTypes[0].toString() != "T") return "Wrong parameter type ${genericParameterTypes[0].toString()}"
|
||||
|
||||
if (method.getGenericReturnType().toString() != "T") return "Wrong return type ${method.getGenericReturnType()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun checkPrimitive(clazz: Class<*>, expected: String) {
|
||||
assert (clazz!!.canonicalName == expected) {
|
||||
"clazz name: ${clazz.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun checkPrimitive(kClass: KClass<*>, expected: String) {
|
||||
checkPrimitive(kClass.java, expected)
|
||||
}
|
||||
|
||||
fun checkObject(clazz: Class<*>, expected: String) {
|
||||
assert (clazz.canonicalName == "$expected") {
|
||||
"clazz should be object, but found: ${clazz!!.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun checkObject(kClass: KClass<*>, expected: String) {
|
||||
checkObject(kClass.java, expected)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
checkPrimitive(Boolean::class.java, "boolean")
|
||||
checkPrimitive(Boolean::class, "boolean")
|
||||
|
||||
checkPrimitive(Char::class.java, "char")
|
||||
checkPrimitive(Char::class, "char")
|
||||
|
||||
checkPrimitive(Byte::class.java, "byte")
|
||||
checkPrimitive(Byte::class, "byte")
|
||||
|
||||
checkPrimitive(Short::class.java, "short")
|
||||
checkPrimitive(Short::class, "short")
|
||||
|
||||
checkPrimitive(Int::class.java, "int")
|
||||
checkPrimitive(Int::class, "int")
|
||||
|
||||
checkPrimitive(Float::class.java, "float")
|
||||
checkPrimitive(Float::class, "float")
|
||||
|
||||
checkPrimitive(Long::class.java, "long")
|
||||
checkPrimitive(Long::class, "long")
|
||||
|
||||
checkPrimitive(Double::class.java, "double")
|
||||
checkPrimitive(Double::class, "double")
|
||||
|
||||
checkObject(String::class.java, "java.lang.String")
|
||||
checkObject(String::class, "java.lang.String")
|
||||
|
||||
checkObject(Nothing::class.java, "java.lang.Void")
|
||||
checkObject(Nothing::class, "java.lang.Void")
|
||||
|
||||
checkObject(java.lang.Void::class.java, "java.lang.Void")
|
||||
checkObject(java.lang.Void::class, "java.lang.Void")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun check(clazz: Class<*>?, expected: String) {
|
||||
assert (clazz!!.canonicalName == expected) {
|
||||
"clazz name: ${clazz.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun check(kClass: KClass<*>, expected: String) {
|
||||
check(kClass.javaObjectType, expected)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(Boolean::class.javaObjectType, "java.lang.Boolean")
|
||||
check(Boolean::class, "java.lang.Boolean")
|
||||
|
||||
check(Char::class.javaObjectType, "java.lang.Character")
|
||||
check(Char::class, "java.lang.Character")
|
||||
|
||||
check(Byte::class.javaObjectType, "java.lang.Byte")
|
||||
check(Byte::class, "java.lang.Byte")
|
||||
|
||||
check(Short::class.javaObjectType, "java.lang.Short")
|
||||
check(Short::class, "java.lang.Short")
|
||||
|
||||
check(Int::class.javaObjectType, "java.lang.Integer")
|
||||
check(Int::class, "java.lang.Integer")
|
||||
|
||||
check(Float::class.javaObjectType, "java.lang.Float")
|
||||
check(Float::class, "java.lang.Float")
|
||||
|
||||
check(Long::class.javaObjectType, "java.lang.Long")
|
||||
check(Long::class, "java.lang.Long")
|
||||
|
||||
check(Double::class.javaObjectType, "java.lang.Double")
|
||||
check(Double::class, "java.lang.Double")
|
||||
|
||||
check(String::class.javaObjectType, "java.lang.String")
|
||||
check(String::class, "java.lang.String")
|
||||
|
||||
check(Nothing::class.javaObjectType, "java.lang.Void")
|
||||
check(Nothing::class, "java.lang.Void")
|
||||
|
||||
check(java.lang.Void::class.javaObjectType, "java.lang.Void")
|
||||
check(java.lang.Void::class, "java.lang.Void")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
inline fun <reified T : Any> check(expected: String) {
|
||||
val clazz = T::class.javaObjectType!!
|
||||
assert (clazz.canonicalName == "java.lang.${expected.capitalize()}") {
|
||||
"clazz name: ${clazz.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check<Boolean>("boolean")
|
||||
check<Char>("character")
|
||||
check<Byte>("byte")
|
||||
check<Short>("short")
|
||||
check<Int>("integer")
|
||||
check<Float>("float")
|
||||
check<Long>("long")
|
||||
check<Double>("double")
|
||||
|
||||
check<String>("String")
|
||||
check<java.lang.Void>("Void")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun check(clazz: Class<*>?, expected: String) {
|
||||
assert (clazz!!.canonicalName == expected) {
|
||||
"clazz name: ${clazz.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun check(kClass: KClass<*>, expected: String) {
|
||||
check(kClass.javaPrimitiveType, expected)
|
||||
}
|
||||
|
||||
fun checkNull(clazz: Class<*>?) {
|
||||
assert (clazz == null) {
|
||||
"clazz should be null: ${clazz!!.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun checkNull(kClass: KClass<*>) {
|
||||
checkNull(kClass.javaPrimitiveType)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(Boolean::class.javaPrimitiveType, "boolean")
|
||||
check(Boolean::class, "boolean")
|
||||
|
||||
check(Char::class.javaPrimitiveType, "char")
|
||||
check(Char::class, "char")
|
||||
|
||||
check(Byte::class.javaPrimitiveType, "byte")
|
||||
check(Byte::class, "byte")
|
||||
|
||||
check(Short::class.javaPrimitiveType, "short")
|
||||
check(Short::class, "short")
|
||||
|
||||
check(Int::class.javaPrimitiveType, "int")
|
||||
check(Int::class, "int")
|
||||
|
||||
check(Float::class.javaPrimitiveType, "float")
|
||||
check(Float::class, "float")
|
||||
|
||||
check(Long::class.javaPrimitiveType, "long")
|
||||
check(Long::class, "long")
|
||||
|
||||
check(Double::class.javaPrimitiveType, "double")
|
||||
check(Double::class, "double")
|
||||
|
||||
checkNull(String::class.javaPrimitiveType)
|
||||
checkNull(String::class)
|
||||
|
||||
checkNull(Nothing::class.javaPrimitiveType)
|
||||
checkNull(Nothing::class)
|
||||
|
||||
checkNull(java.lang.Void::class.javaPrimitiveType)
|
||||
checkNull(java.lang.Void::class)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
inline fun <reified T : Any> check(expected: String) {
|
||||
val clazz = T::class.javaPrimitiveType!!
|
||||
assert (clazz.canonicalName == expected) {
|
||||
"clazz name: ${clazz.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> checkNull() {
|
||||
val clazz = T::class.javaPrimitiveType
|
||||
assert (clazz == null) {
|
||||
"clazz should be null: ${clazz!!.canonicalName}"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check<Boolean>("boolean")
|
||||
check<Char>("char")
|
||||
check<Byte>("byte")
|
||||
check<Short>("short")
|
||||
check<Int>("int")
|
||||
check<Float>("float")
|
||||
check<Long>("long")
|
||||
check<Double>("double")
|
||||
|
||||
checkNull<String>()
|
||||
checkNull<java.lang.Void>()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user