Parcelize: Add the Parcelize compiler plugin with sources extracted from Android Extensions plugin (KT-40030)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@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")
|
||||
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
|
||||
Reference in New Issue
Block a user