Drop Annotations.getAllAnnotations

This commit is contained in:
Alexander Udalov
2018-08-16 12:18:36 +02:00
parent 83fbabd628
commit 87c0d56618
22 changed files with 51 additions and 109 deletions
@@ -88,10 +88,10 @@ class ParcelableAnnotationChecker : CallChecker {
val descriptor = context.trace[BindingContext.DECLARATION_TO_DESCRIPTOR, element] ?: return
val thisMappedType = resolvedCall.typeArguments.values.takeIf { it.size == 2 }?.first() ?: return
val duplicatingAnnotationCount = descriptor.annotations.getAllAnnotations()
.filter { it.annotation.fqName == TYPE_PARCELER_FQNAME }
.mapNotNull { it.annotation.type.arguments.takeIf { it.size == 2 }?.first()?.type }
.count { it == thisMappedType }
val duplicatingAnnotationCount = descriptor.annotations
.filter { it.fqName == TYPE_PARCELER_FQNAME }
.mapNotNull { it.type.arguments.takeIf { args -> args.size == 2 }?.first()?.type }
.count { it == thisMappedType }
if (duplicatingAnnotationCount > 1) {
val reportElement = annotationEntry.typeArguments.firstOrNull() ?: annotationEntry
@@ -19,8 +19,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
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.reportFromPlugin
@@ -88,10 +86,7 @@ class ParcelableDeclarationChecker : DeclarationChecker {
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() }
fun Annotations.hasIgnoredOnParcel() = any { it.fqName == IGNORED_ON_PARCEL_FQNAME }
return property.annotations.hasIgnoredOnParcel() || (property.getter?.annotations?.hasIgnoredOnParcel() ?: false)
}