[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
|
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||||
|
|
||||||
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.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
internal sealed interface AnnotationsProvider {
|
internal sealed interface AnnotationsProvider {
|
||||||
fun classIds(): Collection<ClassId>
|
fun annotationOverviews(): List<KtAnnotationOverview>
|
||||||
operator fun get(classId: ClassId): Collection<KtAnnotationApplication>
|
operator fun get(classId: ClassId): Collection<KtAnnotationApplication>
|
||||||
operator fun contains(classId: ClassId): Boolean
|
operator fun contains(classId: ClassId): Boolean
|
||||||
fun isTheSameAs(other: Any?): Boolean
|
fun isTheSameAs(other: Any?): Boolean
|
||||||
|
|||||||
+5
-2
@@ -6,12 +6,15 @@
|
|||||||
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.KtAnnotationApplication
|
||||||
|
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||||
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 {
|
||||||
override fun classIds(): Collection<ClassId> = buildList {
|
constructor(vararg providers: AnnotationsProvider) : this(providers.toList())
|
||||||
|
|
||||||
|
override fun annotationOverviews(): List<KtAnnotationOverview> = buildList {
|
||||||
for (provider in providers) {
|
for (provider in providers) {
|
||||||
addAll(provider.classIds())
|
addAll(provider.annotationOverviews())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -6,10 +6,11 @@
|
|||||||
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.KtAnnotationApplication
|
||||||
|
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationOverview
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
object EmptyAnnotationsProvider : AnnotationsProvider {
|
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 get(classId: ClassId): Collection<KtAnnotationApplication> = 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
|
||||||
|
|||||||
+4
-3
@@ -23,9 +23,10 @@ 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 classIds = annotationsProvider.classIds()
|
val annotations = annotationsProvider.annotationOverviews().mapNotNullTo(SmartList<PsiAnnotation>()) {
|
||||||
val annotations = classIds.withIndex().mapTo(SmartList<PsiAnnotation>()) { (index, classId) ->
|
it.classId?.let { classId ->
|
||||||
SymbolLightLazyAnnotation(classId, annotationsProvider, index, owner)
|
SymbolLightLazyAnnotation(classId, annotationsProvider, it, owner)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val valueToReturn = synchronized(monitor) {
|
val valueToReturn = synchronized(monitor) {
|
||||||
|
|||||||
+3
-6
@@ -6,10 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
package org.jetbrains.kotlin.light.classes.symbol.annotations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||||
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.symbols.KtClassLikeSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtAnnotatedSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtAnnotatedSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
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 =
|
private inline fun <T> withAnnotatedSymbol(crossinline action: context(KtAnalysisSession) (KtAnnotatedSymbol) -> T): T =
|
||||||
annotatedSymbolPointer.withSymbol(ktModule, action)
|
annotatedSymbolPointer.withSymbol(ktModule, action)
|
||||||
|
|
||||||
override fun classIds(): Collection<ClassId> = withAnnotatedSymbol { annotatedSymbol ->
|
override fun annotationOverviews(): List<KtAnnotationOverview> = withAnnotatedSymbol { annotatedSymbol ->
|
||||||
annotatedSymbol.annotationClassIds
|
annotatedSymbol.annotationOverviews
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = withAnnotatedSymbol { annotatedSymbol ->
|
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.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.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
|
||||||
@@ -16,30 +17,31 @@ import org.jetbrains.kotlin.psi.KtCallElement
|
|||||||
internal class SymbolLightLazyAnnotation private constructor(
|
internal class SymbolLightLazyAnnotation private constructor(
|
||||||
private val classId: ClassId,
|
private val classId: ClassId,
|
||||||
val annotationsProvider: AnnotationsProvider,
|
val annotationsProvider: AnnotationsProvider,
|
||||||
private val index: Int?,
|
private val annotationOverview: KtAnnotationOverview?,
|
||||||
specialAnnotationApplication: KtAnnotationApplication?,
|
private val specialAnnotationApplication: KtAnnotationApplication?,
|
||||||
owner: PsiModifierList,
|
owner: PsiModifierList,
|
||||||
) : SymbolLightAbstractAnnotation(owner) {
|
) : SymbolLightAbstractAnnotation(owner) {
|
||||||
init {
|
init {
|
||||||
require(index != null || specialAnnotationApplication != null)
|
require(annotationOverview != null || specialAnnotationApplication != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val fqName: FqName = classId.asSingleFqName()
|
private val fqName: FqName = classId.asSingleFqName()
|
||||||
|
|
||||||
val annotationApplication: Lazy<KtAnnotationApplication> = specialAnnotationApplication?.let(::lazyOf) ?: lazyPub {
|
val annotationApplication: Lazy<KtAnnotationApplication> = specialAnnotationApplication?.let(::lazyOf) ?: lazyPub {
|
||||||
val applications = annotationsProvider[classId]
|
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(
|
constructor(
|
||||||
classId: ClassId,
|
classId: ClassId,
|
||||||
annotationsProvider: AnnotationsProvider,
|
annotationsProvider: AnnotationsProvider,
|
||||||
index: Int,
|
annotationOverview: KtAnnotationOverview,
|
||||||
owner: PsiModifierList,
|
owner: PsiModifierList,
|
||||||
) : this(
|
) : this(
|
||||||
classId = classId,
|
classId = classId,
|
||||||
annotationsProvider = annotationsProvider,
|
annotationsProvider = annotationsProvider,
|
||||||
index = index,
|
annotationOverview = annotationOverview,
|
||||||
specialAnnotationApplication = null,
|
specialAnnotationApplication = null,
|
||||||
owner = owner,
|
owner = owner,
|
||||||
)
|
)
|
||||||
@@ -52,7 +54,7 @@ internal class SymbolLightLazyAnnotation private constructor(
|
|||||||
) : this(
|
) : this(
|
||||||
classId = classId,
|
classId = classId,
|
||||||
annotationsProvider = annotationsProvider,
|
annotationsProvider = annotationsProvider,
|
||||||
index = null,
|
annotationOverview = null,
|
||||||
specialAnnotationApplication = annotationApplication,
|
specialAnnotationApplication = annotationApplication,
|
||||||
owner = owner,
|
owner = owner,
|
||||||
)
|
)
|
||||||
@@ -70,7 +72,8 @@ 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.index == index &&
|
other.annotationOverview == annotationOverview &&
|
||||||
|
other.specialAnnotationApplication == specialAnnotationApplication &&
|
||||||
annotationsProvider.isTheSameAs(other.annotationsProvider) &&
|
annotationsProvider.isTheSameAs(other.annotationsProvider) &&
|
||||||
other.parent == parent
|
other.parent == parent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user