[SLC] drop hack with setParent for annotations

^KTIJ-23783
This commit is contained in:
Dmitrii Gridin
2022-11-29 16:18:33 +01:00
committed by Space Team
parent c682d4f4cc
commit cba70d70a7
23 changed files with 135 additions and 168 deletions
@@ -18,6 +18,7 @@ abstract class KtLightElementBase(private var parent: PsiElement) : LightElement
abstract val kotlinOrigin: KtElement?
@Deprecated("Hack for ULC", level = DeprecationLevel.ERROR)
fun setParent(newParent: PsiElement) {
parent = newParent
}
@@ -5,10 +5,7 @@
package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiAnnotationMemberValue
import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiElement
import com.intellij.psi.*
import com.intellij.psi.impl.PsiImplUtil
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.asJava.classes.lazyPub
@@ -17,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtCallElement
internal class SymbolLightAnnotationForAnnotationCall(
private val annotationCall: KtAnnotationApplication,
parent: PsiElement,
parent: PsiModifierList,
) : SymbolLightAbstractAnnotation(parent) {
override fun findAttributeValue(attributeName: String?): PsiAnnotationMemberValue? =
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.light.classes.symbol.annotations
import com.intellij.psi.CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiModifierList
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
@@ -91,7 +91,7 @@ internal fun KtAnnotatedSymbol.hasAnnotation(fqName: FqName, annotationUseSiteTa
it.useSiteTarget == annotationUseSiteTarget && it.classId?.asSingleFqName() == fqName
}
internal fun NullabilityType.computeNullabilityAnnotation(parent: PsiElement): SymbolLightSimpleAnnotation? {
internal fun NullabilityType.computeNullabilityAnnotation(parent: PsiModifierList): SymbolLightSimpleAnnotation? {
return when (this) {
NullabilityType.NotNull -> NotNull::class.java
NullabilityType.Nullable -> Nullable::class.java
@@ -102,27 +102,26 @@ internal fun NullabilityType.computeNullabilityAnnotation(parent: PsiElement): S
}
internal fun KtAnnotatedSymbol.computeAnnotations(
parent: PsiElement,
modifierList: PsiModifierList,
nullability: NullabilityType,
annotationUseSiteTarget: AnnotationUseSiteTarget?,
includeAnnotationsWithoutSite: Boolean = true
): List<PsiAnnotation> {
val nullabilityAnnotation = nullability.computeNullabilityAnnotation(parent)
val parent = modifierList.parent
val nullabilityAnnotation = nullability.computeNullabilityAnnotation(modifierList)
val parentIsAnnotation = (parent as? PsiClass)?.isAnnotationType == true
val result = mutableListOf<PsiAnnotation>()
if (parent is SymbolLightMethod<*>) {
if (parent.isDelegated || parent.isOverride()) {
result.add(SymbolLightSimpleAnnotation(java.lang.Override::class.java.name, parent))
result.add(SymbolLightSimpleAnnotation(java.lang.Override::class.java.name, modifierList))
}
}
if (annotations.isEmpty()) {
if (parentIsAnnotation) {
result.add(createRetentionRuntimeAnnotation(parent))
result.add(createRetentionRuntimeAnnotation(modifierList))
}
if (nullabilityAnnotation != null) {
@@ -139,7 +138,7 @@ internal fun KtAnnotatedSymbol.computeAnnotations(
if ((includeAnnotationsWithoutSite && siteTarget == null) ||
siteTarget == annotationUseSiteTarget
) {
result.add(SymbolLightAnnotationForAnnotationCall(annotation, parent))
result.add(SymbolLightAnnotationForAnnotationCall(annotation, modifierList))
}
}
@@ -151,7 +150,7 @@ internal fun KtAnnotatedSymbol.computeAnnotations(
?.firstOrNull { it.name.asString() == "value" }
?.expression
val kotlinRetentionName = (argumentWithKotlinRetention as? KtEnumEntryAnnotationValue)?.callableId?.callableName?.asString()
result.add(createRetentionRuntimeAnnotation(parent, kotlinRetentionName))
result.add(createRetentionRuntimeAnnotation(modifierList, kotlinRetentionName))
}
if (nullabilityAnnotation != null) {
@@ -161,19 +160,19 @@ internal fun KtAnnotatedSymbol.computeAnnotations(
return result
}
private fun createRetentionRuntimeAnnotation(parent: PsiElement, retentionName: String? = null): PsiAnnotation =
private fun createRetentionRuntimeAnnotation(modifierList: PsiModifierList, retentionName: String? = null): PsiAnnotation =
SymbolLightSimpleAnnotation(
JAVA_LANG_ANNOTATION_RETENTION,
parent,
modifierList,
listOf(
KtNamedAnnotationValue(
name = DEFAULT_VALUE_PARAMETER,
expression = KtEnumEntryAnnotationValue(
callableId = CallableId(
ClassId.fromString(RETENTION_POLICY_ENUM.asString()),
Name.identifier(retentionName ?: AnnotationRetention.RUNTIME.name)
Name.identifier(retentionName ?: AnnotationRetention.RUNTIME.name),
),
sourcePsi = null
sourcePsi = null,
)
)
)
@@ -98,17 +98,18 @@ internal open class SymbolLightClassForClassOrObject : SymbolLightClassForNamedC
}
}
val lazyAnnotations = lazyPub {
SymbolLightClassModifierList(
containingDeclaration = this,
lazyModifiers = lazyModifiers,
) { modifierList ->
withClassOrObjectSymbol { classOrObjectSymbol ->
classOrObjectSymbol.computeAnnotations(
parent = this@SymbolLightClassForClassOrObject,
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = null,
)
}
}
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
}
override fun getModifierList(): PsiModifierList? = _modifierList
@@ -48,8 +48,7 @@ internal class SymbolLightClassForEnumEntry(
SymbolLightClassModifierList(
containingDeclaration = this,
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL)),
lazyAnnotations = lazyOf(emptyList()),
)
) { emptyList() }
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -70,20 +70,18 @@ class SymbolLightClassForFacade(
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.FINAL))
val lazyAnnotations = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
withFileSymbols { fileSymbols ->
fileSymbols.flatMap {
it.computeAnnotations(
this@SymbolLightClassForFacade,
NullabilityType.Unknown,
AnnotationUseSiteTarget.FILE,
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = AnnotationUseSiteTarget.FILE,
includeAnnotationsWithoutSite = false,
)
}
}
}
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -35,8 +35,7 @@ internal class SymbolLightClassForInterfaceDefaultImpls(private val containingCl
private val _modifierList: PsiModifierList? by lazyPub {
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL))
val lazyAnnotations = lazyOf(emptyList<PsiAnnotation>())
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { emptyList() }
}
override fun getModifierList(): PsiModifierList? = _modifierList
@@ -77,17 +77,15 @@ internal abstract class SymbolLightClassForInterfaceOrAnnotationClass : SymbolLi
}
}
val lazyAnnotations = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
withClassOrObjectSymbol { classOrObjectSymbol ->
classOrObjectSymbol.computeAnnotations(
parent = this@SymbolLightClassForInterfaceOrAnnotationClass,
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = null,
)
}
}
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
}
override fun isInterface(): Boolean = true
@@ -33,18 +33,17 @@ internal class SymbolLightFieldForEnumEntry(
private val _modifierList by lazyPub {
SymbolLightMemberModifierList(
containingDeclaration = this@SymbolLightFieldForEnumEntry,
containingDeclaration = this,
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC)),
lazyAnnotations = lazyPub {
withEnumEntrySymbol { enumEntrySymbol ->
enumEntrySymbol.computeAnnotations(
this@SymbolLightFieldForEnumEntry,
nullability = NullabilityType.Unknown, // there is no need to add nullability annotations on enum entries
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD,
)
}
) { modifierList ->
withEnumEntrySymbol { enumEntrySymbol ->
enumEntrySymbol.computeAnnotations(
modifierList,
nullability = NullabilityType.Unknown, // there is no need to add nullability annotations on enum entries
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD,
)
}
)
}
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -56,12 +56,12 @@ internal class SymbolLightFieldForObject private constructor(
}
}
val lazyAnnotations = lazyPub {
val notNullAnnotation = SymbolLightSimpleAnnotation(NotNull::class.java.name, this)
listOf(notNullAnnotation)
SymbolLightMemberModifierList(
containingDeclaration = this,
lazyModifiers = lazyModifiers,
) { modifierList ->
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, modifierList))
}
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
}
private val _isDeprecated: Boolean by lazyPub {
@@ -5,7 +5,10 @@
package org.jetbrains.kotlin.light.classes.symbol.fields
import com.intellij.psi.*
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiModifierList
import com.intellij.psi.PsiType
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
@@ -119,22 +122,25 @@ internal class SymbolLightFieldForProperty private constructor(
}
}
private fun computeAnnotations(): List<PsiAnnotation> = withPropertySymbol { propertySymbol ->
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit)) {
getTypeNullability(propertySymbol.returnType)
} else NullabilityType.Unknown
propertySymbol.computeAnnotations(
parent = this@SymbolLightFieldForProperty,
nullability = nullability,
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD,
)
}
private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazyPub { computeModifiers() }
val lazyAnnotations = lazyPub { computeAnnotations() }
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
SymbolLightMemberModifierList(
containingDeclaration = this,
lazyModifiers = lazyPub { computeModifiers() },
) { modifierList ->
withPropertySymbol { propertySymbol ->
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit)) {
getTypeNullability(propertySymbol.returnType)
} else {
NullabilityType.Unknown
}
propertySymbol.computeAnnotations(
modifierList = modifierList,
nullability = nullability,
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD,
)
}
}
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -129,13 +129,15 @@ internal class SymbolLightAccessorMethod private constructor(
//TODO Fix it when SymbolConstructorValueParameter be ready
private val isParameter: Boolean get() = containingPropertyDeclaration == null || containingPropertyDeclaration is KtParameter
private fun computeAnnotations(isPrivate: Boolean): List<PsiAnnotation> = analyzeForLightClasses(ktModule) {
val nullabilityApplicable = isGetter && !isPrivate && !(isParameter && containingClass.isAnnotationType)
private fun computeAnnotations(modifierList: PsiModifierList): List<PsiAnnotation> = analyzeForLightClasses(ktModule) {
val nullabilityApplicable = isGetter &&
!modifierList.hasModifierProperty(PsiModifier.PRIVATE) &&
!(isParameter && containingClass.isAnnotationType)
val propertySymbol = propertySymbol()
val nullabilityType = if (nullabilityApplicable) getTypeNullability(propertySymbol.returnType) else NullabilityType.Unknown
val annotationsFromProperty = propertySymbol.computeAnnotations(
parent = this@SymbolLightAccessorMethod,
modifierList = modifierList,
nullability = nullabilityType,
annotationUseSiteTarget = accessorSite,
includeAnnotationsWithoutSite = false,
@@ -143,7 +145,7 @@ internal class SymbolLightAccessorMethod private constructor(
val propertyAccessorSymbol = propertyAccessorSymbol()
val annotationsFromAccessor = propertyAccessorSymbol.computeAnnotations(
parent = this@SymbolLightAccessorMethod,
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = accessorSite,
)
@@ -184,9 +186,11 @@ internal class SymbolLightAccessorMethod private constructor(
}
private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazyPub { computeModifiers() }
val lazyAnnotations = lazyPub { computeAnnotations(PsiModifier.PRIVATE in lazyModifiers.value) }
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
SymbolLightMemberModifierList(
containingDeclaration = this,
lazyModifiers = lazyPub { computeModifiers() },
annotationsComputer = ::computeAnnotations,
)
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -42,16 +42,6 @@ internal class SymbolLightConstructor(
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
withFunctionSymbol { constructorSymbol ->
constructorSymbol.computeAnnotations(
parent = this@SymbolLightConstructor,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = null,
)
}
}
val lazyModifiers: Lazy<Set<String>> = lazyPub {
// FIR treats an enum entry as an anonymous object w/ its own ctor (not default one).
// On the other hand, FE 1.0 doesn't add anything; then ULC adds default ctor w/ package local visibility.
@@ -65,7 +55,15 @@ internal class SymbolLightConstructor(
}
}
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
SymbolLightMemberModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
withFunctionSymbol { constructorSymbol ->
constructorSymbol.computeAnnotations(
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = null,
)
}
}
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -36,7 +36,7 @@ internal class SymbolLightNoArgConstructor(
override fun isDeprecated(): Boolean = false
private val _modifierList: PsiModifierList by lazyPub {
SymbolLightMemberModifierList(this, lazyOf(setOf(visibility)), lazyOf(emptyList()))
SymbolLightMemberModifierList(containingDeclaration = this, lazyModifiers = lazyOf(setOf(visibility))) { emptyList() }
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -67,10 +67,11 @@ internal class SymbolLightSimpleMethod(
override fun getTypeParameterList(): PsiTypeParameterList? = _typeParameterList
override fun getTypeParameters(): Array<PsiTypeParameter> = _typeParameterList?.typeParameters ?: PsiTypeParameter.EMPTY_ARRAY
context(KtAnalysisSession)
private fun computeAnnotations(functionSymbol: KtFunctionSymbol, isPrivate: Boolean): List<PsiAnnotation> {
private fun computeAnnotations(
modifierList: PsiModifierList,
): List<PsiAnnotation> = withFunctionSymbol { functionSymbol ->
val nullability = when {
isPrivate -> NullabilityType.Unknown
modifierList.hasModifierProperty(PsiModifier.PRIVATE) -> NullabilityType.Unknown
functionSymbol.isSuspend -> /* Any? */ NullabilityType.Nullable
else -> {
val returnType = functionSymbol.returnType
@@ -78,8 +79,8 @@ internal class SymbolLightSimpleMethod(
}
}
return functionSymbol.computeAnnotations(
parent = this@SymbolLightSimpleMethod,
functionSymbol.computeAnnotations(
modifierList = modifierList,
nullability = nullability,
annotationUseSiteTarget = null,
)
@@ -126,13 +127,11 @@ internal class SymbolLightSimpleMethod(
}
}
val lazyAnnotations = lazyPub {
withFunctionSymbol { functionSymbol ->
computeAnnotations(functionSymbol, PsiModifier.PRIVATE in lazyModifiers.value)
}
}
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
SymbolLightMemberModifierList(
containingDeclaration = this,
lazyModifiers = lazyModifiers,
annotationsComputer = ::computeAnnotations,
)
}
override fun getModifierList(): PsiModifierList = _modifierList
@@ -6,32 +6,15 @@
package org.jetbrains.kotlin.light.classes.symbol.modifierLists
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList
import com.intellij.psi.PsiModifierListOwner
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.light.classes.symbol.invalidAccess
import org.jetbrains.kotlin.psi.KtModifierListOwner
internal class SymbolLightClassModifierList<T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
containingDeclaration: T,
private val lazyModifiers: Lazy<Set<String>>,
lazyAnnotations: Lazy<List<PsiAnnotation>>,
) : SymbolLightModifierList<T>(containingDeclaration) {
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
}
lazyModifiers: Lazy<Set<String>>,
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
) : SymbolLightModifierList<T>(containingDeclaration, lazyModifiers, annotationsComputer) {
override fun hasModifierProperty(name: String): Boolean = name in lazyModifiers.value
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
override fun getAnnotations(): Array<out PsiAnnotation> = lazyAnnotations.value.toTypedArray()
override fun findAnnotation(qualifiedName: String): PsiAnnotation? =
lazyAnnotations.value.firstOrNull { it.qualifiedName == qualifiedName }
override fun equals(other: Any?): Boolean = this === other
override fun hashCode(): Int = kotlinOrigin.hashCode()
}
}
@@ -8,11 +8,8 @@ package org.jetbrains.kotlin.light.classes.symbol.modifierLists
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifier
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.asJava.elements.KtLightMember
import org.jetbrains.kotlin.light.classes.symbol.invalidAccess
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
import org.jetbrains.kotlin.psi.KtModifierList
import org.jetbrains.kotlin.psi.KtPropertyAccessor
@@ -20,13 +17,9 @@ import org.jetbrains.kotlin.psi.psiUtil.hasBody
internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
containingDeclaration: T,
private val lazyModifiers: Lazy<Set<String>>,
lazyAnnotations: Lazy<List<PsiAnnotation>>
) : SymbolLightModifierList<T>(containingDeclaration) {
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
}
lazyModifiers: Lazy<Set<String>>,
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
) : SymbolLightModifierList<T>(containingDeclaration, lazyModifiers, annotationsComputer) {
override fun hasModifierProperty(name: String): Boolean = when {
name == PsiModifier.ABSTRACT && isImplementationInInterface() -> false
// Pretend this method behaves like a `default` method
@@ -44,13 +37,6 @@ internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
return if (name == PsiModifier.DEFAULT) false else super.hasExplicitModifier(name)
}
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
override fun getAnnotations(): Array<out PsiAnnotation> = lazyAnnotations.value.toTypedArray()
override fun findAnnotation(qualifiedName: String): PsiAnnotation? =
lazyAnnotations.value.firstOrNull { it.qualifiedName == qualifiedName }
private inline fun <R> getTextVariantFromModifierListOfPropertyAccessorIfNeeded(
retriever: (KtModifierList) -> R
): R? {
@@ -72,8 +58,4 @@ internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
return getTextVariantFromModifierListOfPropertyAccessorIfNeeded(KtModifierList::getTextRange)
?: super.getTextRange()
}
override fun equals(other: Any?): Boolean = this === other
override fun hashCode(): Int = kotlinOrigin.hashCode()
}
@@ -11,13 +11,18 @@ import com.intellij.psi.PsiModifierList
import com.intellij.psi.PsiModifierListOwner
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.asJava.classes.cannotModify
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.light.classes.symbol.invalidAccess
import org.jetbrains.kotlin.psi.KtModifierList
import org.jetbrains.kotlin.psi.KtModifierListOwner
internal abstract class SymbolLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
protected val owner: T
protected val owner: T,
protected val lazyModifiers: Lazy<Set<String>>,
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierListOwner> {
override val kotlinOrigin: KtModifierList? get() = owner.kotlinOrigin?.modifierList
override fun getParent() = owner
@@ -29,6 +34,16 @@ internal abstract class SymbolLightModifierList<out T : KtLightElement<KtModifie
override fun isEquivalentTo(another: PsiElement?) = another is SymbolLightModifierList<*> && owner == another.owner
override fun isWritable() = false
override fun toString() = "Light modifier list of $owner"
abstract override fun equals(other: Any?): Boolean
abstract override fun hashCode(): Int
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
annotationsComputer(this)
}
override fun getAnnotations(): Array<out PsiAnnotation> = lazyAnnotations.value.toTypedArray()
override fun findAnnotation(qualifiedName: String): PsiAnnotation? =
lazyAnnotations.value.firstOrNull { it.qualifiedName == qualifiedName }
override fun equals(other: Any?): Boolean = this === other
override fun hashCode(): Int = kotlinOrigin.hashCode()
}
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.light.classes.symbol.parameters
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
@@ -28,24 +27,21 @@ internal class SymbolLightParameter(
override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
val annotationSite = isConstructorParameterSymbol.ifTrue {
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER
}
parameterSymbolPointer.withSymbol(ktModule) { parameterSymbol ->
val nullability = if (parameterSymbol.isVararg) NullabilityType.NotNull else super.nullabilityType
parameterSymbol.computeAnnotations(
parent = this@SymbolLightParameter,
modifierList = modifierList,
nullability = nullability,
annotationUseSiteTarget = annotationSite,
includeAnnotationsWithoutSite = true,
)
}
}
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
}
private val isVararg: Boolean by lazyPub {
@@ -17,7 +17,6 @@ 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.light.classes.symbol.*
import org.jetbrains.kotlin.light.classes.symbol.annotations.SymbolLightAbstractAnnotation
import org.jetbrains.kotlin.light.classes.symbol.annotations.SymbolLightAnnotationForAnnotationCall
import org.jetbrains.kotlin.light.classes.symbol.annotations.computeNullabilityAnnotation
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
@@ -69,18 +68,16 @@ internal class SymbolLightParameterForReceiver private constructor(
override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<SymbolLightAbstractAnnotation>> = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
withReceiverSymbol { receiver ->
buildList {
receiver.type.nullabilityType.computeNullabilityAnnotation(this@SymbolLightParameterForReceiver)?.let(::add)
receiver.type.nullabilityType.computeNullabilityAnnotation(modifierList)?.let(::add)
receiver.annotations.mapTo(this) {
SymbolLightAnnotationForAnnotationCall(it, this@SymbolLightParameterForReceiver)
SymbolLightAnnotationForAnnotationCall(it, modifierList)
}
}
}
}
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
}
private val _type: PsiType by lazyPub {
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.light.classes.symbol.parameters
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierList
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
@@ -42,16 +41,16 @@ internal class SymbolLightSetterParameter(
override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
analyzeForLightClasses(ktModule) {
val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
parent = this@SymbolLightSetterParameter,
modifierList = modifierList,
nullability = NullabilityType.Unknown,
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
)
val annotationsFromProperty = containingPropertySymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
parent = this@SymbolLightSetterParameter,
modifierList = modifierList,
nullability = nullabilityType,
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
includeAnnotationsWithoutSite = false,
@@ -60,8 +59,6 @@ internal class SymbolLightSetterParameter(
annotationsFromSetter + annotationsFromProperty
}
}
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
}
override fun isVarArgs() = false
@@ -50,14 +50,12 @@ internal class SymbolLightSuspendContinuationParameter(
override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations = lazyPub {
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
if (withFunctionSymbol { it.visibility.isPrivateOrPrivateToThis() })
emptyList()
else
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, this))
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, modifierList))
}
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
}
override fun hasModifierProperty(p0: String): Boolean = false
@@ -33,6 +33,7 @@ abstract class KtLightModifierListDescriptorBased<out T : KtLightElement<KtModif
val annotationsForEntries = owner.givenAnnotations ?: lightAnnotationsForEntries(this)
//TODO: Hacky way to update wrong parents for annotations
annotationsForEntries.forEach {
@Suppress("DEPRECATION_ERROR")
it.parent = this
}
val modifierListOwner = parent