[LC] do not store name identifier as property

^KT-56613
This commit is contained in:
Dmitrii Gridin
2023-02-23 17:49:18 +01:00
committed by Space Team
parent 327208fb8a
commit 58dc93da90
11 changed files with 26 additions and 49 deletions
@@ -37,8 +37,6 @@ abstract class KtLightClassForSourceDeclaration(
StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
override fun cacheDependencies(): List<Any> = classOrObject.getExternalDependencies()
private val lightIdentifier = KtLightIdentifier(this, classOrObject)
override fun getText() = kotlinOrigin.text ?: ""
override fun getTextRange(): TextRange? = kotlinOrigin.textRange ?: TextRange.EMPTY_RANGE
@@ -133,7 +131,7 @@ abstract class KtLightClassForSourceDeclaration(
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
override fun getNameIdentifier(): KtLightIdentifier? = lightIdentifier
override fun getNameIdentifier(): KtLightIdentifier? = KtLightIdentifier(this, classOrObject)
override fun getExtendsList(): PsiReferenceList? = _extendsList
override fun getImplementsList(): PsiReferenceList? = _implementsList
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -36,4 +36,14 @@ open class KtLightIdentifier @JvmOverloads constructor(
override fun getTextRange(): TextRange = origin?.textRange ?: TextRange.EMPTY_RANGE
override fun getTextOffset(): Int = origin?.textOffset ?: -1
override fun equals(other: Any?): Boolean {
return other === this ||
other is KtLightIdentifier &&
other.lightOwner == lightOwner &&
other.ktDeclaration == ktDeclaration &&
other.name == name
}
override fun hashCode(): Int = lightOwner.hashCode()
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -12,7 +12,6 @@ import com.intellij.psi.PsiModifierList
import com.intellij.psi.javadoc.PsiDocComment
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtNamedDeclaration
@@ -20,8 +19,6 @@ abstract class KtLightMemberImpl<out D : PsiMember>(
override val lightMemberOrigin: LightMemberOriginForDeclaration?,
private val containingClass: KtLightClass,
) : KtLightElementBase(containingClass), PsiMember, KtLightMember<D> {
private val lightIdentifier by lazyPub { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
abstract override fun hasModifierProperty(name: String): Boolean
abstract override fun getModifierList(): PsiModifierList?
@@ -32,7 +29,7 @@ abstract class KtLightMemberImpl<out D : PsiMember>(
abstract override fun getName(): String
override fun getNameIdentifier(): PsiIdentifier = lightIdentifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration)
override val kotlinOrigin: KtDeclaration? get() = lightMemberOrigin?.originalElement
@@ -75,11 +75,8 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
abstract override fun getOwnFields(): List<KtLightField>
abstract override fun getOwnMethods(): List<PsiMethod>
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, classOrObjectDeclaration)
}
override fun getNameIdentifier(): PsiIdentifier? = _identifier
override fun getNameIdentifier(): PsiIdentifier? = KtLightIdentifier(this, classOrObjectDeclaration)
abstract override fun getExtendsList(): PsiReferenceList?
@@ -134,12 +134,8 @@ internal class SymbolLightClassForEnumEntry(
return super.isInheritor(baseClass, checkDeep = true)
}
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, kotlinOrigin)
}
// probably should be dropped after KT-54798
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, kotlinOrigin)
override fun getName(): String? = kotlinOrigin.name
override fun isDeprecated(): Boolean = false
@@ -14,7 +14,6 @@ import com.intellij.util.PlatformIcons
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
import org.jetbrains.kotlin.asJava.classes.cannotModify
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightField
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
import org.jetbrains.kotlin.idea.KotlinLanguage
@@ -37,11 +36,7 @@ internal abstract class SymbolLightField protected constructor(
override fun hasInitializer(): Boolean = initializer !== null
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, kotlinOrigin)
}
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, kotlinOrigin)
override fun computeConstantValue(): Any? = null
@@ -229,11 +229,7 @@ internal class SymbolLightAccessorMethod private constructor(
override fun isDeprecated(): Boolean = _isDeprecated
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, containingPropertyDeclaration)
}
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, containingPropertyDeclaration)
private val _returnedType: PsiType by lazyPub {
if (!isGetter) return@lazyPub PsiType.VOID
@@ -108,10 +108,6 @@ internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol> private
}
}
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, functionDeclaration)
}
private val _isDeprecated: Boolean by lazyPub {
withFunctionSymbol { functionSymbol ->
functionSymbol.hasDeprecatedAnnotation()
@@ -120,7 +116,7 @@ internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol> private
override fun isDeprecated(): Boolean = _isDeprecated
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, functionDeclaration)
override fun getParameterList(): PsiParameterList = _parametersList
@@ -28,11 +28,7 @@ internal class SymbolLightNoArgConstructor(
override fun getTypeParameterList(): PsiTypeParameterList? = null
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, ktDeclaration = null)
}
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, ktDeclaration = null)
override fun isDeprecated(): Boolean = false
@@ -48,10 +48,6 @@ internal abstract class SymbolLightParameterCommon(
abstract override fun getModifierList(): PsiModifierList
private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, parameterDeclaration)
}
protected fun nullabilityType(): NullabilityType {
if (isVarArgs) return NullabilityType.NotNull
@@ -65,7 +61,7 @@ internal abstract class SymbolLightParameterCommon(
}
}
override fun getNameIdentifier(): PsiIdentifier = _identifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, parameterDeclaration)
private val _type by lazyPub {
parameterSymbolPointer.withSymbol(ktModule) { parameterSymbol ->
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -67,9 +67,7 @@ internal class KtUltraLightFieldForSourceDeclaration(
) : KtUltraLightFieldImpl(declaration, name, containingClass, support, modifiers),
KtLightFieldForSourceDeclarationSupport {
private val lightIdentifier = KtLightIdentifier(this, declaration)
override fun getNameIdentifier(): PsiIdentifier = lightIdentifier
override fun getNameIdentifier(): PsiIdentifier = KtLightIdentifier(this, declaration)
override fun getStartOffsetInParent(): Int = kotlinOrigin.startOffsetInParent
override fun isWritable(): Boolean = kotlinOrigin.isWritable
override fun getNavigationElement(): PsiElement = kotlinOrigin.navigationElement ?: this
@@ -143,7 +141,9 @@ internal open class KtUltraLightFieldImpl protected constructor(
get() = type
private val _type: PsiType by lazyPub {
fun nonExistent() = JavaPsiFacade.getElementFactory(project).createTypeFromText(StandardNames.NON_EXISTENT_CLASS.asString(), declaration)
fun nonExistent() = JavaPsiFacade.getElementFactory(project).createTypeFromText(
StandardNames.NON_EXISTENT_CLASS.asString(), declaration
)
when {
(declaration is KtProperty && declaration.hasDelegate()) || declaration is KtEnumEntry || declaration is KtObjectDeclaration ->