[SLC] SymbolLightModifierList: separate static and lazy modifiers
^KTIJ-23783
This commit is contained in:
committed by
Space Team
parent
fc8ae0f2e5
commit
9970623e95
+1
-1
@@ -47,7 +47,7 @@ internal class SymbolLightClassForEnumEntry(
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL)),
|
||||
staticModifiers = setOf(PsiModifier.STATIC, PsiModifier.FINAL),
|
||||
) { emptyList() }
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -68,9 +68,10 @@ class SymbolLightClassForFacade(
|
||||
if (multiFileClass)
|
||||
return@lazyPub LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL)
|
||||
|
||||
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.FINAL))
|
||||
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = setOf(PsiModifier.PUBLIC, PsiModifier.FINAL),
|
||||
) { modifierList ->
|
||||
withFileSymbols { fileSymbols ->
|
||||
fileSymbols.flatMap {
|
||||
it.computeAnnotations(
|
||||
|
||||
+4
-2
@@ -34,8 +34,10 @@ internal class SymbolLightClassForInterfaceDefaultImpls(private val containingCl
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = emptyArray()
|
||||
|
||||
private val _modifierList: PsiModifierList? by lazyPub {
|
||||
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL))
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { emptyList() }
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL),
|
||||
) { emptyList() }
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList? = _modifierList
|
||||
|
||||
+6
-2
@@ -65,11 +65,11 @@ internal abstract class SymbolLightClassForInterfaceOrAnnotationClass : SymbolLi
|
||||
)
|
||||
|
||||
private val _modifierList: PsiModifierList? by lazyPub {
|
||||
val staticModifiers = setOf(PsiModifier.ABSTRACT)
|
||||
val lazyModifiers = lazyPub {
|
||||
withClassOrObjectSymbol { classOrObjectSymbol ->
|
||||
buildSet {
|
||||
add(classOrObjectSymbol.toPsiVisibilityForClass(isNested = !isTopLevel))
|
||||
add(PsiModifier.ABSTRACT)
|
||||
if (!isTopLevel && !classOrObjectSymbol.isInner) {
|
||||
add(PsiModifier.STATIC)
|
||||
}
|
||||
@@ -77,7 +77,11 @@ internal abstract class SymbolLightClassForInterfaceOrAnnotationClass : SymbolLi
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
|
||||
SymbolLightClassModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = staticModifiers,
|
||||
lazyModifiers = lazyModifiers,
|
||||
) { modifierList ->
|
||||
withClassOrObjectSymbol { classOrObjectSymbol ->
|
||||
classOrObjectSymbol.computeAnnotations(
|
||||
modifierList = modifierList,
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ internal class SymbolLightFieldForEnumEntry(
|
||||
private val _modifierList by lazyPub {
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC)),
|
||||
staticModifiers = setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC),
|
||||
) { modifierList ->
|
||||
withEnumEntrySymbol { enumEntrySymbol ->
|
||||
enumEntrySymbol.computeAnnotations(
|
||||
|
||||
+3
-1
@@ -50,14 +50,16 @@ internal class SymbolLightFieldForObject private constructor(
|
||||
override fun getName(): String = name
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val staticModifiers = setOf(PsiModifier.STATIC, PsiModifier.FINAL)
|
||||
val lazyModifiers = lazyPub {
|
||||
withObjectDeclarationSymbol { objectSymbol ->
|
||||
setOf(objectSymbol.toPsiVisibilityForMember(), PsiModifier.STATIC, PsiModifier.FINAL)
|
||||
setOf(objectSymbol.toPsiVisibilityForMember())
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = staticModifiers,
|
||||
lazyModifiers = lazyModifiers,
|
||||
) { modifierList ->
|
||||
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, modifierList))
|
||||
|
||||
+12
-7
@@ -91,7 +91,7 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
|
||||
override fun getName(): String = fieldName
|
||||
|
||||
private fun computeModifiers(): Set<String> = withPropertySymbol { propertySymbol ->
|
||||
private fun computeLazyModifiers(): Set<String> = withPropertySymbol { propertySymbol ->
|
||||
buildSet {
|
||||
val suppressFinal = !propertySymbol.isVal
|
||||
|
||||
@@ -101,13 +101,10 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
result = this
|
||||
)
|
||||
|
||||
if (forceStatic) {
|
||||
add(PsiModifier.STATIC)
|
||||
if (takePropertyVisibility) {
|
||||
add(propertySymbol.toPsiVisibilityForMember())
|
||||
}
|
||||
|
||||
val visibility = if (takePropertyVisibility) propertySymbol.toPsiVisibilityForMember() else PsiModifier.PRIVATE
|
||||
add(visibility)
|
||||
|
||||
if (!suppressFinal) {
|
||||
add(PsiModifier.FINAL)
|
||||
}
|
||||
@@ -123,9 +120,17 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val staticModifiers = setOfNotNull(
|
||||
PsiModifier.PRIVATE.takeUnless { takePropertyVisibility },
|
||||
PsiModifier.STATIC.takeIf { forceStatic },
|
||||
)
|
||||
|
||||
val lazyModifiers = lazyPub { computeLazyModifiers() }
|
||||
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
lazyModifiers = lazyPub { computeModifiers() },
|
||||
staticModifiers = staticModifiers,
|
||||
lazyModifiers = lazyModifiers,
|
||||
) { modifierList ->
|
||||
withPropertySymbol { propertySymbol ->
|
||||
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit)) {
|
||||
|
||||
+5
-4
@@ -178,16 +178,17 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
modifiers.add(PsiModifier.STATIC)
|
||||
}
|
||||
|
||||
if (isInterfaceMethod) {
|
||||
modifiers.add(PsiModifier.ABSTRACT)
|
||||
}
|
||||
|
||||
modifiers
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val staticModifiers = setOfNotNull(
|
||||
PsiModifier.ABSTRACT.takeIf { containingClass.isInterface },
|
||||
)
|
||||
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = staticModifiers,
|
||||
lazyModifiers = lazyPub { computeModifiers() },
|
||||
annotationsComputer = ::computeAnnotations,
|
||||
)
|
||||
|
||||
+14
-9
@@ -42,20 +42,25 @@ internal class SymbolLightConstructor(
|
||||
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
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.
|
||||
// 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
|
||||
val (staticModifiers, lazyModifiers) = if (containingClass is SymbolLightClassForEnumEntry) {
|
||||
setOf(PsiModifier.PACKAGE_LOCAL) to null
|
||||
} else {
|
||||
emptySet<String>() to 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.
|
||||
withFunctionSymbol { constructorSymbol ->
|
||||
setOf(constructorSymbol.toPsiVisibilityForMember())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SymbolLightMemberModifierList(containingDeclaration = this, lazyModifiers = lazyModifiers) { modifierList ->
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
staticModifiers = staticModifiers,
|
||||
lazyModifiers = lazyModifiers,
|
||||
) { modifierList ->
|
||||
withFunctionSymbol { constructorSymbol ->
|
||||
constructorSymbol.computeAnnotations(
|
||||
modifierList = modifierList,
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ internal class SymbolLightNoArgConstructor(
|
||||
override fun isDeprecated(): Boolean = false
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightMemberModifierList(containingDeclaration = this, lazyModifiers = lazyOf(setOf(visibility))) { emptyList() }
|
||||
SymbolLightMemberModifierList(containingDeclaration = this, staticModifiers = setOf(visibility)) { emptyList() }
|
||||
}
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
|
||||
internal class SymbolLightClassModifierList<T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
||||
containingDeclaration: T,
|
||||
lazyModifiers: Lazy<Set<String>>,
|
||||
staticModifiers: Set<String> = emptySet(),
|
||||
lazyModifiers: Lazy<Set<String>>? = null,
|
||||
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
|
||||
) : SymbolLightModifierList<T>(containingDeclaration, lazyModifiers, annotationsComputer)
|
||||
) : SymbolLightModifierList<T>(containingDeclaration, staticModifiers, lazyModifiers, annotationsComputer)
|
||||
|
||||
+3
-2
@@ -17,9 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.hasBody
|
||||
|
||||
internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
|
||||
containingDeclaration: T,
|
||||
lazyModifiers: Lazy<Set<String>>,
|
||||
staticModifiers: Set<String> = emptySet(),
|
||||
lazyModifiers: Lazy<Set<String>>? = null,
|
||||
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
|
||||
) : SymbolLightModifierList<T>(containingDeclaration, lazyModifiers, annotationsComputer) {
|
||||
) : SymbolLightModifierList<T>(containingDeclaration, staticModifiers, lazyModifiers, annotationsComputer) {
|
||||
override fun hasModifierProperty(name: String): Boolean = when {
|
||||
name == PsiModifier.ABSTRACT && isImplementationInInterface() -> false
|
||||
// Pretend this method behaves like a `default` method
|
||||
|
||||
+3
-2
@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
|
||||
internal abstract class SymbolLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
|
||||
protected val owner: T,
|
||||
private val lazyModifiers: Lazy<Set<String>>,
|
||||
private val staticModifiers: Set<String>,
|
||||
private val lazyModifiers: Lazy<Set<String>>?,
|
||||
annotationsComputer: (PsiModifierList) -> List<PsiAnnotation>,
|
||||
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierListOwner> {
|
||||
override val kotlinOrigin: KtModifierList? get() = owner.kotlinOrigin?.modifierList
|
||||
@@ -48,5 +49,5 @@ internal abstract class SymbolLightModifierList<out T : KtLightElement<KtModifie
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
|
||||
override fun hasExplicitModifier(name: String) = hasModifierProperty(name)
|
||||
override fun hasModifierProperty(name: String): Boolean = name in lazyModifiers.value
|
||||
override fun hasModifierProperty(name: String): Boolean = name in staticModifiers || lazyModifiers?.value?.contains(name) == true
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ internal class SymbolLightParameter(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
|
||||
SymbolLightClassModifierList(containingDeclaration = this) { modifierList ->
|
||||
val annotationSite = isConstructorParameterSymbol.ifTrue {
|
||||
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER
|
||||
}
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
|
||||
SymbolLightClassModifierList(containingDeclaration = this) { modifierList ->
|
||||
withReceiverSymbol { receiver ->
|
||||
buildList {
|
||||
receiver.type.nullabilityType.computeNullabilityAnnotation(modifierList)?.let(::add)
|
||||
@@ -82,7 +82,7 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
|
||||
private val _type: PsiType by lazyPub {
|
||||
withReceiverSymbol { receiver ->
|
||||
receiver.type.asPsiType(this@SymbolLightParameterForReceiver)
|
||||
receiver.type.asPsiType(this)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ internal class SymbolLightSetterParameter(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
|
||||
SymbolLightClassModifierList(containingDeclaration = this) { modifierList ->
|
||||
analyzeForLightClasses(ktModule) {
|
||||
val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
|
||||
modifierList = modifierList,
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ internal class SymbolLightSuspendContinuationParameter(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightClassModifierList(containingDeclaration = this, lazyModifiers = lazyOf(emptySet())) { modifierList ->
|
||||
SymbolLightClassModifierList(containingDeclaration = this) { modifierList ->
|
||||
if (withFunctionSymbol { it.visibility.isPrivateOrPrivateToThis() })
|
||||
emptyList()
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user