Parcelable: Use @IgnoredOnParcel annotation instead of Transient cause it's inapplicable on properties (KT-20298)

This commit is contained in:
Yan Zhulanow
2017-09-18 20:05:01 +03:00
parent cafd99660a
commit 8c7f469030
10 changed files with 42 additions and 19 deletions
@@ -16,14 +16,15 @@
package org.jetbrains.kotlin.android.parcel.quickfixes
import kotlinx.android.parcel.IgnoredOnParcel
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
class ParcelableAddTransientAnnotationQuickfix(property: KtProperty) : AbstractParcelableQuickFix<KtProperty>(property) {
object Factory : AbstractFactory({ findElement<KtProperty>()?.let(::ParcelableAddTransientAnnotationQuickfix) })
override fun getText() = "Add ''@Transient'' annotation"
class ParcelableAddIgnoreOnParcelAnnotationQuickfix(property: KtProperty) : AbstractParcelableQuickFix<KtProperty>(property) {
object Factory : AbstractFactory({ findElement<KtProperty>()?.let(::ParcelableAddIgnoreOnParcelAnnotationQuickfix) })
override fun getText() = "Add ''@IgnoredOnParcel'' annotation"
override fun invoke(ktPsiFactory: KtPsiFactory, element: KtProperty) {
element.addAnnotationEntry(ktPsiFactory.createAnnotationEntry("@" + Transient::class.java.name)).shortenReferences()
element.addAnnotationEntry(ktPsiFactory.createAnnotationEntry("@" + IgnoredOnParcel::class.java.name)).shortenReferences()
}
}
@@ -29,7 +29,7 @@ class ParcelableQuickFixContributor : QuickFixContributor {
quickFixes.register(ErrorsAndroid.NO_PARCELABLE_SUPERTYPE, ParcelableAddSupertypeQuickfix.Factory)
quickFixes.register(ErrorsAndroid.PARCELABLE_SHOULD_HAVE_PRIMARY_CONSTRUCTOR, ParcelableAddPrimaryConstructorQuickfix.Factory)
quickFixes.register(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED, ParcelableAddTransientAnnotationQuickfix.Factory)
quickFixes.register(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED, ParcelableAddIgnoreOnParcelAnnotationQuickfix.Factory)
quickFixes.register(ErrorsAndroid.OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED, ParcelMigrateToParcelizeQuickFix.FactoryForWrite)
quickFixes.register(ErrorsAndroid.OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED, ParcelRemoveCustomWriteToParcel.Factory)
@@ -5,11 +5,11 @@ import android.os.Parcelable
@Parcelize
class A(val firstName: String) : Parcelable {
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to remove the warning">secondName</warning>: String = ""
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">secondName</warning>: String = ""
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to remove the warning">delegated</warning> by lazy { "" }
val <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">delegated</warning> by lazy { "" }
lateinit var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@Transient' annotation to remove the warning">lateinit</warning>: String
lateinit var <warning descr="[PROPERTY_WONT_BE_SERIALIZED] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">lateinit</warning>: String
val customGetter: String
get() = ""
@@ -1,5 +1,5 @@
// "Annotate with ''@Parcelize''" "true"
// ERROR: Class 'Foo' should be annotated with ''@Parcelize''
// "Annotate containing class with ''@Parcelize''" "true"
// ERROR: Class 'Foo' should be annotated with '@Parcelize'
// WITH_RUNTIME
package com.myapp.activity
@@ -13,5 +13,4 @@ object StringParceler : Parceler<String> {
}
@Parcelize
@TypeParceler<String, StringParceler>
class Foo(<caret>val a: String) : Parcelable
class Foo(@<caret>TypeParceler<String, StringParceler> val a: String)
@@ -1,5 +1,5 @@
// "Annotate containing class with ''@Parcelize''" "true"
// ERROR: Class 'Foo' should be annotated with ''@Parcelize''
// ERROR: Class 'Foo' should be annotated with '@Parcelize'
// WITH_RUNTIME
package com.myapp.activity
@@ -1,13 +1,14 @@
// "Add ''@Transient'' annotation" "true"
// "Add ''@IgnoredOnParcel'' annotation" "true"
// WITH_RUNTIME
package com.myapp.activity
import android.os.Parcelable
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
@Parcelize
class Test : Parcelable {
@Transient
@IgnoredOnParcel
val <caret>a = 5
}
@@ -1,4 +1,4 @@
// "Add ''@Transient'' annotation" "true"
// "Add ''@IgnoredOnParcel'' annotation" "true"
// WITH_RUNTIME
package com.myapp.activity