[SLC] replace lazy with lazyPub

^KT-54051
This commit is contained in:
Dmitrii Gridin
2022-11-28 11:37:24 +01:00
committed by Space Team
parent 815d324a4a
commit ef9412e0aa
29 changed files with 75 additions and 65 deletions
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.analysis.providers.KotlinPsiDeclarationProvider
import org.jetbrains.kotlin.analysis.providers.KotlinPsiDeclarationProviderFactory import org.jetbrains.kotlin.analysis.providers.KotlinPsiDeclarationProviderFactory
import org.jetbrains.kotlin.analysis.providers.createPackagePartProvider import org.jetbrains.kotlin.analysis.providers.createPackagePartProvider
import org.jetbrains.kotlin.asJava.builder.ClsWrapperStubPsiFactory import org.jetbrains.kotlin.asJava.builder.ClsWrapperStubPsiFactory
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
@@ -31,7 +32,7 @@ private class KotlinStaticPsiDeclarationFromBinaryModuleProvider(
private val binaryModules: Collection<KtBinaryModule>, private val binaryModules: Collection<KtBinaryModule>,
override val jarFileSystem: CoreJarFileSystem, override val jarFileSystem: CoreJarFileSystem,
) : KotlinPsiDeclarationProvider(), AbstractDeclarationFromBinaryModuleProvider { ) : KotlinPsiDeclarationProvider(), AbstractDeclarationFromBinaryModuleProvider {
private val psiManager by lazy { PsiManager.getInstance(project) } private val psiManager by lazyPub { PsiManager.getInstance(project) }
private fun clsClassImplsByFqName( private fun clsClassImplsByFqName(
fqName: FqName, fqName: FqName,
@@ -45,7 +45,7 @@ private class SymbolNameValuePairForAnnotationArgument(
override fun setValue(p0: PsiAnnotationMemberValue) = cannotModify() override fun setValue(p0: PsiAnnotationMemberValue) = cannotModify()
private val _nameIdentifier: PsiIdentifier by lazy { private val _nameIdentifier: PsiIdentifier by lazyPub {
LightIdentifier(parent.manager, constantValue.name.asString()) LightIdentifier(parent.manager, constantValue.name.asString())
} }
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.impl.PsiImplUtil import com.intellij.psi.impl.PsiImplUtil
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo
import org.jetbrains.kotlin.psi.KtCallElement import org.jetbrains.kotlin.psi.KtCallElement
@@ -25,7 +26,7 @@ internal class SymbolLightAnnotationForAnnotationCall(
override fun findDeclaredAttributeValue(attributeName: String?) = override fun findDeclaredAttributeValue(attributeName: String?) =
PsiImplUtil.findDeclaredAttributeValue(this, attributeName) PsiImplUtil.findDeclaredAttributeValue(this, attributeName)
private val _parameterList: PsiAnnotationParameterList by lazy { private val _parameterList: PsiAnnotationParameterList by lazyPub {
SymbolAnnotationParameterList(this, annotationCall.arguments) SymbolAnnotationParameterList(this, annotationCall.arguments)
} }
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiAnnotationParameterList
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.impl.PsiImplUtil import com.intellij.psi.impl.PsiImplUtil
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.KtCallElement import org.jetbrains.kotlin.psi.KtCallElement
internal class SymbolLightSimpleAnnotation( internal class SymbolLightSimpleAnnotation(
@@ -35,7 +36,7 @@ internal class SymbolLightSimpleAnnotation(
override fun findDeclaredAttributeValue(attributeName: String?) = override fun findDeclaredAttributeValue(attributeName: String?) =
PsiImplUtil.findDeclaredAttributeValue(this, attributeName) PsiImplUtil.findDeclaredAttributeValue(this, attributeName)
private val _parameterList: PsiAnnotationParameterList by lazy { private val _parameterList: PsiAnnotationParameterList by lazyPub {
SymbolAnnotationParameterList(this, arguments) SymbolAnnotationParameterList(this, arguments)
} }
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiClass
import org.jetbrains.kotlin.asJava.classes.KtFakeLightClass import org.jetbrains.kotlin.asJava.classes.KtFakeLightClass
import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.classes.LightClassInheritanceHelper import org.jetbrains.kotlin.asJava.classes.LightClassInheritanceHelper
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.light.classes.symbol.analyzeForLightClasses import org.jetbrains.kotlin.light.classes.symbol.analyzeForLightClasses
import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
@@ -16,7 +17,7 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
class SymbolBasedFakeLightClass(kotlinOrigin: KtClassOrObject) : KtFakeLightClass(kotlinOrigin) { class SymbolBasedFakeLightClass(kotlinOrigin: KtClassOrObject) : KtFakeLightClass(kotlinOrigin) {
override fun copy(): KtFakeLightClass = SymbolBasedFakeLightClass(kotlinOrigin) override fun copy(): KtFakeLightClass = SymbolBasedFakeLightClass(kotlinOrigin)
private val _containingClass: KtFakeLightClass? by lazy { private val _containingClass: KtFakeLightClass? by lazyPub {
kotlinOrigin.containingClassOrObject?.let { SymbolBasedFakeLightClass(it) } kotlinOrigin.containingClassOrObject?.let { SymbolBasedFakeLightClass(it) }
} }
@@ -62,49 +62,49 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
protected fun <T> withClassOrObjectSymbol(action: KtAnalysisSession.(SType) -> T): T = protected fun <T> withClassOrObjectSymbol(action: KtAnalysisSession.(SType) -> T): T =
classOrObjectSymbolPointer.withSymbol(ktModule, action) classOrObjectSymbolPointer.withSymbol(ktModule, action)
override val isTopLevel: Boolean by lazy { override val isTopLevel: Boolean by lazyPub {
classOrObjectDeclaration?.isTopLevel() ?: withClassOrObjectSymbol { it.symbolKind == KtSymbolKind.TOP_LEVEL } classOrObjectDeclaration?.isTopLevel() ?: withClassOrObjectSymbol { it.symbolKind == KtSymbolKind.TOP_LEVEL }
} }
internal val isCompanionObject: Boolean by lazy { internal val isCompanionObject: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtObjectDeclaration && it.isCompanion() } ?: withClassOrObjectSymbol { classOrObjectDeclaration?.let { it is KtObjectDeclaration && it.isCompanion() } ?: withClassOrObjectSymbol {
it.classKind == KtClassKind.COMPANION_OBJECT it.classKind == KtClassKind.COMPANION_OBJECT
} }
} }
internal val isLocal: Boolean by lazy { internal val isLocal: Boolean by lazyPub {
classOrObjectDeclaration?.isLocal ?: withClassOrObjectSymbol { it.symbolKind == KtSymbolKind.LOCAL } classOrObjectDeclaration?.isLocal ?: withClassOrObjectSymbol { it.symbolKind == KtSymbolKind.LOCAL }
} }
internal val isNamedObject: Boolean by lazy { internal val isNamedObject: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtObjectDeclaration && !it.isCompanion() } ?: withClassOrObjectSymbol { classOrObjectDeclaration?.let { it is KtObjectDeclaration && !it.isCompanion() } ?: withClassOrObjectSymbol {
it.classKind == KtClassKind.OBJECT it.classKind == KtClassKind.OBJECT
} }
} }
internal val isObject: Boolean by lazy { internal val isObject: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtObjectDeclaration } ?: withClassOrObjectSymbol { it.classKind.isObject } classOrObjectDeclaration?.let { it is KtObjectDeclaration } ?: withClassOrObjectSymbol { it.classKind.isObject }
} }
internal val isInterface: Boolean by lazy { internal val isInterface: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtClass && it.isInterface() } ?: withClassOrObjectSymbol { classOrObjectDeclaration?.let { it is KtClass && it.isInterface() } ?: withClassOrObjectSymbol {
it.classKind == KtClassKind.INTERFACE it.classKind == KtClassKind.INTERFACE
} }
} }
internal val isAnnotation: Boolean by lazy { internal val isAnnotation: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtClass && it.isAnnotation() } ?: withClassOrObjectSymbol { classOrObjectDeclaration?.let { it is KtClass && it.isAnnotation() } ?: withClassOrObjectSymbol {
it.classKind == KtClassKind.ANNOTATION_CLASS it.classKind == KtClassKind.ANNOTATION_CLASS
} }
} }
internal val isEnum: Boolean by lazy { internal val isEnum: Boolean by lazyPub {
classOrObjectDeclaration?.let { it is KtClass && it.isEnum() } ?: withClassOrObjectSymbol { classOrObjectDeclaration?.let { it is KtClass && it.isEnum() } ?: withClassOrObjectSymbol {
it.classKind == KtClassKind.ENUM_CLASS it.classKind == KtClassKind.ENUM_CLASS
} }
} }
private val _isDeprecated: Boolean by lazy { private val _isDeprecated: Boolean by lazyPub {
withClassOrObjectSymbol { it.hasDeprecatedAnnotation() } withClassOrObjectSymbol { it.hasDeprecatedAnnotation() }
} }
@@ -114,7 +114,7 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
abstract override fun getOwnFields(): List<KtLightField> abstract override fun getOwnFields(): List<KtLightField>
abstract override fun getOwnMethods(): List<PsiMethod> abstract override fun getOwnMethods(): List<PsiMethod>
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, classOrObjectDeclaration) KtLightIdentifier(this, classOrObjectDeclaration)
} }
@@ -123,7 +123,7 @@ abstract class SymbolLightClassForClassLike<SType : KtClassOrObjectSymbol> prote
abstract override fun getExtendsList(): PsiReferenceList? abstract override fun getExtendsList(): PsiReferenceList?
abstract override fun getImplementsList(): PsiReferenceList? abstract override fun getImplementsList(): PsiReferenceList?
private val _typeParameterList: PsiTypeParameterList? by lazy { private val _typeParameterList: PsiTypeParameterList? by lazyPub {
hasTypeParameters().ifTrue { hasTypeParameters().ifTrue {
SymbolLightTypeParameterList( SymbolLightTypeParameterList(
owner = this, owner = this,
@@ -85,8 +85,8 @@ internal open class SymbolLightClassForClassOrObject : SymbolLightClassForNamedC
manager = manager, manager = manager,
) )
private val _modifierList: PsiModifierList? by lazy { private val _modifierList: PsiModifierList? by lazyPub {
val lazyModifiers = lazy { val lazyModifiers = lazyPub {
withClassOrObjectSymbol { classOrObjectSymbol -> withClassOrObjectSymbol { classOrObjectSymbol ->
buildSet { buildSet {
add(classOrObjectSymbol.toPsiVisibilityForClass(isNested = !isTopLevel)) add(classOrObjectSymbol.toPsiVisibilityForClass(isNested = !isTopLevel))
@@ -44,7 +44,7 @@ internal class SymbolLightClassForEnumEntry(
override fun toString(): String = "SymbolLightClassForEnumEntry:$name" override fun toString(): String = "SymbolLightClassForEnumEntry:$name"
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
SymbolLightClassModifierList( SymbolLightClassModifierList(
containingDeclaration = this, containingDeclaration = this,
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL)), lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL)),
@@ -62,11 +62,11 @@ class SymbolLightClassForFacade(
action(files.map { it.getFileSymbol() }) action(files.map { it.getFileSymbol() })
} }
private val firstFileInFacade by lazy { files.first() } private val firstFileInFacade by lazyPub { files.first() }
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
if (multiFileClass) if (multiFileClass)
return@lazy LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL) return@lazyPub LightModifierList(manager, KotlinLanguage.INSTANCE, PsiModifier.PUBLIC, PsiModifier.FINAL)
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.FINAL)) val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.FINAL))
@@ -111,7 +111,7 @@ class SymbolLightClassForFacade(
} }
} }
private val multiFileClass: Boolean by lazy { private val multiFileClass: Boolean by lazyPub {
files.size > 1 || firstFileInFacade.isJvmMultifileClassFile files.size > 1 || firstFileInFacade.isJvmMultifileClassFile
} }
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.light.classes.symbol.classes
import com.intellij.psi.* import com.intellij.psi.*
import com.intellij.util.IncorrectOperationException 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.light.classes.symbol.modifierLists.SymbolLightClassModifierList
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
@@ -32,7 +33,7 @@ internal class SymbolLightClassForInterfaceDefaultImpls(private val containingCl
override fun getTypeParameterList(): PsiTypeParameterList? = null override fun getTypeParameterList(): PsiTypeParameterList? = null
override fun getTypeParameters(): Array<PsiTypeParameter> = emptyArray() override fun getTypeParameters(): Array<PsiTypeParameter> = emptyArray()
private val _modifierList: PsiModifierList? by lazy { private val _modifierList: PsiModifierList? by lazyPub {
val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL)) val lazyModifiers = lazyOf(setOf(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL))
val lazyAnnotations = lazyOf(emptyList<PsiAnnotation>()) val lazyAnnotations = lazyOf(emptyList<PsiAnnotation>())
SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations) SymbolLightClassModifierList(this, lazyModifiers, lazyAnnotations)
@@ -64,8 +64,8 @@ internal abstract class SymbolLightClassForInterfaceOrAnnotationClass : SymbolLi
manager = manager, manager = manager,
) )
private val _modifierList: PsiModifierList? by lazy { private val _modifierList: PsiModifierList? by lazyPub {
val lazyModifiers = lazy { val lazyModifiers = lazyPub {
withClassOrObjectSymbol { classOrObjectSymbol -> withClassOrObjectSymbol { classOrObjectSymbol ->
buildSet { buildSet {
add(classOrObjectSymbol.toPsiVisibilityForClass(isNested = !isTopLevel)) add(classOrObjectSymbol.toPsiVisibilityForClass(isNested = !isTopLevel))
@@ -14,6 +14,7 @@ import com.intellij.util.PlatformIcons
import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
import org.jetbrains.kotlin.asJava.classes.cannotModify 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.KtLightField
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.KotlinLanguage
@@ -36,7 +37,7 @@ internal abstract class SymbolLightField protected constructor(
override fun hasInitializer(): Boolean = initializer !== null override fun hasInitializer(): Boolean = initializer !== null
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, kotlinOrigin) KtLightIdentifier(this, kotlinOrigin)
} }
@@ -30,7 +30,7 @@ internal class SymbolLightFieldForEnumEntry(
action(enumEntry.getEnumEntrySymbol()) action(enumEntry.getEnumEntrySymbol())
} }
private val _modifierList by lazy { private val _modifierList by lazyPub {
SymbolLightMemberModifierList( SymbolLightMemberModifierList(
containingDeclaration = this@SymbolLightFieldForEnumEntry, containingDeclaration = this@SymbolLightFieldForEnumEntry,
lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC)), lazyModifiers = lazyOf(setOf(PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PUBLIC)),
@@ -54,7 +54,7 @@ internal class SymbolLightFieldForEnumEntry(
private val hasBody: Boolean get() = enumEntry.body != null private val hasBody: Boolean get() = enumEntry.body != null
private val _initializingClass: PsiEnumConstantInitializer? by lazy { private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
hasBody.ifTrue { hasBody.ifTrue {
SymbolLightClassForEnumEntry( SymbolLightClassForEnumEntry(
enumConstant = this@SymbolLightFieldForEnumEntry, enumConstant = this@SymbolLightFieldForEnumEntry,
@@ -49,14 +49,14 @@ internal class SymbolLightFieldForObject private constructor(
override fun getName(): String = name override fun getName(): String = name
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazy { val lazyModifiers = lazyPub {
withObjectDeclarationSymbol { objectSymbol -> withObjectDeclarationSymbol { objectSymbol ->
setOf(objectSymbol.toPsiVisibilityForMember(), PsiModifier.STATIC, PsiModifier.FINAL) setOf(objectSymbol.toPsiVisibilityForMember(), PsiModifier.STATIC, PsiModifier.FINAL)
} }
} }
val lazyAnnotations = lazy { val lazyAnnotations = lazyPub {
val notNullAnnotation = SymbolLightSimpleAnnotation(NotNull::class.java.name, this) val notNullAnnotation = SymbolLightSimpleAnnotation(NotNull::class.java.name, this)
listOf(notNullAnnotation) listOf(notNullAnnotation)
} }
@@ -64,7 +64,7 @@ internal class SymbolLightFieldForObject private constructor(
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations) SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
} }
private val _isDeprecated: Boolean by lazy { private val _isDeprecated: Boolean by lazyPub {
withObjectDeclarationSymbol { objectSymbol -> withObjectDeclarationSymbol { objectSymbol ->
objectSymbol.hasDeprecatedAnnotation() objectSymbol.hasDeprecatedAnnotation()
} }
@@ -76,7 +76,7 @@ internal class SymbolLightFieldForProperty private constructor(
} }
} }
private val _isDeprecated: Boolean by lazy { private val _isDeprecated: Boolean by lazyPub {
withPropertySymbol { propertySymbol -> withPropertySymbol { propertySymbol ->
propertySymbol.hasDeprecatedAnnotation(AnnotationUseSiteTarget.FIELD) propertySymbol.hasDeprecatedAnnotation(AnnotationUseSiteTarget.FIELD)
} }
@@ -131,7 +131,7 @@ internal class SymbolLightFieldForProperty private constructor(
) )
} }
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazyPub { computeModifiers() } val lazyModifiers = lazyPub { computeModifiers() }
val lazyAnnotations = lazyPub { computeAnnotations() } val lazyAnnotations = lazyPub { computeAnnotations() }
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations) SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
@@ -103,7 +103,7 @@ internal class SymbolLightAccessorMethod private constructor(
override fun getName(): String = _name override fun getName(): String = _name
private val _typeParameterList: PsiTypeParameterList? by lazy { private val _typeParameterList: PsiTypeParameterList? by lazyPub {
hasTypeParameters().ifTrue { hasTypeParameters().ifTrue {
SymbolLightTypeParameterList( SymbolLightTypeParameterList(
owner = this, owner = this,
@@ -183,7 +183,7 @@ internal class SymbolLightAccessorMethod private constructor(
modifiers modifiers
} }
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazyPub { computeModifiers() } val lazyModifiers = lazyPub { computeModifiers() }
val lazyAnnotations = lazyPub { computeAnnotations(PsiModifier.PRIVATE in lazyModifiers.value) } val lazyAnnotations = lazyPub { computeAnnotations(PsiModifier.PRIVATE in lazyModifiers.value) }
SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations) SymbolLightMemberModifierList(this, lazyModifiers, lazyAnnotations)
@@ -193,7 +193,7 @@ internal class SymbolLightAccessorMethod private constructor(
override fun isConstructor(): Boolean = false override fun isConstructor(): Boolean = false
private val _isDeprecated: Boolean by lazy { private val _isDeprecated: Boolean by lazyPub {
analyzeForLightClasses(ktModule) { analyzeForLightClasses(ktModule) {
propertySymbol().hasDeprecatedAnnotation(accessorSite) propertySymbol().hasDeprecatedAnnotation(accessorSite)
} }
@@ -201,7 +201,7 @@ internal class SymbolLightAccessorMethod private constructor(
override fun isDeprecated(): Boolean = _isDeprecated override fun isDeprecated(): Boolean = _isDeprecated
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, containingPropertyDeclaration) KtLightIdentifier(this, containingPropertyDeclaration)
} }
@@ -43,7 +43,7 @@ internal class SymbolLightConstructor(
override fun getTypeParameterList(): PsiTypeParameterList? = null override fun getTypeParameterList(): PsiTypeParameterList? = null
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub { val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
withFunctionSymbol { constructorSymbol -> withFunctionSymbol { constructorSymbol ->
constructorSymbol.computeAnnotations( constructorSymbol.computeAnnotations(
@@ -54,7 +54,7 @@ internal class SymbolLightConstructor(
} }
} }
val lazyModifiers: Lazy<Set<String>> = lazy { val lazyModifiers: Lazy<Set<String>> = lazyPub {
// FIR treats an enum entry as an anonymous object w/ its own ctor (not default one). // 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. // 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. // Technically, an enum entry should not be instantiated anywhere else, and thus FIR's modeling makes sense.
@@ -63,7 +63,7 @@ internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol> private
protected fun <T> withFunctionSymbol(action: KtAnalysisSession.(FType) -> T): T = functionSymbolPointer.withSymbol(ktModule, action) protected fun <T> withFunctionSymbol(action: KtAnalysisSession.(FType) -> T): T = functionSymbolPointer.withSymbol(ktModule, action)
private val _isVarArgs: Boolean by lazy { private val _isVarArgs: Boolean by lazyPub {
functionDeclaration?.valueParameters?.any { it.isVarArg } ?: withFunctionSymbol { functionSymbol -> functionDeclaration?.valueParameters?.any { it.isVarArg } ?: withFunctionSymbol { functionSymbol ->
functionSymbol.valueParameters.any { it.isVararg } functionSymbol.valueParameters.any { it.isVararg }
} }
@@ -103,11 +103,11 @@ internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol> private
} }
} }
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this@SymbolLightMethod, functionDeclaration) KtLightIdentifier(this, functionDeclaration)
} }
private val _isDeprecated: Boolean by lazy { private val _isDeprecated: Boolean by lazyPub {
withFunctionSymbol { functionSymbol -> withFunctionSymbol { functionSymbol ->
functionSymbol.hasDeprecatedAnnotation() functionSymbol.hasDeprecatedAnnotation()
} }
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.light.classes.symbol.methods
import com.intellij.psi.* import com.intellij.psi.*
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForClassLike import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForClassLike
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList
@@ -26,7 +27,7 @@ internal class SymbolLightNoArgConstructor(
override fun getTypeParameterList(): PsiTypeParameterList? = null override fun getTypeParameterList(): PsiTypeParameterList? = null
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, ktDeclaration = null) KtLightIdentifier(this, ktDeclaration = null)
} }
@@ -34,13 +35,13 @@ internal class SymbolLightNoArgConstructor(
override fun isDeprecated(): Boolean = false override fun isDeprecated(): Boolean = false
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
SymbolLightMemberModifierList(this, lazyOf(setOf(visibility)), lazyOf(emptyList())) SymbolLightMemberModifierList(this, lazyOf(setOf(visibility)), lazyOf(emptyList()))
} }
override fun getModifierList(): PsiModifierList = _modifierList override fun getModifierList(): PsiModifierList = _modifierList
private val _parameterList: PsiParameterList by lazy { private val _parameterList: PsiParameterList by lazyPub {
SymbolLightParameterList(parent = this) SymbolLightParameterList(parent = this)
} }
@@ -119,7 +119,7 @@ internal class SymbolLightSimpleMethod(
return modifiers return modifiers
} }
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyModifiers = lazyPub { val lazyModifiers = lazyPub {
withFunctionSymbol { functionSymbol -> withFunctionSymbol { functionSymbol ->
computeModifiers(functionSymbol) computeModifiers(functionSymbol)
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.light.classes.symbol.modifierLists
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifierListOwner 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.KtLightAbstractAnnotation
import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
@@ -18,7 +19,7 @@ internal class SymbolLightClassModifierList<T : KtLightElement<KtModifierListOwn
private val lazyModifiers: Lazy<Set<String>>, private val lazyModifiers: Lazy<Set<String>>,
lazyAnnotations: Lazy<List<PsiAnnotation>>, lazyAnnotations: Lazy<List<PsiAnnotation>>,
) : SymbolLightModifierList<T>(containingDeclaration) { ) : SymbolLightModifierList<T>(containingDeclaration) {
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazy { private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this } lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
} }
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.light.classes.symbol.modifierLists
import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiAnnotation import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiModifier 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.KtLightAbstractAnnotation
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.asJava.elements.KtLightMember import org.jetbrains.kotlin.asJava.elements.KtLightMember
@@ -22,7 +23,7 @@ internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
private val lazyModifiers: Lazy<Set<String>>, private val lazyModifiers: Lazy<Set<String>>,
lazyAnnotations: Lazy<List<PsiAnnotation>> lazyAnnotations: Lazy<List<PsiAnnotation>>
) : SymbolLightModifierList<T>(containingDeclaration) { ) : SymbolLightModifierList<T>(containingDeclaration) {
private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazy { private val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this } lazyAnnotations.value.onEach { (it as? KtLightElementBase)?.parent = this }
} }
@@ -27,7 +27,7 @@ internal class SymbolLightParameter(
override fun getModifierList(): PsiModifierList = _modifierList override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub { val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
val annotationSite = isConstructorParameterSymbol.ifTrue { val annotationSite = isConstructorParameterSymbol.ifTrue {
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER
@@ -48,7 +48,7 @@ internal class SymbolLightParameter(
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations) SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
} }
private val isVararg: Boolean by lazy { private val isVararg: Boolean by lazyPub {
parameterSymbolPointer.withSymbol(ktModule) { it.isVararg } parameterSymbolPointer.withSymbol(ktModule) { it.isVararg }
} }
@@ -35,7 +35,7 @@ internal abstract class SymbolLightParameterCommon(
kotlinOrigin = parameterSymbol.psiSafe(), kotlinOrigin = parameterSymbol.psiSafe(),
) )
private val _name: String by lazy { private val _name: String by lazyPub {
parameterSymbolPointer.withSymbol(ktModule) { parameterSymbolPointer.withSymbol(ktModule) {
it.name.asString() it.name.asString()
} }
@@ -47,7 +47,7 @@ internal abstract class SymbolLightParameterCommon(
abstract override fun getModifierList(): PsiModifierList abstract override fun getModifierList(): PsiModifierList
private val _identifier: PsiIdentifier by lazy { private val _identifier: PsiIdentifier by lazyPub {
KtLightIdentifier(this, parameterDeclaration) KtLightIdentifier(this, parameterDeclaration)
} }
@@ -64,7 +64,7 @@ internal abstract class SymbolLightParameterCommon(
override fun getNameIdentifier(): PsiIdentifier = _identifier override fun getNameIdentifier(): PsiIdentifier = _identifier
private val _type by lazy { private val _type by lazyPub {
parameterSymbolPointer.withSymbol(ktModule) { parameterSymbol -> parameterSymbolPointer.withSymbol(ktModule) { parameterSymbol ->
val convertedType = run { val convertedType = run {
val ktType = parameterSymbol.returnType val ktType = parameterSymbol.returnType
@@ -53,7 +53,7 @@ internal class SymbolLightParameterForReceiver private constructor(
} }
} }
private val _name: String by lazy { private val _name: String by lazyPub {
AsmUtil.getLabeledThisName(methodName, AsmUtil.LABELED_THIS_PARAMETER, AsmUtil.RECEIVER_PARAMETER_NAME) AsmUtil.getLabeledThisName(methodName, AsmUtil.LABELED_THIS_PARAMETER, AsmUtil.RECEIVER_PARAMETER_NAME)
} }
@@ -68,7 +68,7 @@ internal class SymbolLightParameterForReceiver private constructor(
override fun getModifierList(): PsiModifierList = _modifierList override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<SymbolLightAbstractAnnotation>> = lazyPub { val lazyAnnotations: Lazy<List<SymbolLightAbstractAnnotation>> = lazyPub {
withReceiverSymbol { receiver -> withReceiverSymbol { receiver ->
buildList { buildList {
@@ -83,7 +83,7 @@ internal class SymbolLightParameterForReceiver private constructor(
SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations) SymbolLightClassModifierList(this, lazyOf(emptySet()), lazyAnnotations)
} }
private val _type: PsiType by lazy { private val _type: PsiType by lazyPub {
withReceiverSymbol { receiver -> withReceiverSymbol { receiver ->
receiver.type.asPsiType(this@SymbolLightParameterForReceiver) receiver.type.asPsiType(this@SymbolLightParameterForReceiver)
} ?: nonExistentType() } ?: nonExistentType()
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiParameterList
import com.intellij.psi.impl.light.LightParameterListBuilder import com.intellij.psi.impl.light.LightParameterListBuilder
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
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.elements.KtLightElement import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
@@ -29,7 +30,7 @@ internal class SymbolLightParameterList(
override val kotlinOrigin: KtParameterList? override val kotlinOrigin: KtParameterList?
get() = (parent.kotlinOrigin as? KtFunction)?.valueParameterList get() = (parent.kotlinOrigin as? KtFunction)?.valueParameterList
private val clsDelegate: PsiParameterList by lazy { private val clsDelegate: PsiParameterList by lazyPub {
val builder = LightParameterListBuilder(manager, language) val builder = LightParameterListBuilder(manager, language)
callableWithReceiverSymbolPointer?.let { callableWithReceiverSymbolPointer?.let {
@@ -33,7 +33,7 @@ internal class SymbolLightSetterParameter(
return super.getName() return super.getName()
} }
private val isDefaultSetterParameter: Boolean by lazy { private val isDefaultSetterParameter: Boolean by lazyPub {
containingPropertySymbolPointer.withSymbol(ktModule) { containingPropertySymbolPointer.withSymbol(ktModule) {
it.setter?.isDefault != false it.setter?.isDefault != false
} }
@@ -41,7 +41,7 @@ internal class SymbolLightSetterParameter(
override fun getModifierList(): PsiModifierList = _modifierList override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub { val lazyAnnotations: Lazy<List<PsiAnnotation>> = lazyPub {
analyzeForLightClasses(ktModule) { analyzeForLightClasses(ktModule) {
val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations( val annotationsFromSetter = parameterSymbolPointer.restoreSymbolOrThrowIfDisposed().computeAnnotations(
@@ -49,8 +49,8 @@ internal class SymbolLightSuspendContinuationParameter(
override fun getModifierList(): PsiModifierList = _modifierList override fun getModifierList(): PsiModifierList = _modifierList
private val _modifierList: PsiModifierList by lazy { private val _modifierList: PsiModifierList by lazyPub {
val lazyAnnotations = lazy { val lazyAnnotations = lazyPub {
if (withFunctionSymbol { it.visibility.isPrivateOrPrivateToThis() }) if (withFunctionSymbol { it.visibility.isPrivateOrPrivateToThis() })
emptyList() emptyList()
else else
@@ -158,7 +158,7 @@ internal class SymbolLightTypeParameter private constructor(
override fun addAnnotation(qualifiedName: String): PsiAnnotation = cannotModify() override fun addAnnotation(qualifiedName: String): PsiAnnotation = cannotModify()
//End of PsiClass simple implementation //End of PsiClass simple implementation
private val _name: String by lazy { private val _name: String by lazyPub {
typeParameterDeclaration?.name ?: withTypeParameterSymbol { it.name.asString() } typeParameterDeclaration?.name ?: withTypeParameterSymbol { it.name.asString() }
} }