diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableDeclarationChecker.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableDeclarationChecker.kt index 4e63a80b473..98b6c0f81ba 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableDeclarationChecker.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableDeclarationChecker.kt @@ -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) diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/diagnostic/DefaultErrorMessagesAndroid.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/diagnostic/DefaultErrorMessagesAndroid.kt index 7ee8042f181..922a850264d 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/diagnostic/DefaultErrorMessagesAndroid.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/diagnostic/DefaultErrorMessagesAndroid.kt @@ -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") diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddTransientAnnotationQuickfix.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddIgnoreOnParcelAnnotationQuickfix.kt similarity index 72% rename from plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddTransientAnnotationQuickfix.kt rename to plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddIgnoreOnParcelAnnotationQuickfix.kt index 6acb8982919..e3e3341740a 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddTransientAnnotationQuickfix.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableAddIgnoreOnParcelAnnotationQuickfix.kt @@ -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(property) { - object Factory : AbstractFactory({ findElement()?.let(::ParcelableAddTransientAnnotationQuickfix) }) - override fun getText() = "Add ''@Transient'' annotation" +class ParcelableAddIgnoreOnParcelAnnotationQuickfix(property: KtProperty) : AbstractParcelableQuickFix(property) { + object Factory : AbstractFactory({ findElement()?.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() } } \ No newline at end of file diff --git a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableQuickFixContributor.kt b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableQuickFixContributor.kt index f92a820afaf..727fa4f7d88 100644 --- a/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableQuickFixContributor.kt +++ b/plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/parcel/quickfixes/ParcelableQuickFixContributor.kt @@ -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) diff --git a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/checker/properties.kt b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/checker/properties.kt index 9595db73195..10a2b191dcd 100644 --- a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/checker/properties.kt +++ b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/checker/properties.kt @@ -5,11 +5,11 @@ import android.os.Parcelable @Parcelize class A(val firstName: String) : Parcelable { - val secondName: String = "" + val secondName: String = "" - val delegated by lazy { "" } + val delegated by lazy { "" } - lateinit var lateinit: String + lateinit var lateinit: String val customGetter: String get() = "" diff --git a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.after.kt b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.after.kt index e9ceb68c141..61a9e833d59 100644 --- a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.after.kt +++ b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.after.kt @@ -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 { } @Parcelize -@TypeParceler -class Foo(val a: String) : Parcelable \ No newline at end of file +class Foo(@TypeParceler val a: String) \ No newline at end of file diff --git a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.before.Main.kt b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.before.Main.kt index 778c15d36c7..863af3bb14d 100644 --- a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.before.Main.kt +++ b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/classShouldBeAnnotated/simple.before.Main.kt @@ -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 diff --git a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.after.kt b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.after.kt index dbb8ad5360f..d31e8b00143 100644 --- a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.after.kt +++ b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.after.kt @@ -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 a = 5 } \ No newline at end of file diff --git a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.before.Main.kt b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.before.Main.kt index c13552aba64..6d4310ce575 100644 --- a/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.before.Main.kt +++ b/plugins/android-extensions/android-extensions-idea/testData/android/parcel/quickfix/propertyWontBeSerialized/simple.before.Main.kt @@ -1,4 +1,4 @@ -// "Add ''@Transient'' annotation" "true" +// "Add ''@IgnoredOnParcel'' annotation" "true" // WITH_RUNTIME package com.myapp.activity diff --git a/plugins/android-extensions/android-extensions-runtime/src/kotlinx/android/parcel/IgnoredOnParcel.kt b/plugins/android-extensions/android-extensions-runtime/src/kotlinx/android/parcel/IgnoredOnParcel.kt new file mode 100644 index 00000000000..26459be2b7b --- /dev/null +++ b/plugins/android-extensions/android-extensions-runtime/src/kotlinx/android/parcel/IgnoredOnParcel.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlinx.android.parcel + +@Target(AnnotationTarget.PROPERTY) +@Retention(AnnotationRetention.SOURCE) +annotation class IgnoredOnParcel \ No newline at end of file