[AA] introduce KtAnnotationApplication

^KT-56046
This commit is contained in:
Dmitrii Gridin
2023-01-27 17:22:14 +01:00
committed by Space Team
parent 59f07c2197
commit 6e25b45f7d
27 changed files with 170 additions and 166 deletions
@@ -5,13 +5,13 @@
package org.jetbrains.kotlin.analysis.api.descriptors.annotations package org.jetbrains.kotlin.analysis.api.descriptors.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.maybeLocalClassId import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.maybeLocalClassId
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtAnnotationApplication import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtAnnotationOverview import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtAnnotationInfo
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
@@ -29,7 +29,7 @@ internal class KtFe10AnnotationsList private constructor(
override val token: KtLifetimeToken override val token: KtLifetimeToken
get() = analysisContext.token get() = analysisContext.token
override val annotations: List<KtAnnotationApplication> override val annotations: List<KtAnnotationApplicationWithArgumentsInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
fe10Annotations.mapIndexedNotNull { index, annotation -> fe10Annotations.mapIndexedNotNull { index, annotation ->
if (annotation.annotationClass.classId in annotationsToIgnore) if (annotation.annotationClass.classId in annotationsToIgnore)
@@ -39,13 +39,13 @@ internal class KtFe10AnnotationsList private constructor(
} }
} }
override val annotationOverviews: List<KtAnnotationOverview> override val annotationInfos: List<KtAnnotationApplicationInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
fe10Annotations.mapIndexedNotNull { index, annotation -> fe10Annotations.mapIndexedNotNull { index, annotation ->
if (annotation.annotationClass.classId in annotationsToIgnore) if (annotation.annotationClass.classId in annotationsToIgnore)
null null
else else
annotation.toKtAnnotationOverview(index) annotation.toKtAnnotationInfo(index)
} }
} }
@@ -73,7 +73,7 @@ internal class KtFe10AnnotationsList private constructor(
acceptAnnotationsWithoutUseSite: Boolean, acceptAnnotationsWithoutUseSite: Boolean,
): Boolean = hasAnnotation(classId) ): Boolean = hasAnnotation(classId)
override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = withValidityAssertion { override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> = withValidityAssertion {
if (classId in annotationsToIgnore) return@withValidityAssertion emptyList() if (classId in annotationsToIgnore) return@withValidityAssertion emptyList()
fe10Annotations.mapIndexedNotNull { index, annotation -> fe10Annotations.mapIndexedNotNull { index, annotation ->
@@ -457,7 +457,7 @@ internal fun ConstantValue<*>.toKtAnnotationValue(analysisContext: Fe10AnalysisC
is AnnotationValue -> { is AnnotationValue -> {
KtAnnotationApplicationValue( KtAnnotationApplicationValue(
KtAnnotationApplication( KtAnnotationApplicationWithArgumentsInfo(
value.annotationClass?.classId, value.annotationClass?.classId,
psi = null, psi = null,
useSiteTarget = null, useSiteTarget = null,
@@ -612,7 +612,7 @@ internal fun createKtInitializerValue(
internal fun AnnotationDescriptor.toKtAnnotationApplication( internal fun AnnotationDescriptor.toKtAnnotationApplication(
analysisContext: Fe10AnalysisContext, analysisContext: Fe10AnalysisContext,
index: Int, index: Int,
): KtAnnotationApplication = KtAnnotationApplication( ): KtAnnotationApplicationWithArgumentsInfo = KtAnnotationApplicationWithArgumentsInfo(
classId = classIdIfNonLocal, classId = classIdIfNonLocal,
psi = psi, psi = psi,
useSiteTarget = useSiteTarget, useSiteTarget = useSiteTarget,
@@ -620,11 +620,11 @@ internal fun AnnotationDescriptor.toKtAnnotationApplication(
index = index, index = index,
) )
internal fun AnnotationDescriptor.toKtAnnotationOverview(index: Int): KtAnnotationOverview = KtAnnotationOverview( internal fun AnnotationDescriptor.toKtAnnotationInfo(index: Int): KtAnnotationApplicationInfo = KtAnnotationApplicationInfo(
classId = classIdIfNonLocal, classId = classIdIfNonLocal,
psi = psi, psi = psi,
useSiteTarget = useSiteTarget, useSiteTarget = useSiteTarget,
hasArguments = allValueArguments.isNotEmpty(), isCallWithArguments = allValueArguments.isNotEmpty(),
index = index, index = index,
) )
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.analysis.api.fir package org.jetbrains.kotlin.analysis.api.fir
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.fir.annotations.mapAnnotationParameters import org.jetbrains.kotlin.analysis.api.fir.annotations.mapAnnotationParameters
import org.jetbrains.kotlin.analysis.api.fir.evaluate.FirAnnotationValueConverter import org.jetbrains.kotlin.analysis.api.fir.evaluate.FirAnnotationValueConverter
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
@@ -71,7 +71,7 @@ internal fun ConeDiagnostic.getCandidateSymbols(): Collection<FirBasedSymbol<*>>
internal fun FirAnnotation.toKtAnnotationApplication( internal fun FirAnnotation.toKtAnnotationApplication(
useSiteSession: FirSession, useSiteSession: FirSession,
index: Int, index: Int,
): KtAnnotationApplication = KtAnnotationApplication( ): KtAnnotationApplicationWithArgumentsInfo = KtAnnotationApplicationWithArgumentsInfo(
classId = toAnnotationClassId(useSiteSession), classId = toAnnotationClassId(useSiteSession),
psi = psi as? KtCallElement, psi = psi as? KtCallElement,
useSiteTarget = useSiteTarget, useSiteTarget = useSiteTarget,
@@ -82,10 +82,13 @@ internal fun FirAnnotation.toKtAnnotationApplication(
index = index, index = index,
) )
internal fun FirAnnotation.toKtAnnotationOverview(useSiteSession: FirSession, index: Int): KtAnnotationOverview = KtAnnotationOverview( internal fun FirAnnotation.toKtAnnotationInfo(
useSiteSession: FirSession,
index: Int,
): KtAnnotationApplicationInfo = KtAnnotationApplicationInfo(
classId = toAnnotationClassId(useSiteSession), classId = toAnnotationClassId(useSiteSession),
psi = psi as? KtCallElement, psi = psi as? KtCallElement,
useSiteTarget = useSiteTarget, useSiteTarget = useSiteTarget,
hasArguments = this is FirAnnotationCall && arguments.isNotEmpty(), isCallWithArguments = this is FirAnnotationCall && arguments.isNotEmpty(),
index = index, index = index,
) )
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.analysis.api.fir.annotations package org.jetbrains.kotlin.analysis.api.fir.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
@@ -21,14 +21,14 @@ internal class KtFirAnnotationListForDeclaration private constructor(
private val useSiteSession: FirSession, private val useSiteSession: FirSession,
override val token: KtLifetimeToken, override val token: KtLifetimeToken,
) : KtAnnotationsList() { ) : KtAnnotationsList() {
override val annotations: List<KtAnnotationApplication> override val annotations: List<KtAnnotationApplicationWithArgumentsInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
annotations(firSymbol, useSiteSession) annotations(firSymbol, useSiteSession)
} }
override val annotationOverviews: List<KtAnnotationOverview> override val annotationInfos: List<KtAnnotationApplicationInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
annotationOverviews(firSymbol, useSiteSession) annotationInfos(firSymbol, useSiteSession)
} }
override fun hasAnnotation( override fun hasAnnotation(
@@ -43,7 +43,7 @@ internal class KtFirAnnotationListForDeclaration private constructor(
hasAnnotation(firSymbol, classId, useSiteSession) hasAnnotation(firSymbol, classId, useSiteSession)
} }
override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = withValidityAssertion { override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> = withValidityAssertion {
annotationsByClassId(firSymbol, classId, useSiteSession) annotationsByClassId(firSymbol, classId, useSiteSession)
} }
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.analysis.api.fir.annotations package org.jetbrains.kotlin.analysis.api.fir.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
@@ -23,14 +23,14 @@ internal class KtFirAnnotationListForReceiverParameter private constructor(
private val useSiteSession: FirSession, private val useSiteSession: FirSession,
override val token: KtLifetimeToken, override val token: KtLifetimeToken,
) : KtAnnotationsList() { ) : KtAnnotationsList() {
override val annotations: List<KtAnnotationApplication> override val annotations: List<KtAnnotationApplicationWithArgumentsInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
annotations(firCallableSymbol, useSiteSession, receiverParameter) annotations(firCallableSymbol, useSiteSession, receiverParameter)
} }
override val annotationOverviews: List<KtAnnotationOverview> override val annotationInfos: List<KtAnnotationApplicationInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
annotationOverviews(firCallableSymbol, useSiteSession, receiverParameter) annotationInfos(firCallableSymbol, useSiteSession, receiverParameter)
} }
override fun hasAnnotation( override fun hasAnnotation(
@@ -45,7 +45,7 @@ internal class KtFirAnnotationListForReceiverParameter private constructor(
hasAnnotation(firCallableSymbol, classId, useSiteSession, receiverParameter) hasAnnotation(firCallableSymbol, classId, useSiteSession, receiverParameter)
} }
override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = withValidityAssertion { override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> = withValidityAssertion {
annotationsByClassId(firCallableSymbol, classId, useSiteSession, receiverParameter) annotationsByClassId(firCallableSymbol, classId, useSiteSession, receiverParameter)
} }
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.analysis.api.fir.annotations package org.jetbrains.kotlin.analysis.api.fir.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationApplication import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationOverview import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationInfo
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
@@ -31,17 +31,17 @@ internal class KtFirAnnotationListForType private constructor(
private val useSiteSession: FirSession, private val useSiteSession: FirSession,
override val token: KtLifetimeToken, override val token: KtLifetimeToken,
) : KtAnnotationsList() { ) : KtAnnotationsList() {
override val annotations: List<KtAnnotationApplication> override val annotations: List<KtAnnotationApplicationWithArgumentsInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
coneType.customAnnotationsWithLazyResolve(FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING).mapIndexed { index, annotation -> coneType.customAnnotationsWithLazyResolve(FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING).mapIndexed { index, annotation ->
annotation.toKtAnnotationApplication(useSiteSession, index) annotation.toKtAnnotationApplication(useSiteSession, index)
} }
} }
override val annotationOverviews: List<KtAnnotationOverview> override val annotationInfos: List<KtAnnotationApplicationInfo>
get() = withValidityAssertion { get() = withValidityAssertion {
coneType.customAnnotationsWithLazyResolve(FirResolvePhase.TYPES).mapIndexed { index, annotation -> coneType.customAnnotationsWithLazyResolve(FirResolvePhase.TYPES).mapIndexed { index, annotation ->
annotation.toKtAnnotationOverview(useSiteSession, index) annotation.toKtAnnotationInfo(useSiteSession, index)
} }
} }
@@ -60,7 +60,7 @@ internal class KtFirAnnotationListForType private constructor(
coneType.customAnnotationsWithLazyResolve(FirResolvePhase.TYPES).hasAnnotation(classId, useSiteSession) coneType.customAnnotationsWithLazyResolve(FirResolvePhase.TYPES).hasAnnotation(classId, useSiteSession)
} }
override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = withValidityAssertion { override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> = withValidityAssertion {
coneType.customAnnotationsWithLazyResolve(FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING).mapIndexedNotNull { index, annotation -> coneType.customAnnotationsWithLazyResolve(FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING).mapIndexedNotNull { index, annotation ->
if (annotation.toAnnotationClassId(useSiteSession) != classId) return@mapIndexedNotNull null if (annotation.toAnnotationClassId(useSiteSession) != classId) return@mapIndexedNotNull null
annotation.toKtAnnotationApplication(useSiteSession, index) annotation.toKtAnnotationApplication(useSiteSession, index)
@@ -5,10 +5,10 @@
package org.jetbrains.kotlin.analysis.api.fir.annotations package org.jetbrains.kotlin.analysis.api.fir.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationApplication import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationOverview import org.jetbrains.kotlin.analysis.api.fir.toKtAnnotationInfo
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry
import org.jetbrains.kotlin.analysis.utils.errors.checkWithAttachmentBuilder import org.jetbrains.kotlin.analysis.utils.errors.checkWithAttachmentBuilder
import org.jetbrains.kotlin.analysis.utils.errors.withClassEntry import org.jetbrains.kotlin.analysis.utils.errors.withClassEntry
@@ -45,7 +45,7 @@ internal fun annotationsByClassId(
classId: ClassId, classId: ClassId,
useSiteSession: FirSession, useSiteSession: FirSession,
annotationContainer: FirAnnotationContainer = firSymbol.fir, annotationContainer: FirAnnotationContainer = firSymbol.fir,
): List<KtAnnotationApplication> = ): List<KtAnnotationApplicationWithArgumentsInfo> =
if (firSymbol.isFromCompilerRequiredAnnotationsPhase(classId)) { if (firSymbol.isFromCompilerRequiredAnnotationsPhase(classId)) {
annotationContainer.resolvedCompilerRequiredAnnotations(firSymbol).mapIndexedNotNull { index, annotation -> annotationContainer.resolvedCompilerRequiredAnnotations(firSymbol).mapIndexedNotNull { index, annotation ->
if (annotation.toAnnotationClassIdSafe(useSiteSession) != classId) return@mapIndexedNotNull null if (annotation.toAnnotationClassIdSafe(useSiteSession) != classId) return@mapIndexedNotNull null
@@ -62,16 +62,17 @@ internal fun annotations(
firSymbol: FirBasedSymbol<*>, firSymbol: FirBasedSymbol<*>,
useSiteSession: FirSession, useSiteSession: FirSession,
annotationContainer: FirAnnotationContainer = firSymbol.fir, annotationContainer: FirAnnotationContainer = firSymbol.fir,
): List<KtAnnotationApplication> = annotationContainer.resolvedAnnotationsWithArguments(firSymbol).mapIndexed { index, annotation -> ): List<KtAnnotationApplicationWithArgumentsInfo> =
annotation.toKtAnnotationApplication(useSiteSession, index) annotationContainer.resolvedAnnotationsWithArguments(firSymbol).mapIndexed { index, annotation ->
} annotation.toKtAnnotationApplication(useSiteSession, index)
}
internal fun annotationOverviews( internal fun annotationInfos(
firSymbol: FirBasedSymbol<*>, firSymbol: FirBasedSymbol<*>,
useSiteSession: FirSession, useSiteSession: FirSession,
annotationContainer: FirAnnotationContainer = firSymbol.fir, annotationContainer: FirAnnotationContainer = firSymbol.fir,
): List<KtAnnotationOverview> = annotationContainer.resolvedAnnotationsWithClassIds(firSymbol).mapIndexed { index, annotation -> ): List<KtAnnotationApplicationInfo> = annotationContainer.resolvedAnnotationsWithClassIds(firSymbol).mapIndexed { index, annotation ->
annotation.toKtAnnotationOverview(useSiteSession, index) annotation.toKtAnnotationInfo(useSiteSession, index)
} }
internal fun annotationClassIds( internal fun annotationClassIds(
@@ -112,7 +112,7 @@ internal object FirAnnotationValueConverter {
} }
KtAnnotationApplicationValue( KtAnnotationApplicationValue(
KtAnnotationApplication( KtAnnotationApplicationWithArgumentsInfo(
resolvedSymbol.callableId.classId, resolvedSymbol.callableId.classId,
psi as? KtCallElement, psi as? KtCallElement,
useSiteTarget = null, useSiteTarget = null,
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.analysis.api.impl.base.annotations package org.jetbrains.kotlin.analysis.api.impl.base.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
@@ -14,11 +14,9 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
class KtEmptyAnnotationsList(override val token: KtLifetimeToken) : KtAnnotationsList() { class KtEmptyAnnotationsList(override val token: KtLifetimeToken) : KtAnnotationsList() {
override val annotations: List<KtAnnotationApplication> override val annotations: List<KtAnnotationApplicationWithArgumentsInfo> get() = withValidityAssertion { emptyList() }
get() = withValidityAssertion { emptyList() }
override val annotationOverviews: List<KtAnnotationOverview> override val annotationInfos: List<KtAnnotationApplicationInfo> get() = withValidityAssertion { emptyList() }
get() = withValidityAssertion { emptyList() }
override fun hasAnnotation( override fun hasAnnotation(
classId: ClassId, classId: ClassId,
@@ -28,9 +26,9 @@ class KtEmptyAnnotationsList(override val token: KtLifetimeToken) : KtAnnotation
override fun hasAnnotation(classId: ClassId): Boolean = withValidityAssertion { false } override fun hasAnnotation(classId: ClassId): Boolean = withValidityAssertion { false }
override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = override fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> = withValidityAssertion {
withValidityAssertion { emptyList() } emptyList()
}
override val annotationClassIds: Collection<ClassId> override val annotationClassIds: Collection<ClassId> get() = withValidityAssertion { emptyList() }
get() = withValidityAssertion { emptyList() } }
}
@@ -20,16 +20,16 @@ public interface KtAnnotated {
* *
* @see [KtAnnotationsList.annotations] * @see [KtAnnotationsList.annotations]
*/ */
public val KtAnnotated.annotations: List<KtAnnotationApplication> public val KtAnnotated.annotations: List<KtAnnotationApplicationWithArgumentsInfo>
get() = annotationsList.annotations get() = annotationsList.annotations
/** /**
* A list of annotation overviews. * A list of annotation overviews.
* *
* @see [KtAnnotationsList.annotationOverviews] * @see [KtAnnotationsList.annotationInfos]
*/ */
public val KtAnnotated.annotationOverviews: List<KtAnnotationOverview> public val KtAnnotated.annotationInfos: List<KtAnnotationApplicationInfo>
get() = annotationsList.annotationOverviews get() = annotationsList.annotationInfos
/** /**
* Checks if entity has annotation with specified [classId]. * Checks if entity has annotation with specified [classId].
@@ -54,7 +54,7 @@ public fun KtAnnotated.hasAnnotation(
* *
* @see [KtAnnotationsList.annotationClassIds] * @see [KtAnnotationsList.annotationClassIds]
*/ */
public fun KtAnnotated.annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> = public fun KtAnnotated.annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo> =
annotationsList.annotationsByClassId(classId) annotationsList.annotationsByClassId(classId)
/** /**
@@ -17,33 +17,33 @@ import org.jetbrains.kotlin.psi.KtCallElement
* - For types: `fun foo(x: List<@A Int>){}` * - For types: `fun foo(x: List<@A Int>){}`
* - Inside other annotation (`B` is annotation here): `@A(B()) fun foo(){} * - Inside other annotation (`B` is annotation here): `@A(B()) fun foo(){}
*/ */
public data class KtAnnotationApplication( public sealed interface KtAnnotationApplication {
/** /**
* The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class. * The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class.
*/ */
public val classId: ClassId?, public val classId: ClassId?
/** /**
* PsiElement which was used to apply annotation to declaration/type. * 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` * Present only for declarations from sources. For declarations from other places (libraries, stdlib) it's `null`
*/ */
public val psi: KtCallElement?, public val psi: KtCallElement?
/** /**
* [AnnotationUseSiteTarget] to which annotation was applied. May be not-null only for annotation applications for declarations. * [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. * 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?, public val useSiteTarget: AnnotationUseSiteTarget?
/** /**
* A list of annotation arguments which were applied when constructing annotation. Every argument is [KtAnnotationValue] * **true** if the annotation is a call with arguments
*/ */
public val arguments: List<KtNamedAnnotationValue>, public val isCallWithArguments: Boolean
/** /**
* An index of the annotation in an owner. Can be `-1` in case of annotation arguments * An index of the annotation in an owner. Can be `-1` in case of annotation arguments
*/ */
public val index: Int, public val index: Int
) }
@@ -16,33 +16,33 @@ import org.jetbrains.kotlin.psi.KtCallElement
* - For declarations: `@Deprecated("Should not be used") fun foo(){}` * - For declarations: `@Deprecated("Should not be used") fun foo(){}`
* - For types: `fun foo(x: List<@A Int>){}` * - For types: `fun foo(x: List<@A Int>){}`
*/ */
public data class KtAnnotationOverview( public data class KtAnnotationApplicationInfo(
/** /**
* The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class. * The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class.
*/ */
public val classId: ClassId?, public override val classId: ClassId?,
/** /**
* PsiElement which was used to apply annotation to declaration/type. * [com.intellij.psi.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` * Present only for declarations from sources. For declarations from other places (libraries, stdlib) it's `null`
*/ */
public val psi: KtCallElement?, public override val psi: KtCallElement?,
/** /**
* [AnnotationUseSiteTarget] to which annotation was applied. May be not-null only for annotation applications for declarations. * [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. * 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?, public override val useSiteTarget: AnnotationUseSiteTarget?,
/** /**
* **true** if the annotation has any arguments * **true** if the annotation has any arguments
*/ */
public val hasArguments: Boolean, public override val isCallWithArguments: Boolean,
/** /**
* An index of the annotation in an owner * An index of the annotation in an owner
*/ */
public val index: Int, public override val index: Int,
) ) : KtAnnotationApplication
@@ -0,0 +1,24 @@
/*
* 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
public data class KtAnnotationApplicationWithArgumentsInfo(
override val classId: ClassId?,
override val psi: KtCallElement?,
override val useSiteTarget: AnnotationUseSiteTarget?,
/**
* A list of annotation arguments which were applied when constructing annotation. Every argument is [KtAnnotationValue]
*/
public val arguments: List<KtNamedAnnotationValue>,
override val index: Int,
) : KtAnnotationApplication {
override val isCallWithArguments: Boolean get() = arguments.isNotEmpty()
}
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -50,7 +50,7 @@ public class KtArrayAnnotationValue(
* Other annotation used as argument. E.g: `@A(B)` where `B` is annotation too * Other annotation used as argument. E.g: `@A(B)` where `B` is annotation too
*/ */
public class KtAnnotationApplicationValue( public class KtAnnotationApplicationValue(
public val annotationValue: KtAnnotationApplication, public val annotationValue: KtAnnotationApplicationWithArgumentsInfo,
) : KtAnnotationValue() { ) : KtAnnotationValue() {
override val sourcePsi: KtElement? get() = annotationValue.psi override val sourcePsi: KtElement? get() = annotationValue.psi
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -56,7 +56,7 @@ internal object KtAnnotationValueRenderer {
renderAnnotationApplication(application.annotationValue) renderAnnotationApplication(application.annotationValue)
} }
private fun StringBuilder.renderAnnotationApplication(value: KtAnnotationApplication) { private fun StringBuilder.renderAnnotationApplication(value: KtAnnotationApplicationWithArgumentsInfo) {
append(value.classId) append(value.classId)
if (value.arguments.isNotEmpty()) { if (value.arguments.isNotEmpty()) {
append("(") append("(")
@@ -22,16 +22,16 @@ public abstract class KtAnnotationsList : KtLifetimeOwner {
* *
* @see KtAnnotationApplication * @see KtAnnotationApplication
*/ */
public abstract val annotations: List<KtAnnotationApplication> public abstract val annotations: List<KtAnnotationApplicationWithArgumentsInfo>
/** /**
* A list of annotation overviews. * A list of annotation overviews.
* *
* Can be used instead of [annotations] if applicable to reduce resolve. * Can be used instead of [annotations] if applicable to reduce resolve.
* *
* @see KtAnnotationOverview * @see KtAnnotationApplicationInfo
*/ */
public abstract val annotationOverviews: List<KtAnnotationOverview> public abstract val annotationInfos: List<KtAnnotationApplicationInfo>
/** /**
* Checks if entity contains annotation with specified [classId]. * Checks if entity contains annotation with specified [classId].
@@ -74,9 +74,9 @@ public abstract class KtAnnotationsList : KtLifetimeOwner {
* annotationsList.annotationsByClassId(classId) == annotationsList.annotations.filter { it.classId == classId } * annotationsList.annotationsByClassId(classId) == annotationsList.annotations.filter { it.classId == classId }
* ``` * ```
* *
* @see KtAnnotationApplication * @see KtAnnotationApplicationWithArgumentsInfo
*/ */
public abstract fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplication> public abstract fun annotationsByClassId(classId: ClassId): List<KtAnnotationApplicationWithArgumentsInfo>
/** /**
* A list of annotations [ClassId]. * A list of annotations [ClassId].
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValueRenderer import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValueRenderer
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
@@ -30,6 +31,8 @@ public interface KtAnnotationArgumentsRenderer {
owner: KtAnnotated, owner: KtAnnotated,
printer: PrettyPrinter printer: PrettyPrinter
) { ) {
if (annotation !is KtAnnotationApplicationWithArgumentsInfo) return
if (annotation.arguments.isEmpty()) return if (annotation.arguments.isEmpty()) return
printer.printCollection(annotation.arguments, prefix = "(", postfix = ")") { argument -> printer.printCollection(annotation.arguments, prefix = "(", postfix = ")") { argument ->
append(argument.name.render()) append(argument.name.render())
@@ -1,11 +1,11 @@
/* /*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * 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.signatures package org.jetbrains.kotlin.analysis.api.signatures
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtConstantAnnotationValue import org.jetbrains.kotlin.analysis.api.annotations.KtConstantAnnotationValue
import org.jetbrains.kotlin.analysis.api.annotations.annotationsByClassId import org.jetbrains.kotlin.analysis.api.annotations.annotationsByClassId
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
@@ -81,7 +81,7 @@ public class KtVariableLikeSignature<out S : KtVariableLikeSymbol>(
return (constantArgumentValue.constantValue.value as? String)?.let(Name::identifier) return (constantArgumentValue.constantValue.value as? String)?.let(Name::identifier)
} }
private fun findParameterNameAnnotation(): KtAnnotationApplication? { private fun findParameterNameAnnotation(): KtAnnotationApplicationWithArgumentsInfo? {
val allParameterNameAnnotations = returnType.annotationsByClassId(StandardNames.FqNames.parameterNameClassId) val allParameterNameAnnotations = returnType.annotationsByClassId(StandardNames.FqNames.parameterNameClassId)
val (explicitAnnotations, implicitAnnotations) = allParameterNameAnnotations.partition { it.psi != null } val (explicitAnnotations, implicitAnnotations) = allParameterNameAnnotations.partition { it.psi != null }
@@ -16,7 +16,10 @@ import org.jetbrains.kotlin.analysis.api.contracts.description.KtContractEffectD
import org.jetbrains.kotlin.analysis.api.contracts.description.renderKtContractEffectDeclaration import org.jetbrains.kotlin.analysis.api.contracts.description.renderKtContractEffectDeclaration
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossiblyNamedSymbol import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossiblyNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.* import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType
import org.jetbrains.kotlin.analysis.api.types.KtClassTypeQualifier
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.project.structure.KtModule import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
@@ -246,11 +249,15 @@ public class DebugSymbolRenderer(
private fun PrettyPrinter.renderAnnotationApplication(call: KtAnnotationApplication) { private fun PrettyPrinter.renderAnnotationApplication(call: KtAnnotationApplication) {
renderValue(call.classId, renderSymbolsFully = false) renderValue(call.classId, renderSymbolsFully = false)
append('(') append('(')
call.arguments.sortedBy { it.name }.forEachIndexed { index, value -> if (call is KtAnnotationApplicationWithArgumentsInfo) {
if (index > 0) { call.arguments.sortedBy { it.name }.forEachIndexed { index, value ->
append(", ") if (index > 0) {
append(", ")
}
renderValue(value, renderSymbolsFully = false)
} }
renderValue(value, renderSymbolsFully = false) } else {
append("isCallWithArguments=${call.isCallWithArguments}")
} }
append(')') append(')')
@@ -118,7 +118,7 @@ private fun SymbolLightLazyAnnotation.tryConvertToRetentionJavaAnnotation(
) )
private fun SymbolLightJavaAnnotation.computeJavaRetentionArguments(): List<KtNamedAnnotationValue> { private fun SymbolLightJavaAnnotation.computeJavaRetentionArguments(): List<KtNamedAnnotationValue> {
val argumentWithKotlinRetention = originalLightAnnotation.annotationApplication val argumentWithKotlinRetention = originalLightAnnotation.annotationApplicationWithArgumentsInfo
.value .value
.arguments .arguments
.firstOrNull { .firstOrNull {
@@ -203,7 +203,7 @@ private fun SymbolLightLazyAnnotation.tryConvertToTargetJavaAnnotation(
) )
private fun SymbolLightJavaAnnotation.computeTargetJavaAnnotationArguments(): List<KtNamedAnnotationValue> { private fun SymbolLightJavaAnnotation.computeTargetJavaAnnotationArguments(): List<KtNamedAnnotationValue> {
val allowedKotlinTargets = originalLightAnnotation.annotationApplication val allowedKotlinTargets = originalLightAnnotation.annotationApplicationWithArgumentsInfo
.value .value
.arguments .arguments
.firstOrNull() .firstOrNull()
@@ -5,13 +5,13 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
internal sealed interface AnnotationsProvider { internal sealed interface AnnotationsProvider {
fun annotationOverviews(): List<KtAnnotationOverview> fun annotationInfos(): List<KtAnnotationApplicationInfo>
operator fun get(classId: ClassId): Collection<KtAnnotationApplication> operator fun get(classId: ClassId): Collection<KtAnnotationApplicationWithArgumentsInfo>
operator fun contains(classId: ClassId): Boolean operator fun contains(classId: ClassId): Boolean
fun isTheSameAs(other: Any?): Boolean fun isTheSameAs(other: Any?): Boolean
fun ownerClassId(): ClassId? fun ownerClassId(): ClassId?
@@ -5,20 +5,20 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
internal class CompositeAnnotationsProvider(val providers: Collection<AnnotationsProvider>) : AnnotationsProvider { internal class CompositeAnnotationsProvider(val providers: Collection<AnnotationsProvider>) : AnnotationsProvider {
constructor(vararg providers: AnnotationsProvider) : this(providers.toList()) constructor(vararg providers: AnnotationsProvider) : this(providers.toList())
override fun annotationOverviews(): List<KtAnnotationOverview> = buildList { override fun annotationInfos(): List<KtAnnotationApplicationInfo> = buildList {
for (provider in providers) { for (provider in providers) {
addAll(provider.annotationOverviews()) addAll(provider.annotationInfos())
} }
} }
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = buildList { override fun get(classId: ClassId): Collection<KtAnnotationApplicationWithArgumentsInfo> = buildList {
for (provider in providers) { for (provider in providers) {
addAll(provider[classId]) addAll(provider[classId])
} }
@@ -5,13 +5,13 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations package org.jetbrains.kotlin.light.classes.symbol.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationInfo
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
internal object EmptyAnnotationsProvider : AnnotationsProvider { internal object EmptyAnnotationsProvider : AnnotationsProvider {
override fun annotationOverviews(): List<KtAnnotationOverview> = emptyList() override fun annotationInfos(): List<KtAnnotationApplicationInfo> = emptyList()
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = emptyList() override fun get(classId: ClassId): Collection<KtAnnotationApplicationWithArgumentsInfo> = emptyList()
override fun contains(classId: ClassId): Boolean = false override fun contains(classId: ClassId): Boolean = false
override fun isTheSameAs(other: Any?): Boolean = this === other override fun isTheSameAs(other: Any?): Boolean = this === other
override fun ownerClassId(): ClassId? = null override fun ownerClassId(): ClassId? = null
@@ -24,9 +24,9 @@ internal class LazyAnnotationsBox(
override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> { override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> {
annotationsArray.get()?.let { return it } annotationsArray.get()?.let { return it }
val annotations = annotationsProvider.annotationOverviews().mapNotNullTo(SmartList<PsiAnnotation>()) { val annotations = annotationsProvider.annotationInfos().mapNotNullTo(SmartList<PsiAnnotation>()) { applicationInfo ->
it.classId?.let { classId -> applicationInfo.classId?.let { _ ->
SymbolLightLazyAnnotation(classId, annotationsProvider, it, owner) SymbolLightLazyAnnotation(annotationsProvider, applicationInfo, owner)
} }
} }
@@ -73,13 +73,7 @@ internal class LazyAnnotationsBox(
val specialAnnotationClassId = specialAnnotationsList[qualifiedName] val specialAnnotationClassId = specialAnnotationsList[qualifiedName]
val specialAnnotation = if (specialAnnotationClassId != null) { val specialAnnotation = if (specialAnnotationClassId != null) {
val annotationApplication = annotationsProvider[specialAnnotationClassId].firstOrNull() ?: return null val annotationApplication = annotationsProvider[specialAnnotationClassId].firstOrNull() ?: return null
SymbolLightLazyAnnotation(annotationsProvider, annotationApplication, owner)
SymbolLightLazyAnnotation(
specialAnnotationClassId,
annotationsProvider,
annotationApplication,
owner,
)
} else if (withAdditionalAnnotations) { } else if (withAdditionalAnnotations) {
additionalAnnotationsProvider.findAdditionalAnnotation(this, qualifiedName, owner) additionalAnnotationsProvider.findAdditionalAnnotation(this, qualifiedName, owner)
} else { } else {
@@ -24,13 +24,13 @@ internal class SymbolAnnotationsProvider<T : KtAnnotatedSymbol>(
private inline fun <T> withAnnotatedSymbol(crossinline action: context(KtAnalysisSession) (KtAnnotatedSymbol) -> T): T = private inline fun <T> withAnnotatedSymbol(crossinline action: context(KtAnalysisSession) (KtAnnotatedSymbol) -> T): T =
annotatedSymbolPointer.withSymbol(ktModule, action) annotatedSymbolPointer.withSymbol(ktModule, action)
override fun annotationOverviews(): List<KtAnnotationOverview> = withAnnotatedSymbol { annotatedSymbol -> override fun annotationInfos(): List<KtAnnotationApplicationInfo> = withAnnotatedSymbol { annotatedSymbol ->
annotatedSymbol.annotationOverviews.filter { annotatedSymbol.annotationInfos.filter {
it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null
} }
} }
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = withAnnotatedSymbol { annotatedSymbol -> override fun get(classId: ClassId): Collection<KtAnnotationApplicationWithArgumentsInfo> = withAnnotatedSymbol { annotatedSymbol ->
annotatedSymbol.annotationsByClassId(classId).filter { annotatedSymbol.annotationsByClassId(classId).filter {
it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null
} }
@@ -8,64 +8,39 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotationParameterList import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiModifierList import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplicationWithArgumentsInfo
import org.jetbrains.kotlin.asJava.classes.lazyPub import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtCallElement import org.jetbrains.kotlin.psi.KtCallElement
internal class SymbolLightLazyAnnotation private constructor( internal class SymbolLightLazyAnnotation(
private val classId: ClassId,
val annotationsProvider: AnnotationsProvider, val annotationsProvider: AnnotationsProvider,
private val annotationOverview: KtAnnotationOverview?, private val annotationApplication: KtAnnotationApplication,
private val specialAnnotationApplication: KtAnnotationApplication?,
owner: PsiModifierList, owner: PsiModifierList,
) : SymbolLightAbstractAnnotation(owner) { ) : SymbolLightAbstractAnnotation(owner) {
init { init {
require(annotationOverview != null || specialAnnotationApplication != null) requireNotNull(annotationApplication.classId)
} }
private val classId: ClassId get() = annotationApplication.classId!!
private val fqName: FqName = classId.asSingleFqName() private val fqName: FqName = classId.asSingleFqName()
val annotationApplication: Lazy<KtAnnotationApplication> = specialAnnotationApplication?.let(::lazyOf) ?: lazyPub { val annotationApplicationWithArgumentsInfo: Lazy<KtAnnotationApplicationWithArgumentsInfo> =
val applications = annotationsProvider[classId] (annotationApplication as? KtAnnotationApplicationWithArgumentsInfo)?.let(::lazyOf) ?: lazyPub {
applications.find { it.index == annotationOverview?.index } val applications = annotationsProvider[classId]
?: error("expected index: ${annotationOverview?.index}, actual indices: ${applications.map { it.index }}") applications.find { it.index == annotationApplication.index }
} ?: error("expected application: ${annotationApplication}, actual indices: ${applications.map { it.index }}")
}
constructor( override val kotlinOrigin: KtCallElement? get() = annotationApplicationWithArgumentsInfo.value.psi
classId: ClassId,
annotationsProvider: AnnotationsProvider,
annotationOverview: KtAnnotationOverview,
owner: PsiModifierList,
) : this(
classId = classId,
annotationsProvider = annotationsProvider,
annotationOverview = annotationOverview,
specialAnnotationApplication = null,
owner = owner,
)
constructor(
classId: ClassId,
annotationsProvider: AnnotationsProvider,
annotationApplication: KtAnnotationApplication,
owner: PsiModifierList,
) : this(
classId = classId,
annotationsProvider = annotationsProvider,
annotationOverview = null,
specialAnnotationApplication = annotationApplication,
owner = owner,
)
override val kotlinOrigin: KtCallElement? get() = annotationApplication.value.psi
override fun getQualifiedName(): String = fqName.asString() override fun getQualifiedName(): String = fqName.asString()
private val _parameterList: PsiAnnotationParameterList by lazyPub { private val _parameterList: PsiAnnotationParameterList by lazyPub {
if (annotationOverview?.hasArguments == true || !specialAnnotationApplication?.arguments.isNullOrEmpty()) { if (annotationApplication.isCallWithArguments) {
SymbolLightLazyAnnotationParameterList(this, lazyPub { annotationApplication.value.arguments }) SymbolLightLazyAnnotationParameterList(this, lazyPub { annotationApplicationWithArgumentsInfo.value.arguments })
} else { } else {
SymbolLightEmptyAnnotationParameterList(this) SymbolLightEmptyAnnotationParameterList(this)
} }
@@ -76,8 +51,7 @@ internal class SymbolLightLazyAnnotation private constructor(
override fun equals(other: Any?): Boolean = this === other || override fun equals(other: Any?): Boolean = this === other ||
other is SymbolLightLazyAnnotation && other is SymbolLightLazyAnnotation &&
other.fqName == fqName && other.fqName == fqName &&
other.annotationOverview == annotationOverview && other.annotationApplication == annotationApplication &&
other.specialAnnotationApplication == specialAnnotationApplication &&
annotationsProvider.isTheSameAs(other.annotationsProvider) && annotationsProvider.isTheSameAs(other.annotationsProvider) &&
other.parent == parent other.parent == parent
@@ -72,7 +72,7 @@ internal fun KtAnnotatedSymbol.findAnnotation(
classId: ClassId, classId: ClassId,
annotationUseSiteTarget: AnnotationUseSiteTarget?, annotationUseSiteTarget: AnnotationUseSiteTarget?,
acceptAnnotationsWithoutUseSite: Boolean = false, acceptAnnotationsWithoutUseSite: Boolean = false,
): KtAnnotationApplication? { ): KtAnnotationApplicationWithArgumentsInfo? {
if (!hasAnnotation(classId, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)) return null if (!hasAnnotation(classId, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)) return null
return annotations.find { return annotations.find {