[AA] KtAnnotationsList: introduce 'annotationOverviews'
it provides a solution for several problems with redundant resolve. It is a more powerful tool than 'annotationClassIds' ^KT-56046
This commit is contained in:
committed by
Space Team
parent
24041bf96d
commit
3a7602a38f
+9
-1
@@ -23,6 +23,14 @@ public interface KtAnnotated {
|
||||
public val KtAnnotated.annotations: List<KtAnnotationApplication>
|
||||
get() = annotationsList.annotations
|
||||
|
||||
/**
|
||||
* A list of annotation overviews.
|
||||
*
|
||||
* @see [KtAnnotationsList.annotationOverviews]
|
||||
*/
|
||||
public val KtAnnotated.annotationOverviews: List<KtAnnotationOverview>
|
||||
get() = annotationsList.annotationOverviews
|
||||
|
||||
/**
|
||||
* Checks if entity has annotation with specified [classId].
|
||||
*
|
||||
@@ -55,4 +63,4 @@ public fun KtAnnotated.annotationsByClassId(classId: ClassId): List<KtAnnotation
|
||||
* @see [KtAnnotationsList.annotationClassIds]
|
||||
*/
|
||||
public val KtAnnotated.annotationClassIds: Collection<ClassId>
|
||||
get() = annotationsList.annotationClassIds
|
||||
get() = annotationsList.annotationClassIds
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
/**
|
||||
* Overview of annotation to some declaration or type.
|
||||
*
|
||||
* Some examples:
|
||||
* - For declarations: `@Deprecated("Should not be used") fun foo(){}`
|
||||
* - For types: `fun foo(x: List<@A Int>){}`
|
||||
*/
|
||||
public data class KtAnnotationOverview(
|
||||
/**
|
||||
* The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class.
|
||||
*/
|
||||
public val classId: ClassId?,
|
||||
|
||||
/**
|
||||
* PsiElement which was used to apply annotation to declaration/type.
|
||||
*
|
||||
* Present only for declarations from sources. For declarations from other places (libraries, stdlib) it's `null`
|
||||
*/
|
||||
public val psi: KtCallElement?,
|
||||
|
||||
/**
|
||||
* [AnnotationUseSiteTarget] to which annotation was applied. May be not-null only for annotation applications for declarations.
|
||||
*
|
||||
* See in more details in [Kotlin Documentation](https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets) for more information about annotation targets.
|
||||
*/
|
||||
public val useSiteTarget: AnnotationUseSiteTarget?,
|
||||
|
||||
/**
|
||||
* **true** if the annotation has any arguments
|
||||
*/
|
||||
public val hasArguments: Boolean,
|
||||
|
||||
/**
|
||||
* An index of the annotation in an owner
|
||||
*/
|
||||
public val index: Int,
|
||||
)
|
||||
+9
-1
@@ -24,6 +24,15 @@ public abstract class KtAnnotationsList : KtLifetimeOwner {
|
||||
*/
|
||||
public abstract val annotations: List<KtAnnotationApplication>
|
||||
|
||||
/**
|
||||
* A list of annotation overviews.
|
||||
*
|
||||
* Can be used instead of [annotations] if applicable to reduce resolve.
|
||||
*
|
||||
* @see KtAnnotationOverview
|
||||
*/
|
||||
public abstract val annotationOverviews: List<KtAnnotationOverview>
|
||||
|
||||
/**
|
||||
* Checks if entity contains annotation with specified [classId].
|
||||
*
|
||||
@@ -81,4 +90,3 @@ public abstract class KtAnnotationsList : KtLifetimeOwner {
|
||||
*/
|
||||
public abstract val annotationClassIds: Collection<ClassId>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user