Parcelize: Recognize (suspend) function types as serializable
This commit is contained in:
committed by
Yan Zhulanow
parent
a2418484bb
commit
aca9478998
+3
-1
@@ -230,7 +230,9 @@ class IrParcelSerializerFactory(symbols: AndroidSymbols) {
|
||||
classifier.isEnumClass ->
|
||||
return wrapNullableSerializerIfNeeded(irType, IrEnumParcelSerializer(classifier))
|
||||
|
||||
classifier.isSubclassOfFqName("java.io.Serializable") ->
|
||||
classifier.isSubclassOfFqName("java.io.Serializable")
|
||||
// Functions and Continuations are always serializable.
|
||||
|| irType.isFunctionTypeOrSubtype() || irType.isSuspendFunctionTypeOrSubtype() ->
|
||||
return serializableSerializer
|
||||
|
||||
strict() ->
|
||||
|
||||
+1
-1
@@ -301,7 +301,7 @@ interface ParcelSerializer {
|
||||
private fun Type.isSparseIntArray() = this.descriptor == "Landroid/util/SparseIntArray;"
|
||||
private fun Type.isSparseLongArray() = this.descriptor == "Landroid/util/SparseLongArray;"
|
||||
private fun Type.isSparseArray() = this.descriptor == "Landroid/util/SparseArray;"
|
||||
private fun KotlinType.isSerializable() = matchesFqNameWithSupertypes("java.io.Serializable")
|
||||
private fun KotlinType.isSerializable() = matchesFqNameWithSupertypes("java.io.Serializable") || matchesFqNameWithSupertypes("kotlin.Function")
|
||||
private fun KotlinType.isException() = matchesFqNameWithSupertypes("java.lang.Exception")
|
||||
private fun KotlinType.isIBinder() = matchesFqNameWithSupertypes("android.os.IBinder")
|
||||
private fun KotlinType.isIInterface() = matchesFqNameWithSupertypes("android.os.IInterface")
|
||||
|
||||
+5
@@ -109,6 +109,11 @@ public class ParcelBoxTestGenerated extends AbstractParcelBoxTest {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/exceptions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functions.kt")
|
||||
public void testFunctions() throws Exception {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intArray.kt")
|
||||
public void testIntArray() throws Exception {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/intArray.kt");
|
||||
|
||||
+5
@@ -109,6 +109,11 @@ public class ParcelIrBoxTestGenerated extends AbstractParcelIrBoxTest {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/exceptions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functions.kt")
|
||||
public void testFunctions() throws Exception {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intArray.kt")
|
||||
public void testIntArray() throws Exception {
|
||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/intArray.kt");
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class Test(val callback: () -> Int = { 0 }, val suspendCallback: suspend () -> Int = { 0 }) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val test = Test({ 1 }, { 1 })
|
||||
test.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val test2 = readFromParcel<Test>(parcel)
|
||||
|
||||
assert(test.callback() == 1)
|
||||
}
|
||||
Reference in New Issue
Block a user