Parcelize: Generate non-final 'writeToParcel()' and 'describeContents()' (#KT-24720)
This commit is contained in:
+5
-2
@@ -245,7 +245,10 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
|
||||
val containerAsmType = codegen.typeMapper.mapType(parcelableClass)
|
||||
val creatorAsmType = codegen.typeMapper.mapType(creatorClass)
|
||||
|
||||
createMethod(creatorClass, CREATE_FROM_PARCEL, parcelableClass.builtIns.anyType, "in" to parcelClassType).write(codegen) {
|
||||
createMethod(
|
||||
creatorClass, CREATE_FROM_PARCEL, Modality.FINAL,
|
||||
parcelableClass.builtIns.anyType, "in" to parcelClassType
|
||||
).write(codegen) {
|
||||
if (parcelerObject != null) {
|
||||
val (companionAsmType, companionFieldName) = getCompanionClassType(containerAsmType, parcelerObject)
|
||||
|
||||
@@ -361,7 +364,7 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
|
||||
val builtIns = parcelableClass.builtIns
|
||||
val parcelableAsmType = codegen.typeMapper.mapType(parcelableClass)
|
||||
|
||||
createMethod(creatorClass, NEW_ARRAY,
|
||||
createMethod(creatorClass, NEW_ARRAY, Modality.FINAL,
|
||||
builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType),
|
||||
"size" to builtIns.intType
|
||||
).write(codegen) {
|
||||
|
||||
+5
-3
@@ -47,6 +47,7 @@ open class ParcelableResolveExtension : SyntheticResolveExtension {
|
||||
fun createMethod(
|
||||
classDescriptor: ClassDescriptor,
|
||||
componentKind: ParcelableSyntheticComponent.ComponentKind,
|
||||
modality: Modality,
|
||||
returnType: KotlinType,
|
||||
vararg parameters: Pair<String, KotlinType>
|
||||
): SimpleFunctionDescriptor {
|
||||
@@ -65,7 +66,7 @@ open class ParcelableResolveExtension : SyntheticResolveExtension {
|
||||
|
||||
functionDescriptor.initialize(
|
||||
null, classDescriptor.thisAsReceiverParameter, emptyList(), valueParameters,
|
||||
returnType, Modality.FINAL, Visibilities.PUBLIC)
|
||||
returnType, modality, Visibilities.PUBLIC)
|
||||
|
||||
return functionDescriptor
|
||||
}
|
||||
@@ -98,7 +99,7 @@ open class ParcelableResolveExtension : SyntheticResolveExtension {
|
||||
&& result.none { it.isDescribeContents() }
|
||||
&& fromSupertypes.none { it.isDescribeContents() }
|
||||
) {
|
||||
result += createMethod(clazz, DESCRIBE_CONTENTS, clazz.builtIns.intType)
|
||||
result += createMethod(clazz, DESCRIBE_CONTENTS, Modality.OPEN, clazz.builtIns.intType)
|
||||
} else if (name.asString() == WRITE_TO_PARCEL.methodName
|
||||
&& clazz.isParcelize
|
||||
&& isExperimental()
|
||||
@@ -106,7 +107,8 @@ open class ParcelableResolveExtension : SyntheticResolveExtension {
|
||||
) {
|
||||
val builtIns = clazz.builtIns
|
||||
val parcelClassType = resolveParcelClassType(clazz.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type")
|
||||
result += createMethod(clazz, WRITE_TO_PARCEL, builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType)
|
||||
result += createMethod(clazz, WRITE_TO_PARCEL, Modality.OPEN,
|
||||
builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -22,7 +22,10 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
class ParcelBoxTest : AbstractParcelBoxTest() {
|
||||
fun testSimple() = doTest("simple")
|
||||
fun testPrimitiveTypes() = doTest("primitiveTypes")
|
||||
@@ -56,6 +59,7 @@ class ParcelBoxTest : AbstractParcelBoxTest() {
|
||||
fun testKt20717() = doTest("kt20717")
|
||||
fun testEnumObject() = doTest("enumObject")
|
||||
fun testIntArray() = doTest("intArray")
|
||||
fun testOpenParcelize() = doTest("openParcelize")
|
||||
}
|
||||
|
||||
class ParcelBoxTestWithSerializableLikeExtension : AbstractParcelBoxTest() {
|
||||
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize
|
||||
open class Base(val a: String) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
class Inh(var b: Int) : Base(""), Parcelable
|
||||
|
||||
fun box(): String {
|
||||
Inh(0)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user