Parcelize: Generate non-final 'writeToParcel()' and 'describeContents()' (#KT-24720)

This commit is contained in:
Yan Zhulanow
2018-06-18 19:28:15 +03:00
parent adf3057fea
commit 26ca7a140d
4 changed files with 33 additions and 5 deletions
@@ -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) {
@@ -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)
}
}