Fix JVM Parcelize use of Parceler
This commit is contained in:
+4
-4
@@ -226,7 +226,7 @@ open class ParcelableCodegenExtension : ParcelableExtensionBase, ExpressionCodeg
|
||||
|
||||
v.getstatic(containerAsmType.internalName, companionFieldName, companionAsmType.descriptor)
|
||||
v.load(1, PARCEL_TYPE)
|
||||
v.invokevirtual(companionAsmType.internalName, "create", "(${PARCEL_TYPE.descriptor})Ljava/lang/Object;", false)
|
||||
v.invokevirtual(companionAsmType.internalName, "create", "(${PARCEL_TYPE.descriptor})$containerAsmType", false)
|
||||
}
|
||||
else {
|
||||
v.anew(containerAsmType)
|
||||
@@ -367,8 +367,8 @@ open class ParcelableCodegenExtension : ParcelableExtensionBase, ExpressionCodeg
|
||||
|
||||
v.getstatic(containerAsmType.internalName, companionFieldName, companionAsmType.descriptor)
|
||||
v.load(1, Type.INT_TYPE)
|
||||
v.invokevirtual(companionAsmType.internalName, "newArray", "(I)[Ljava/lang/Object;", false)
|
||||
v.areturn(Type.getType("[Ljava/lang/Object;"))
|
||||
v.invokevirtual(companionAsmType.internalName, "newArray", "(I)[$parcelableAsmType", false)
|
||||
v.areturn(Type.getType("[$parcelableAsmType"))
|
||||
|
||||
return@write
|
||||
}
|
||||
@@ -376,7 +376,7 @@ open class ParcelableCodegenExtension : ParcelableExtensionBase, ExpressionCodeg
|
||||
|
||||
v.load(1, Type.INT_TYPE)
|
||||
v.newarray(parcelableAsmType)
|
||||
v.areturn(Type.getType("[L$parcelableAsmType;"))
|
||||
v.areturn(Type.getType("[$parcelableAsmType"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class User(val firstName: String, val secondName: String, val age: Int) : Parcelable {
|
||||
companion object : Parceler<User> {
|
||||
override fun User.write(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(firstName)
|
||||
parcel.writeString(secondName)
|
||||
}
|
||||
|
||||
override fun create(parcel: Parcel) = User(parcel.readString(), parcel.readString(), 0)
|
||||
|
||||
override fun newArray(size: Int) = arrayOfNulls<User>(size) as Array<User>
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val user = User("John", "Smith", 20)
|
||||
val user2 = User("Joe", "Bloggs", 30)
|
||||
val array = arrayOf(user, user2)
|
||||
parcel.writeTypedArray(array, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val creator = User::class.java.getDeclaredField("CREATOR").get(null) as Parcelable.Creator<User>
|
||||
val result = parcel.createTypedArray(creator)
|
||||
|
||||
assert(result.size == 2)
|
||||
assert(result[0].firstName == user.firstName)
|
||||
assert(result[1].firstName == user2.firstName)
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize class TestParcel : Parcelable {
|
||||
companion object : Parceler<TestParcel> {
|
||||
override fun create(parcel: Parcel): TestParcel {
|
||||
return TestParcel()
|
||||
}
|
||||
override fun TestParcel.write(parcel: Parcel, flags: Int) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
TestParcel()
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class User(val firstName: String, val secondName: String, val age: Int) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val user = User("John", "Smith", 20)
|
||||
val user2 = User("Joe", "Bloggs", 30)
|
||||
val array = arrayOf(user, user2)
|
||||
parcel.writeTypedArray(array, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val creator = User::class.java.getDeclaredField("CREATOR").get(null) as Parcelable.Creator<User>
|
||||
val result = parcel.createTypedArray(creator)
|
||||
|
||||
assert(result.size == 2)
|
||||
assert(result[0].firstName == user.firstName)
|
||||
assert(result[1].firstName == user2.firstName)
|
||||
}
|
||||
Vendored
+1
-1
@@ -42,7 +42,7 @@ public final class User$Creator : java/lang/Object, android/os/Parcelable$Creato
|
||||
INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkNotNullParameter, (Ljava/lang/Object;Ljava/lang/String;)V)
|
||||
GETSTATIC (Companion, LUser$Companion;)
|
||||
ALOAD (1)
|
||||
INVOKEVIRTUAL (User$Companion, create, (Landroid/os/Parcel;)Ljava/lang/Object;)
|
||||
INVOKEVIRTUAL (User$Companion, create, (Landroid/os/Parcel;)LUser;)
|
||||
ARETURN
|
||||
LABEL (L1)
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public final class User$Creator : java/lang/Object, android/os/Parcelable$Creato
|
||||
LABEL (L0)
|
||||
GETSTATIC (Companion, LUser$Companion;)
|
||||
ILOAD (1)
|
||||
INVOKEVIRTUAL (User$Companion, newArray, (I)[Ljava/lang/Object;)
|
||||
INVOKEVIRTUAL (User$Companion, newArray, (I)[LUser;)
|
||||
ARETURN
|
||||
LABEL (L1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user