[SLC] add use site filter to SymbolAnnotationsProvider
^KT-56046
This commit is contained in:
committed by
Space Team
parent
31701ba673
commit
26b17a850d
+13
-4
@@ -11,31 +11,40 @@ 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
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
internal class SymbolAnnotationsProvider<T : KtAnnotatedSymbol>(
|
||||
private val ktModule: KtModule,
|
||||
private val annotatedSymbolPointer: KtSymbolPointer<T>
|
||||
private val annotatedSymbolPointer: KtSymbolPointer<T>,
|
||||
private val annotationUseSiteTarget: AnnotationUseSiteTarget? = null,
|
||||
private val acceptAnnotationsWithoutSite: Boolean = false,
|
||||
) : AnnotationsProvider {
|
||||
private inline fun <T> withAnnotatedSymbol(crossinline action: context(KtAnalysisSession) (KtAnnotatedSymbol) -> T): T =
|
||||
annotatedSymbolPointer.withSymbol(ktModule, action)
|
||||
|
||||
override fun annotationOverviews(): List<KtAnnotationOverview> = withAnnotatedSymbol { annotatedSymbol ->
|
||||
annotatedSymbol.annotationOverviews
|
||||
annotatedSymbol.annotationOverviews.filter {
|
||||
it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(classId: ClassId): Collection<KtAnnotationApplication> = withAnnotatedSymbol { annotatedSymbol ->
|
||||
annotatedSymbol.annotationsByClassId(classId)
|
||||
annotatedSymbol.annotationsByClassId(classId).filter {
|
||||
it.useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutSite && it.useSiteTarget == null
|
||||
}
|
||||
}
|
||||
|
||||
override fun contains(classId: ClassId): Boolean = withAnnotatedSymbol { annotatedSymbol ->
|
||||
annotatedSymbol.hasAnnotation(classId)
|
||||
annotatedSymbol.hasAnnotation(classId, annotationUseSiteTarget, acceptAnnotationsWithoutSite)
|
||||
}
|
||||
|
||||
override fun isTheSameAs(other: Any?): Boolean = other === this ||
|
||||
other is SymbolAnnotationsProvider<*> &&
|
||||
other.ktModule == ktModule &&
|
||||
other.annotationUseSiteTarget == annotationUseSiteTarget &&
|
||||
other.acceptAnnotationsWithoutSite == acceptAnnotationsWithoutSite &&
|
||||
annotatedSymbolPointer.pointsToTheSameSymbolAs(other.annotatedSymbolPointer)
|
||||
|
||||
override fun ownerClassId(): ClassId? = withAnnotatedSymbol { annotatedSymbol ->
|
||||
|
||||
+15
-9
@@ -15,8 +15,11 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.LazyAnnotationsBox
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.NullabilityAnnotationsProvider
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.SymbolAnnotationsProvider
|
||||
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
@@ -69,14 +72,17 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
annotationsBox = LazyAnnotationsBox(
|
||||
annotationsProvider = SymbolAnnotationsProvider(ktModule, receiverPointer),
|
||||
additionalAnnotationsProvider = CompositeAdditionalAnnotationsProvider(
|
||||
NullabilityAnnotationsProvider {
|
||||
withReceiverSymbol { receiver ->
|
||||
receiver.type.nullabilityType
|
||||
}
|
||||
},
|
||||
)
|
||||
annotationsProvider = SymbolAnnotationsProvider(
|
||||
ktModule = ktModule,
|
||||
annotatedSymbolPointer = receiverPointer,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.RECEIVER,
|
||||
acceptAnnotationsWithoutSite = true,
|
||||
),
|
||||
additionalAnnotationsProvider = NullabilityAnnotationsProvider {
|
||||
withReceiverSymbol { receiver ->
|
||||
receiver.type.nullabilityType
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user