Add default implementation for Annotations.findAnnotation
This commit is contained in:
@@ -26,9 +26,9 @@ interface Annotations : Iterable<AnnotationDescriptor> {
|
||||
|
||||
fun isEmpty(): Boolean
|
||||
|
||||
fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||
fun findAnnotation(fqName: FqName): AnnotationDescriptor? = firstOrNull { it.fqName == fqName }
|
||||
|
||||
fun hasAnnotation(fqName: FqName) = findAnnotation(fqName) != null
|
||||
fun hasAnnotation(fqName: FqName): Boolean = findAnnotation(fqName) != null
|
||||
|
||||
fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor? = null
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.annotations
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class AnnotationsImpl : Annotations {
|
||||
private val annotations: List<AnnotationDescriptor>
|
||||
private val targetedAnnotations: List<AnnotationWithTarget>
|
||||
@@ -38,8 +36,6 @@ class AnnotationsImpl : Annotations {
|
||||
|
||||
override fun isEmpty() = targetedAnnotations.isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull { it.fqName == fqName }
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> {
|
||||
return targetedAnnotations
|
||||
.filter { it.target != null }
|
||||
|
||||
@@ -58,14 +58,12 @@ fun TypeParameterDescriptor.hasOnlyInputTypesAnnotation(): Boolean = annotations
|
||||
fun getExactInAnnotations(): Annotations = AnnotationsWithOnly(EXACT_ANNOTATION_FQ_NAME)
|
||||
|
||||
private class AnnotationsWithOnly(val presentAnnotation: FqName): Annotations {
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> = listOf<AnnotationDescriptor>().iterator()
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> = emptyList<AnnotationDescriptor>().iterator()
|
||||
|
||||
override fun isEmpty(): Boolean = false
|
||||
|
||||
override fun hasAnnotation(fqName: FqName): Boolean = fqName == this.presentAnnotation
|
||||
|
||||
override fun findAnnotation(fqName: FqName): AnnotationDescriptor? = null
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> = emptyList()
|
||||
|
||||
override fun getAllAnnotations(): List<AnnotationWithTarget> = emptyList()
|
||||
|
||||
-2
@@ -31,8 +31,6 @@ open class DeserializedAnnotations(
|
||||
|
||||
override fun isEmpty(): Boolean = annotations.isEmpty()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull { it.fqName == fqName }
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> = emptyList()
|
||||
|
||||
override fun getAllAnnotations(): List<AnnotationWithTarget> = annotations.map { AnnotationWithTarget(it, null) }
|
||||
|
||||
Reference in New Issue
Block a user