[SLC] AnnotationsProvider: migrate to classIds to annotationOverviews
^KT-56046
This commit is contained in:
committed by
Space Team
parent
3a7602a38f
commit
aa9e7444c9
+2
-1
@@ -6,10 +6,11 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
internal sealed interface AnnotationsProvider {
|
||||
fun classIds(): Collection<ClassId>
|
||||
fun annotationOverviews(): List<KtAnnotationOverview>
|
||||
operator fun get(classId: ClassId): Collection<KtAnnotationApplication>
|
||||
operator fun contains(classId: ClassId): Boolean
|
||||
fun isTheSameAs(other: Any?): Boolean
|
||||
|
||||
+5
-2
@@ -6,12 +6,15 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
internal class CompositeAnnotationsProvider(val providers: Collection<AnnotationsProvider>) : AnnotationsProvider {
|
||||
override fun classIds(): Collection<ClassId> = buildList {
|
||||
constructor(vararg providers: AnnotationsProvider) : this(providers.toList())
|
||||
|
||||
override fun annotationOverviews(): List<KtAnnotationOverview> = buildList {
|
||||
for (provider in providers) {
|
||||
addAll(provider.classIds())
|
||||
addAll(provider.annotationOverviews())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -6,10 +6,11 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
object EmptyAnnotationsProvider : AnnotationsProvider {
|
||||
override fun classIds(): Collection<ClassId> = emptyList()
|
||||
override fun annotationOverviews(): List<KtAnnotationOverview> = emptyList()
|
||||
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = emptyList()
|
||||
override fun contains(classId: ClassId): Boolean = false
|
||||
override fun isTheSameAs(other: Any?): Boolean = this === other
|
||||
|
||||
+4
-3
@@ -23,9 +23,10 @@ internal class LazyAnnotationsBox(
|
||||
override fun annotations(owner: PsiModifierList): Array<PsiAnnotation> {
|
||||
annotationsArray.get()?.let { return it }
|
||||
|
||||
val classIds = annotationsProvider.classIds()
|
||||
val annotations = classIds.withIndex().mapTo(SmartList<PsiAnnotation>()) { (index, classId) ->
|
||||
SymbolLightLazyAnnotation(classId, annotationsProvider, index, owner)
|
||||
val annotations = annotationsProvider.annotationOverviews().mapNotNullTo(SmartList<PsiAnnotation>()) {
|
||||
it.classId?.let { classId ->
|
||||
SymbolLightLazyAnnotation(classId, annotationsProvider, it, owner)
|
||||
}
|
||||
}
|
||||
|
||||
val valueToReturn = synchronized(monitor) {
|
||||
|
||||
+3
-6
@@ -6,10 +6,7 @@
|
||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotationClassIds
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotationsByClassId
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.hasAnnotation
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtAnnotatedSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -24,8 +21,8 @@ internal class SymbolAnnotationsProvider<T : KtAnnotatedSymbol>(
|
||||
private inline fun <T> withAnnotatedSymbol(crossinline action: context(KtAnalysisSession) (KtAnnotatedSymbol) -> T): T =
|
||||
annotatedSymbolPointer.withSymbol(ktModule, action)
|
||||
|
||||
override fun classIds(): Collection<ClassId> = withAnnotatedSymbol { annotatedSymbol ->
|
||||
annotatedSymbol.annotationClassIds
|
||||
override fun annotationOverviews(): List<KtAnnotationOverview> = withAnnotatedSymbol { annotatedSymbol ->
|
||||
annotatedSymbol.annotationOverviews
|
||||
}
|
||||
|
||||
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = withAnnotatedSymbol { annotatedSymbol ->
|
||||
|
||||
+11
-8
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||
import com.intellij.psi.PsiAnnotationParameterList
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -16,30 +17,31 @@ import org.jetbrains.kotlin.psi.KtCallElement
|
||||
internal class SymbolLightLazyAnnotation private constructor(
|
||||
private val classId: ClassId,
|
||||
val annotationsProvider: AnnotationsProvider,
|
||||
private val index: Int?,
|
||||
specialAnnotationApplication: KtAnnotationApplication?,
|
||||
private val annotationOverview: KtAnnotationOverview?,
|
||||
private val specialAnnotationApplication: KtAnnotationApplication?,
|
||||
owner: PsiModifierList,
|
||||
) : SymbolLightAbstractAnnotation(owner) {
|
||||
init {
|
||||
require(index != null || specialAnnotationApplication != null)
|
||||
require(annotationOverview != null || specialAnnotationApplication != null)
|
||||
}
|
||||
|
||||
private val fqName: FqName = classId.asSingleFqName()
|
||||
|
||||
val annotationApplication: Lazy<KtAnnotationApplication> = specialAnnotationApplication?.let(::lazyOf) ?: lazyPub {
|
||||
val applications = annotationsProvider[classId]
|
||||
applications.find { it.index == index } ?: error("expected index: $index, actual indices: ${applications.map { it.index }}")
|
||||
applications.find { it.index == annotationOverview?.index }
|
||||
?: error("expected index: ${annotationOverview?.index}, actual indices: ${applications.map { it.index }}")
|
||||
}
|
||||
|
||||
constructor(
|
||||
classId: ClassId,
|
||||
annotationsProvider: AnnotationsProvider,
|
||||
index: Int,
|
||||
annotationOverview: KtAnnotationOverview,
|
||||
owner: PsiModifierList,
|
||||
) : this(
|
||||
classId = classId,
|
||||
annotationsProvider = annotationsProvider,
|
||||
index = index,
|
||||
annotationOverview = annotationOverview,
|
||||
specialAnnotationApplication = null,
|
||||
owner = owner,
|
||||
)
|
||||
@@ -52,7 +54,7 @@ internal class SymbolLightLazyAnnotation private constructor(
|
||||
) : this(
|
||||
classId = classId,
|
||||
annotationsProvider = annotationsProvider,
|
||||
index = null,
|
||||
annotationOverview = null,
|
||||
specialAnnotationApplication = annotationApplication,
|
||||
owner = owner,
|
||||
)
|
||||
@@ -70,7 +72,8 @@ internal class SymbolLightLazyAnnotation private constructor(
|
||||
override fun equals(other: Any?): Boolean = this === other ||
|
||||
other is SymbolLightLazyAnnotation &&
|
||||
other.fqName == fqName &&
|
||||
other.index == index &&
|
||||
other.annotationOverview == annotationOverview &&
|
||||
other.specialAnnotationApplication == specialAnnotationApplication &&
|
||||
annotationsProvider.isTheSameAs(other.annotationsProvider) &&
|
||||
other.parent == parent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user