Parcelize: Recognize '@IgnoredOnParcel' with @get: use-site annotation target
This commit is contained in:
+14
-2
@@ -18,6 +18,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||||
import org.jetbrains.kotlin.diagnostics.reportFromPlugin
|
import org.jetbrains.kotlin.diagnostics.reportFromPlugin
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
@@ -83,9 +86,18 @@ class ParcelableDeclarationChecker : DeclarationChecker {
|
|||||||
diagnosticHolder: DiagnosticSink,
|
diagnosticHolder: DiagnosticSink,
|
||||||
bindingContext: BindingContext
|
bindingContext: BindingContext
|
||||||
) {
|
) {
|
||||||
|
fun hasIgnoredOnParcel(): Boolean {
|
||||||
|
fun AnnotationDescriptor.isIgnoredOnParcel() = fqName == IGNORED_ON_PARCEL_FQNAME
|
||||||
|
|
||||||
|
fun Annotations.hasIgnoredOnParcel() = getAllAnnotations()
|
||||||
|
.any { (it.target == null || it.target == AnnotationUseSiteTarget.PROPERTY_GETTER) && it.annotation.isIgnoredOnParcel() }
|
||||||
|
|
||||||
|
return property.annotations.hasIgnoredOnParcel() || (property.getter?.annotations?.hasIgnoredOnParcel() ?: false)
|
||||||
|
}
|
||||||
|
|
||||||
if (containingClass.isParcelize
|
if (containingClass.isParcelize
|
||||||
&& (declaration.hasDelegate() || bindingContext[BindingContext.BACKING_FIELD_REQUIRED, property] == true)
|
&& (declaration.hasDelegate() || bindingContext[BindingContext.BACKING_FIELD_REQUIRED, property] == true)
|
||||||
&& !property.annotations.hasAnnotation(IGNORED_ON_PARCEL_FQNAME)
|
&& !hasIgnoredOnParcel()
|
||||||
) {
|
) {
|
||||||
val reportElement = declaration.nameIdentifier ?: declaration
|
val reportElement = declaration.nameIdentifier ?: declaration
|
||||||
diagnosticHolder.reportFromPlugin(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED.on(reportElement), DefaultErrorMessagesAndroid)
|
diagnosticHolder.reportFromPlugin(ErrorsAndroid.PROPERTY_WONT_BE_SERIALIZED.on(reportElement), DefaultErrorMessagesAndroid)
|
||||||
|
|||||||
Vendored
+1
-1
@@ -29,7 +29,7 @@ class B(<warning descr="[PLUGIN_WARNING] '@IgnoredOnParcel' is inapplicable to p
|
|||||||
var <warning descr="[PLUGIN_WARNING] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">b</warning>: String = ""
|
var <warning descr="[PLUGIN_WARNING] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">b</warning>: String = ""
|
||||||
|
|
||||||
@get:IgnoredOnParcel
|
@get:IgnoredOnParcel
|
||||||
var <warning descr="[PLUGIN_WARNING] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">c</warning>: String = ""
|
var c: String = ""
|
||||||
|
|
||||||
@set:IgnoredOnParcel
|
@set:IgnoredOnParcel
|
||||||
var <warning descr="[PLUGIN_WARNING] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">d</warning>: String = ""
|
var <warning descr="[PLUGIN_WARNING] Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning">d</warning>: String = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user