Support kotlinx.collections.immutable in kotlin-parcelize plugin
#KT-57685 Fixed Co-authored-by: Ilya Gulya <ilyagulya@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import kotlinx.parcelize.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import java.util.*
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
@Parcelize
|
||||
data class Test(
|
||||
@@ -21,7 +22,11 @@ data class Test(
|
||||
val h: HashSet<String>,
|
||||
val i: LinkedHashSet<String>,
|
||||
val j: NavigableSet<String>,
|
||||
val k: SortedSet<String>
|
||||
val k: SortedSet<String>,
|
||||
val l: PersistentList<String>,
|
||||
val m: PersistentSet<String>,
|
||||
val n: ImmutableList<String>,
|
||||
val o: ImmutableSet<String>,
|
||||
) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
@@ -36,7 +41,11 @@ fun box() = parcelTest { parcel ->
|
||||
h = HashSet<String>().apply { this += "H" },
|
||||
i = LinkedHashSet<String>().apply { this += "I" },
|
||||
j = TreeSet<String>().apply { this += "J" },
|
||||
k = TreeSet<String>().apply { this += "K" }
|
||||
k = TreeSet<String>().apply { this += "K" },
|
||||
l = persistentListOf("L"),
|
||||
m = persistentSetOf("M"),
|
||||
n = persistentListOf("N"),
|
||||
o = persistentSetOf("O"),
|
||||
)
|
||||
|
||||
first.writeToParcel(parcel, 0)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
|
||||
package test
|
||||
|
||||
import kotlinx.parcelize.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
@Parcelize
|
||||
data class Test(val a: PersistentList<String>) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val first = Test(persistentListOf("A", "B"))
|
||||
|
||||
first.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val first2 = parcelableCreator<Test>().createFromParcel(parcel)
|
||||
|
||||
assert(first == first2)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import kotlinx.parcelize.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import java.util.*
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
@Parcelize
|
||||
data class Test(
|
||||
@@ -17,7 +18,9 @@ data class Test(
|
||||
val d: LinkedHashMap<String, String>,
|
||||
val e: TreeMap<String, String>,
|
||||
val f: SortedMap<String, String>,
|
||||
val g: NavigableMap<String, String>
|
||||
val g: NavigableMap<String, String>,
|
||||
val h: PersistentMap<String, String>,
|
||||
val i: ImmutableMap<String, String>,
|
||||
) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
@@ -28,7 +31,9 @@ fun box() = parcelTest { parcel ->
|
||||
d = LinkedHashMap<String, String>().apply { put("A", "B") },
|
||||
e = TreeMap<String, String>().apply { put("A", "B") },
|
||||
f = TreeMap<String, String>().apply { put("A", "B") },
|
||||
g = TreeMap<String, String>().apply { put("A", "B") }
|
||||
g = TreeMap<String, String>().apply { put("A", "B") },
|
||||
h = persistentMapOf("A" to "B"),
|
||||
i = persistentMapOf("A" to "B"),
|
||||
)
|
||||
|
||||
first.writeToParcel(parcel, 0)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
|
||||
package test
|
||||
|
||||
import kotlinx.parcelize.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
@Parcelize
|
||||
data class Test(val a: PersistentMap<String, String>) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val first = Test(persistentMapOf("A" to "B", "C" to "D"))
|
||||
|
||||
first.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val first2 = parcelableCreator<Test>().createFromParcel(parcel)
|
||||
|
||||
assert(first == first2)
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
public final class Test$Creator : java/lang/Object, android/os/Parcelable$Creator {
|
||||
public void <init>()
|
||||
|
||||
public final Test createFromParcel(android.os.Parcel parcel) {
|
||||
LABEL (L0)
|
||||
ALOAD (1)
|
||||
LDC (parcel)
|
||||
INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkNotNullParameter, (Ljava/lang/Object;Ljava/lang/String;)V)
|
||||
NEW (Test)
|
||||
DUP
|
||||
ALOAD (1)
|
||||
INVOKEVIRTUAL (android/os/Parcel, createStringArrayList, ()Ljava/util/ArrayList;)
|
||||
CHECKCAST (java/lang/Iterable)
|
||||
INVOKESTATIC (kotlinx/collections/immutable/ExtensionsKt, toPersistentList, (Ljava/lang/Iterable;)Lkotlinx/collections/immutable/PersistentList;)
|
||||
INVOKESPECIAL (Test, <init>, (Lkotlinx/collections/immutable/PersistentList;)V)
|
||||
ARETURN
|
||||
LABEL (L1)
|
||||
}
|
||||
|
||||
public java.lang.Object createFromParcel(android.os.Parcel source) {
|
||||
LABEL (L0)
|
||||
ALOAD (0)
|
||||
ALOAD (1)
|
||||
INVOKEVIRTUAL (Test$Creator, createFromParcel, (Landroid/os/Parcel;)LTest;)
|
||||
ARETURN
|
||||
LABEL (L1)
|
||||
}
|
||||
|
||||
public final Test[] newArray(int size)
|
||||
|
||||
public java.lang.Object[] newArray(int size)
|
||||
}
|
||||
|
||||
public final class Test : java/lang/Object, android/os/Parcelable {
|
||||
public final static android.os.Parcelable$Creator CREATOR
|
||||
|
||||
private final kotlinx.collections.immutable.PersistentList names
|
||||
|
||||
static void <clinit>()
|
||||
|
||||
public void <init>(kotlinx.collections.immutable.PersistentList names)
|
||||
|
||||
public int describeContents()
|
||||
|
||||
public final kotlinx.collections.immutable.PersistentList getNames()
|
||||
|
||||
public void writeToParcel(android.os.Parcel out, int flags)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// CURIOUS_ABOUT: createFromParcel
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlinx.parcelize.*
|
||||
import android.os.Parcelable
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
@Parcelize
|
||||
class Test(val names: PersistentList<String>): Parcelable
|
||||
Reference in New Issue
Block a user