[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.markers.KtAnnotatedSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
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.light.classes.symbol.withSymbol
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
internal class SymbolAnnotationsProvider<T : KtAnnotatedSymbol>(
|
internal class SymbolAnnotationsProvider<T : KtAnnotatedSymbol>(
|
||||||
private val ktModule: KtModule,
|
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 {
|
) : AnnotationsProvider {
|
||||||
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 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 ->
|
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 ->
|
override fun contains(classId: ClassId): Boolean = withAnnotatedSymbol { annotatedSymbol ->
|
||||||
annotatedSymbol.hasAnnotation(classId)
|
annotatedSymbol.hasAnnotation(classId, annotationUseSiteTarget, acceptAnnotationsWithoutSite)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isTheSameAs(other: Any?): Boolean = other === this ||
|
override fun isTheSameAs(other: Any?): Boolean = other === this ||
|
||||||
other is SymbolAnnotationsProvider<*> &&
|
other is SymbolAnnotationsProvider<*> &&
|
||||||
other.ktModule == ktModule &&
|
other.ktModule == ktModule &&
|
||||||
|
other.annotationUseSiteTarget == annotationUseSiteTarget &&
|
||||||
|
other.acceptAnnotationsWithoutSite == acceptAnnotationsWithoutSite &&
|
||||||
annotatedSymbolPointer.pointsToTheSameSymbolAs(other.annotatedSymbolPointer)
|
annotatedSymbolPointer.pointsToTheSameSymbolAs(other.annotatedSymbolPointer)
|
||||||
|
|
||||||
override fun ownerClassId(): ClassId? = withAnnotatedSymbol { annotatedSymbol ->
|
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.analysis.api.symbols.pointers.KtSymbolPointer
|
||||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
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.*
|
||||||
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.methods.SymbolLightMethodBase
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
||||||
import org.jetbrains.kotlin.psi.KtParameter
|
import org.jetbrains.kotlin.psi.KtParameter
|
||||||
@@ -69,14 +72,17 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
SymbolLightClassModifierList(
|
SymbolLightClassModifierList(
|
||||||
containingDeclaration = this,
|
containingDeclaration = this,
|
||||||
annotationsBox = LazyAnnotationsBox(
|
annotationsBox = LazyAnnotationsBox(
|
||||||
annotationsProvider = SymbolAnnotationsProvider(ktModule, receiverPointer),
|
annotationsProvider = SymbolAnnotationsProvider(
|
||||||
additionalAnnotationsProvider = CompositeAdditionalAnnotationsProvider(
|
ktModule = ktModule,
|
||||||
NullabilityAnnotationsProvider {
|
annotatedSymbolPointer = receiverPointer,
|
||||||
withReceiverSymbol { receiver ->
|
annotationUseSiteTarget = AnnotationUseSiteTarget.RECEIVER,
|
||||||
receiver.type.nullabilityType
|
acceptAnnotationsWithoutSite = true,
|
||||||
}
|
),
|
||||||
},
|
additionalAnnotationsProvider = NullabilityAnnotationsProvider {
|
||||||
)
|
withReceiverSymbol { receiver ->
|
||||||
|
receiver.type.nullabilityType
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user