Files
kotlin-fork/plugins/parcelize/parcelize-compiler/testData/box/kt20717.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

31 lines
710 B
Kotlin
Vendored

// WITH_STDLIB
@file:JvmName("TestKt")
package test
import kotlinx.parcelize.*
import android.os.Parcel
import android.os.Parcelable
fun box() = doTest { creator ->
assert(creator.newArray(5) != null)
}
fun doTest(work: (Parcelable.Creator<DummyParcelable>) -> Unit): String {
val dummy = DummyParcelable(42)
val clazz = dummy.javaClass
val field = clazz.getDeclaredField("CREATOR")
@Suppress("UNCHECKED_CAST")
val creator = field.get(dummy) as Parcelable.Creator<DummyParcelable>
val parcel = Parcel.obtain()
dummy.writeToParcel(parcel, 0)
parcel.setDataPosition(0)
work(creator)
return "OK"
}
@Parcelize
data class DummyParcelable(val int: Int): Parcelable