Parcelable: Use @IgnoredOnParcel annotation instead of Transient cause it's inapplicable on properties (KT-20298)
This commit is contained in:
+3
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.android.parcel
|
||||
|
||||
import kotlinx.android.parcel.IgnoredOnParcel
|
||||
import org.jetbrains.kotlin.android.parcel.serializers.ParcelSerializer
|
||||
import org.jetbrains.kotlin.android.parcel.serializers.isParcelable
|
||||
import org.jetbrains.kotlin.android.synthetic.diagnostic.DefaultErrorMessagesAndroid
|
||||
@@ -46,7 +47,7 @@ val ANDROID_PARCEL_CLASS_FQNAME = FqName("android.os.Parcel")
|
||||
|
||||
class ParcelableDeclarationChecker : SimpleDeclarationChecker {
|
||||
private companion object {
|
||||
private val TRANSIENT_FQNAME = FqName(Transient::class.java.canonicalName)
|
||||
private val IGNORED_ON_PARCEL_FQNAME = FqName(IgnoredOnParcel::class.java.canonicalName)
|
||||
}
|
||||
|
||||
override fun check(
|
||||
@@ -97,7 +98,7 @@ class ParcelableDeclarationChecker : SimpleDeclarationChecker {
|
||||
) {
|
||||
if (containingClass.isParcelize
|
||||
&& (declaration.hasDelegate() || bindingContext[BindingContext.BACKING_FIELD_REQUIRED, property] == true)
|
||||
&& !property.annotations.hasAnnotation(TRANSIENT_FQNAME)
|
||||
&& !property.annotations.hasAnnotation(IGNORED_ON_PARCEL_FQNAME)
|
||||
) {
|
||||
val reportElement = declaration.nameIdentifier ?: declaration
|
||||
diagnosticHolder.reportFromPlugin(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED.on(reportElement), DefaultErrorMessagesAndroid)
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ object DefaultErrorMessagesAndroid : DefaultErrorMessages.Extension {
|
||||
"'Parcelable' constructor parameter should be 'val' or 'var'")
|
||||
|
||||
MAP.put(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED,
|
||||
"Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to remove the warning")
|
||||
"Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning")
|
||||
|
||||
MAP.put(ErrorsAndroid.OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED,
|
||||
"Overriding 'writeToParcel' is not allowed. Use 'Parceler' companion object instead")
|
||||
|
||||
Reference in New Issue
Block a user