[SLC] modifiers should be calculated lazily
^KTIJ-23280 Fixed
This commit is contained in:
committed by
Space Team
parent
90bf4a3a24
commit
608d1e3431
+2
-2
@@ -50,7 +50,7 @@ internal open class SymbolLightClass(classOrObject: KtClassOrObject, ktModule: K
|
||||
require(classOrObject !is KtClass || !classOrObject.isInterface() && !classOrObject.isAnnotation())
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList? by lazyPub {
|
||||
private val _modifierList: PsiModifierList? by lazy {
|
||||
val lazyModifiers = lazy {
|
||||
withNamedClassOrObjectSymbol { classOrObjectSymbol ->
|
||||
buildSet {
|
||||
@@ -73,7 +73,7 @@ internal open class SymbolLightClass(classOrObject: KtClassOrObject, ktModule: K
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this@SymbolLightClass, lazyModifiers, lazyAnnotations)
|
||||
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList? = _modifierList
|
||||
|
||||
+2
-2
@@ -36,11 +36,11 @@ internal class SymbolLightClassForEnumEntry(
|
||||
|
||||
override fun toString(): String = "SymbolLightClassForEnumEntry:$name"
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL)),
|
||||
lazyAnnotations = lazyOf(emptyList())
|
||||
lazyAnnotations = lazyOf(emptyList()),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -62,11 +62,11 @@ class SymbolLightClassForFacade(
|
||||
action(files.map { it.getFileSymbol() })
|
||||
}
|
||||
|
||||
private val firstFileInFacade by lazyPub { files.first() }
|
||||
private val firstFileInFacade by lazy { files.first() }
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
if (multiFileClass)
|
||||
return@lazyPub LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL)
|
||||
return@lazy LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL)
|
||||
|
||||
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.FINAL))
|
||||
|
||||
@@ -83,7 +83,7 @@ class SymbolLightClassForFacade(
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this@SymbolLightClassForFacade, lazyModifiers, lazyAnnotations)
|
||||
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+2
-3
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.light.classes.symbol.classes
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
|
||||
@@ -23,10 +22,10 @@ internal class SymbolLightClassForInterfaceDefaultImpls(private val containingCl
|
||||
override fun getTypeParameterList(): PsiTypeParameterList? = null
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = emptyArray()
|
||||
|
||||
private val _modifierList: PsiModifierList? by lazyPub {
|
||||
private val _modifierList: PsiModifierList? by lazy {
|
||||
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL))
|
||||
val lazyAnnotations = lazyOf(emptyList<PsiAnnotation>())
|
||||
SymbolLightClassModifierList(this@SymbolLightClassForInterfaceDefaultImpls, lazyModifiers, lazyAnnotations)
|
||||
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList? = _modifierList
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ internal abstract class SymbolLightInterfaceOrAnnotationClass(classOrObject: KtC
|
||||
require(isInterface || isAnnotation)
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList? by lazyPub {
|
||||
private val _modifierList: PsiModifierList? by lazy {
|
||||
val lazyModifiers = lazy {
|
||||
withNamedClassOrObjectSymbol { classOrObjectSymbol ->
|
||||
buildSet {
|
||||
@@ -47,7 +47,7 @@ internal abstract class SymbolLightInterfaceOrAnnotationClass(classOrObject: KtC
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this@SymbolLightInterfaceOrAnnotationClass, lazyModifiers, lazyAnnotations)
|
||||
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun isInterface(): Boolean = true
|
||||
|
||||
+10
-8
@@ -32,16 +32,18 @@ internal class SymbolLightFieldForEnumEntry(
|
||||
action(enumEntry.getEnumEntrySymbol())
|
||||
}
|
||||
|
||||
private val _modifierList by lazyPub {
|
||||
private val _modifierList by lazy {
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this@SymbolLightFieldForEnumEntry,
|
||||
modifiers = setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC),
|
||||
annotations = withEnumEntrySymbol { enumEntrySymbol ->
|
||||
enumEntrySymbol.computeAnnotations(
|
||||
this@SymbolLightFieldForEnumEntry,
|
||||
nullability = NullabilityType.Unknown, // there is no need to add nullability annotations on enum entries
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD
|
||||
)
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+11
-5
@@ -38,13 +38,19 @@ internal class SymbolLightFieldForObject(
|
||||
|
||||
override fun getName(): String = name
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val modifiers = withObjectDeclarationSymbol { objectSymbol ->
|
||||
setOf(objectSymbol.toPsiVisibilityForMember(), PsiModifier.STATIC, PsiModifier.FINAL)
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyModifiers = lazy {
|
||||
withObjectDeclarationSymbol { objectSymbol ->
|
||||
setOf(objectSymbol.toPsiVisibilityForMember(), PsiModifier.STATIC, PsiModifier.FINAL)
|
||||
}
|
||||
}
|
||||
|
||||
val notNullAnnotation = SymbolLightSimpleAnnotation(NotNull::class.java.name, this)
|
||||
SymbolLightMemberModifierList(this, modifiers, listOf(notNullAnnotation))
|
||||
val lazyAnnotations = lazyPub {
|
||||
val notNullAnnotation = SymbolLightSimpleAnnotation(NotNull::class.java.name, this)
|
||||
listOf(notNullAnnotation)
|
||||
}
|
||||
|
||||
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
|
||||
+30
-29
@@ -5,10 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.light.classes.symbol.fields
|
||||
|
||||
import com.intellij.psi.PsiExpression
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
|
||||
@@ -36,9 +33,9 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
private val fieldName: String,
|
||||
containingClass: SymbolLightClassBase,
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
isTopLevel: Boolean,
|
||||
forceStatic: Boolean,
|
||||
takePropertyVisibility: Boolean,
|
||||
private val isTopLevel: Boolean,
|
||||
private val forceStatic: Boolean,
|
||||
private val takePropertyVisibility: Boolean,
|
||||
override val kotlinOrigin: KtCallableDeclaration?,
|
||||
) : SymbolLightField(containingClass, lightMemberOrigin) {
|
||||
internal constructor(
|
||||
@@ -91,51 +88,55 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
|
||||
override fun getName(): String = fieldName
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
withPropertySymbol { propertySymbol ->
|
||||
val modifiers = mutableSetOf<String>()
|
||||
|
||||
private fun computeModifiers(): Set<String> = withPropertySymbol { propertySymbol ->
|
||||
buildSet {
|
||||
val suppressFinal = !propertySymbol.isVal
|
||||
|
||||
propertySymbol.computeModalityForMethod(
|
||||
isTopLevel = isTopLevel,
|
||||
suppressFinal = suppressFinal,
|
||||
result = modifiers
|
||||
result = this
|
||||
)
|
||||
|
||||
if (forceStatic) {
|
||||
modifiers.add(PsiModifier.STATIC)
|
||||
add(PsiModifier.STATIC)
|
||||
}
|
||||
|
||||
val visibility = if (takePropertyVisibility) propertySymbol.toPsiVisibilityForMember() else PsiModifier.PRIVATE
|
||||
modifiers.add(visibility)
|
||||
add(visibility)
|
||||
|
||||
if (!suppressFinal) {
|
||||
modifiers.add(PsiModifier.FINAL)
|
||||
add(PsiModifier.FINAL)
|
||||
}
|
||||
|
||||
if (propertySymbol.hasAnnotation(TRANSIENT_ANNOTATION_CLASS_ID, null)) {
|
||||
modifiers.add(PsiModifier.TRANSIENT)
|
||||
add(PsiModifier.TRANSIENT)
|
||||
}
|
||||
|
||||
if (propertySymbol.hasAnnotation(VOLATILE_ANNOTATION_CLASS_ID, null)) {
|
||||
modifiers.add(PsiModifier.VOLATILE)
|
||||
add(PsiModifier.VOLATILE)
|
||||
}
|
||||
|
||||
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit)) {
|
||||
getTypeNullability(propertySymbol.returnType)
|
||||
} else NullabilityType.Unknown
|
||||
|
||||
val annotations = propertySymbol.computeAnnotations(
|
||||
parent = this@SymbolLightFieldForProperty,
|
||||
nullability = nullability,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.FIELD,
|
||||
)
|
||||
|
||||
SymbolLightMemberModifierList(this@SymbolLightFieldForProperty, modifiers, annotations)
|
||||
}
|
||||
}
|
||||
|
||||
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 lazy {
|
||||
val lazyModifiers = lazyPub { computeModifiers() }
|
||||
val lazyAnnotations = lazyPub { computeAnnotations() }
|
||||
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _initializerValue: KtConstantValue? by lazyPub {
|
||||
|
||||
+4
-4
@@ -183,10 +183,10 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
modifiers
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val modifiers = computeModifiers()
|
||||
val annotations = computeAnnotations(modifiers.contains(PsiModifier.PRIVATE))
|
||||
SymbolLightMemberModifierList(this, modifiers, annotations)
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyModifiers = lazyPub { computeModifiers() }
|
||||
val lazyAnnotations = lazyPub { computeAnnotations(PsiModifier.PRIVATE in lazyModifiers.value) }
|
||||
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+22
-22
@@ -43,31 +43,31 @@ internal class SymbolLightConstructor(
|
||||
override fun getTypeParameterList(): PsiTypeParameterList? = null
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
withFunctionSymbol { constructorSymbol ->
|
||||
constructorSymbol.computeAnnotations(
|
||||
parent = this@SymbolLightConstructor,
|
||||
nullability = NullabilityType.Unknown,
|
||||
annotationUseSiteTarget = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val _modifiers: Set<String> by 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.
|
||||
// Technically, an enum entry should not be instantiated anywhere else, and thus FIR's modeling makes sense.
|
||||
// But, to be backward compatible, we manually force the visibility of enum entry ctor to be package private.
|
||||
if (containingClass is SymbolLightClassForEnumEntry)
|
||||
setOf(PsiModifier.PACKAGE_LOCAL)
|
||||
else
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
|
||||
withFunctionSymbol { constructorSymbol ->
|
||||
setOf(constructorSymbol.toPsiVisibilityForMember())
|
||||
constructorSymbol.computeAnnotations(
|
||||
parent = this@SymbolLightConstructor,
|
||||
nullability = NullabilityType.Unknown,
|
||||
annotationUseSiteTarget = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightMemberModifierList(this, _modifiers, _annotations)
|
||||
val lazyModifiers: Lazy<Set<String>> = lazy {
|
||||
// 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.
|
||||
// Technically, an enum entry should not be instantiated anywhere else, and thus FIR's modeling makes sense.
|
||||
// But, to be backward compatible, we manually force the visibility of enum entry ctor to be package private.
|
||||
if (containingClass is SymbolLightClassForEnumEntry)
|
||||
setOf(PsiModifier.PACKAGE_LOCAL)
|
||||
else
|
||||
withFunctionSymbol { constructorSymbol ->
|
||||
setOf(constructorSymbol.toPsiVisibilityForMember())
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+3
-5
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameter
|
||||
internal class SymbolLightNoArgConstructor(
|
||||
lightMemberOrigin: LightMemberOrigin,
|
||||
containingClass: SymbolLightClassForClassOrObject,
|
||||
visibility: String,
|
||||
private val visibility: String,
|
||||
methodIndex: Int,
|
||||
) : SymbolLightMethodBase(lightMemberOrigin, containingClass, methodIndex) {
|
||||
override fun getName(): String = containingClass.name ?: ""
|
||||
@@ -35,10 +35,8 @@ internal class SymbolLightNoArgConstructor(
|
||||
|
||||
override fun isDeprecated(): Boolean = false
|
||||
|
||||
private val _modifiers: Set<String> = setOf(visibility)
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightMemberModifierList(this, _modifiers, emptyList())
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
SymbolLightMemberModifierList(this, lazyOf(setOf(visibility)), lazyOf(emptyList()))
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+13
-5
@@ -119,12 +119,20 @@ internal class SymbolLightSimpleMethod(
|
||||
return modifiers
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
val modifiers = computeModifiers(functionSymbol)
|
||||
val annotations = computeAnnotations(functionSymbol, modifiers.contains(PsiModifier.PRIVATE))
|
||||
SymbolLightMemberModifierList(this@SymbolLightSimpleMethod, modifiers, annotations)
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyModifiers = lazyPub {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
computeModifiers(functionSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
val lazyAnnotations = lazyPub {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
computeAnnotations(functionSymbol, PsiModifier.PRIVATE in lazyModifiers.value)
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+6
-8
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.light.classes.symbol.modifierLists
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
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
|
||||
@@ -17,20 +16,19 @@ 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>>
|
||||
lazyAnnotations: Lazy<List<PsiAnnotation>>,
|
||||
) : SymbolLightModifierList<T>(containingDeclaration) {
|
||||
private val lazyAnnotations = lazy {
|
||||
lazyAnnotations.value
|
||||
.onEach { (it as? KtLightElementBase)?.parent = this }
|
||||
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazy {
|
||||
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
|
||||
}
|
||||
|
||||
override fun hasModifierProperty(name: String): Boolean = name in lazyModifiers.value
|
||||
|
||||
override val givenAnnotations: List<KtLightAbstractAnnotation>?
|
||||
get() = invalidAccess()
|
||||
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
|
||||
|
||||
override fun getAnnotations(): Array<out PsiAnnotation> = lazyAnnotations.value.toTypedArray()
|
||||
override fun findAnnotation(qualifiedName: String) = annotations.firstOrNull { it.qualifiedName == qualifiedName }
|
||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? =
|
||||
lazyAnnotations.value.firstOrNull { it.qualifiedName == qualifiedName }
|
||||
|
||||
override fun equals(other: Any?): Boolean = this === other
|
||||
|
||||
|
||||
+14
-20
@@ -19,25 +19,19 @@ import org.jetbrains.kotlin.psi.psiUtil.hasBody
|
||||
|
||||
internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
|
||||
containingDeclaration: T,
|
||||
private val modifiers: Set<String>,
|
||||
private val annotations: List<PsiAnnotation>
|
||||
private val lazyModifiers: Lazy<Set<String>>,
|
||||
lazyAnnotations: Lazy<List<PsiAnnotation>>
|
||||
) : SymbolLightModifierList<T>(containingDeclaration) {
|
||||
init {
|
||||
annotations.forEach {
|
||||
(it as? KtLightElementBase)?.parent = this
|
||||
}
|
||||
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazy {
|
||||
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
|
||||
}
|
||||
|
||||
override fun hasModifierProperty(name: String): Boolean {
|
||||
return when {
|
||||
name == PsiModifier.ABSTRACT && isImplementationInInterface() -> false
|
||||
// Pretend this method behaves like a `default` method
|
||||
name == PsiModifier.DEFAULT && isImplementationInInterface() -> true
|
||||
// TODO: FINAL && isPossiblyAffectedByAllOpen
|
||||
else -> {
|
||||
name in modifiers
|
||||
}
|
||||
}
|
||||
override fun hasModifierProperty(name: String): Boolean = when {
|
||||
name == PsiModifier.ABSTRACT && isImplementationInInterface() -> false
|
||||
// Pretend this method behaves like a `default` method
|
||||
name == PsiModifier.DEFAULT && isImplementationInInterface() -> true
|
||||
// TODO: FINAL && isPossiblyAffectedByAllOpen
|
||||
else -> name in lazyModifiers.value
|
||||
}
|
||||
|
||||
private fun isImplementationInInterface(): Boolean {
|
||||
@@ -49,12 +43,12 @@ internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
|
||||
return if (name == PsiModifier.DEFAULT) false else super.hasExplicitModifier(name)
|
||||
}
|
||||
|
||||
override val givenAnnotations: List<KtLightAbstractAnnotation>?
|
||||
get() = invalidAccess()
|
||||
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
|
||||
|
||||
override fun getAnnotations(): Array<out PsiAnnotation> = annotations.toTypedArray()
|
||||
override fun getAnnotations(): Array<out PsiAnnotation> = lazyAnnotations.value.toTypedArray()
|
||||
|
||||
override fun findAnnotation(qualifiedName: String) = annotations.firstOrNull { it.qualifiedName == qualifiedName }
|
||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? =
|
||||
lazyAnnotations.value.firstOrNull { it.qualifiedName == qualifiedName }
|
||||
|
||||
private inline fun <R> getTextVariantFromModifierListOfPropertyAccessorIfNeeded(
|
||||
retriever: (KtModifierList) -> R
|
||||
|
||||
+2
-17
@@ -19,31 +19,16 @@ import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
internal abstract class SymbolLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
||||
protected val owner: T
|
||||
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierListOwner> {
|
||||
|
||||
override val kotlinOrigin: KtModifierList?
|
||||
get() = owner.kotlinOrigin?.modifierList
|
||||
|
||||
override val kotlinOrigin: KtModifierList? get() = owner.kotlinOrigin?.modifierList
|
||||
override fun getParent() = owner
|
||||
|
||||
override fun hasExplicitModifier(name: String) = hasModifierProperty(name)
|
||||
|
||||
override fun setModifierProperty(name: String, value: Boolean) = cannotModify()
|
||||
override fun checkSetModifierProperty(name: String, value: Boolean) = throw IncorrectOperationException()
|
||||
override fun addAnnotation(qualifiedName: String): PsiAnnotation = cannotModify()
|
||||
|
||||
override fun getApplicableAnnotations(): Array<out PsiAnnotation> = annotations
|
||||
|
||||
override fun getAnnotations(): Array<out PsiAnnotation> = emptyArray() //TODO()
|
||||
override fun findAnnotation(qualifiedName: String): PsiAnnotation? = null //TODO()
|
||||
|
||||
override fun isEquivalentTo(another: PsiElement?) =
|
||||
another is SymbolLightModifierList<*> && owner == another.owner
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
+19
-20
@@ -25,28 +25,27 @@ internal class SymbolLightParameter(
|
||||
) : SymbolLightParameterCommon(ktAnalysisSession, parameterSymbol, containingMethod) {
|
||||
private val isConstructorParameterSymbol = containingMethod.isConstructor
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
|
||||
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,
|
||||
nullability = nullability,
|
||||
annotationUseSiteTarget = annotationSite,
|
||||
includeAnnotationsWithoutSite = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyOf(_annotations))
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
|
||||
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,
|
||||
nullability = nullability,
|
||||
annotationUseSiteTarget = annotationSite,
|
||||
includeAnnotationsWithoutSite = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
|
||||
}
|
||||
|
||||
private val isVararg: Boolean by lazy {
|
||||
|
||||
+13
-13
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.light.classes.symbol.parameters
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiIdentifier
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import com.intellij.psi.PsiType
|
||||
@@ -18,6 +17,7 @@ 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
|
||||
@@ -66,21 +66,21 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
|
||||
override val kotlinOrigin: KtParameter? = null
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
withReceiverSymbol { receiver ->
|
||||
buildList {
|
||||
receiver.type.nullabilityType.computeNullabilityAnnotation(this@SymbolLightParameterForReceiver)?.let(::add)
|
||||
receiver.annotations.mapTo(this) {
|
||||
SymbolLightAnnotationForAnnotationCall(it, this@SymbolLightParameterForReceiver)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyOf(_annotations))
|
||||
val lazyAnnotations: Lazy<List<SymbolLightAbstractAnnotation>> = lazyPub {
|
||||
withReceiverSymbol { receiver ->
|
||||
buildList {
|
||||
receiver.type.nullabilityType.computeNullabilityAnnotation(this@SymbolLightParameterForReceiver)?.let(::add)
|
||||
receiver.annotations.mapTo(this) {
|
||||
SymbolLightAnnotationForAnnotationCall(it, this@SymbolLightParameterForReceiver)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
|
||||
}
|
||||
|
||||
private val _type: PsiType by lazy {
|
||||
|
||||
+21
-21
@@ -39,29 +39,29 @@ internal class SymbolLightSetterParameter(
|
||||
}
|
||||
}
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
analyzeForLightClasses(ktModule) {
|
||||
val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
|
||||
parent = this@SymbolLightSetterParameter,
|
||||
nullability = NullabilityType.Unknown,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
|
||||
)
|
||||
|
||||
val annotationsFromProperty = containingPropertySymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
|
||||
parent = this@SymbolLightSetterParameter,
|
||||
nullability = nullabilityType,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
|
||||
includeAnnotationsWithoutSite = false,
|
||||
)
|
||||
|
||||
annotationsFromSetter + annotationsFromProperty
|
||||
}
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyOf(_annotations))
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
|
||||
analyzeForLightClasses(ktModule) {
|
||||
val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
|
||||
parent = this@SymbolLightSetterParameter,
|
||||
nullability = NullabilityType.Unknown,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
|
||||
)
|
||||
|
||||
val annotationsFromProperty = containingPropertySymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
|
||||
parent = this@SymbolLightSetterParameter,
|
||||
nullability = nullabilityType,
|
||||
annotationUseSiteTarget = AnnotationUseSiteTarget.SETTER_PARAMETER,
|
||||
includeAnnotationsWithoutSite = false,
|
||||
)
|
||||
|
||||
annotationsFromSetter + annotationsFromProperty
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
|
||||
}
|
||||
|
||||
override fun isVarArgs() = false
|
||||
|
||||
+2
-2
@@ -50,11 +50,11 @@ internal class SymbolLightSuspendContinuationParameter(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazy {
|
||||
val lazyAnnotations = lazy {
|
||||
val lazyAnnotations = lazyPub {
|
||||
if (withFunctionSymbol { it.visibility.isPrivateOrPrivateToThis() })
|
||||
emptyList()
|
||||
else
|
||||
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, this@SymbolLightSuspendContinuationParameter))
|
||||
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, this))
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
|
||||
|
||||
Reference in New Issue
Block a user