[SLC] drop KtAnalysisSession from SymbolLightTypeParameterList

^KT-54051
This commit is contained in:
Dmitrii Gridin
2022-11-24 13:58:02 +01:00
committed by Space Team
parent 5217a97145
commit af73bb9bf3
4 changed files with 61 additions and 47 deletions
@@ -14,6 +14,8 @@ import com.intellij.psi.stubs.StubElement
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.symbols.pointers.symbolPointer
import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.asJava.classes.getParentForLocalDeclaration
import org.jetbrains.kotlin.asJava.classes.lazyPub
@@ -28,6 +30,7 @@ import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo
import org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForObject
import org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForProperty
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightTypeParameterList
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassBody
@@ -42,10 +45,11 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
abstract class SymbolLightClassForClassOrObject(protected val classOrObject: KtClassOrObject, ktModule: KtModule) :
SymbolLightClassBase(ktModule, classOrObject.manager),
StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
protected fun <T> withClassOrObjectSymbol(action: KtAnalysisSession.(KtClassOrObjectSymbol) -> T): T =
analyzeForLightClasses(ktModule) {
action(requireNotNull(classOrObject.getClassOrObjectSymbol()))
}
private val classOrObjectSymbolPointer: KtSymbolPointer<KtClassOrObjectSymbol> = classOrObject.symbolPointer()
protected fun <T> withClassOrObjectSymbol(action: KtAnalysisSession.(KtClassOrObjectSymbol) -> T): T {
return classOrObjectSymbolPointer.withSymbol(ktModule, action)
}
protected fun <T> withNamedClassOrObjectSymbol(action: KtAnalysisSession.(KtNamedClassOrObjectSymbol) -> T): T =
analyzeForLightClasses(ktModule) {
@@ -82,12 +86,12 @@ abstract class SymbolLightClassForClassOrObject(protected val classOrObject: KtC
private val _typeParameterList: PsiTypeParameterList? by lazyPub {
hasTypeParameters().ifTrue {
withClassOrObjectSymbol {
SymbolLightTypeParameterList(
owner = this@SymbolLightClassForClassOrObject,
symbolWithTypeParameterList = it,
)
}
SymbolLightTypeParameterList(
owner = this,
symbolWithTypeParameterPointer = classOrObjectSymbolPointer,
ktModule = ktModule,
ktDeclaration = classOrObject,
)
}
}
@@ -89,12 +89,12 @@ internal class SymbolLightAccessorMethod(
private val _typeParameterList: PsiTypeParameterList? by lazyPub {
hasTypeParameters().ifTrue {
analyzeForLightClasses(ktModule) {
SymbolLightTypeParameterList(
owner = this@SymbolLightAccessorMethod,
symbolWithTypeParameterList = propertySymbol(),
)
}
SymbolLightTypeParameterList(
owner = this,
symbolWithTypeParameterPointer = containingPropertySymbolPointer,
ktModule = ktModule,
ktDeclaration = containingPropertyDeclaration,
)
}
}
@@ -51,12 +51,12 @@ internal class SymbolLightSimpleMethod(
private val _typeParameterList: PsiTypeParameterList? by lazyPub {
hasTypeParameters().ifTrue {
withFunctionSymbol { functionSymbol ->
SymbolLightTypeParameterList(
owner = this@SymbolLightSimpleMethod,
symbolWithTypeParameterList = functionSymbol,
)
}
SymbolLightTypeParameterList(
owner = this,
symbolWithTypeParameterPointer = functionSymbolPointer,
ktModule = ktModule,
ktDeclaration = functionDeclaration,
)
}
}
@@ -8,18 +8,22 @@ package org.jetbrains.kotlin.light.classes.symbol.parameters
import com.intellij.psi.*
import com.intellij.psi.impl.light.LightElement
import com.intellij.psi.scope.PsiScopeProcessor
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithTypeParameters
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo
import org.jetbrains.kotlin.light.classes.symbol.compareSymbolPointers
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
context(KtAnalysisSession)
internal class SymbolLightTypeParameterList(
internal val owner: PsiTypeParameterListOwner,
private val symbolWithTypeParameterList: KtSymbolWithTypeParameters,
private val symbolWithTypeParameterPointer: KtSymbolPointer<KtSymbolWithTypeParameters>,
internal val ktModule: KtModule,
private val ktDeclaration: KtTypeParameterListOwner?,
) : LightElement(owner.manager, KotlinLanguage.INSTANCE), PsiTypeParameterList {
override fun accept(visitor: PsiElementVisitor) {
if (visitor is JavaElementVisitor) {
visitor.visitTypeParameterList(this)
@@ -33,39 +37,45 @@ internal class SymbolLightTypeParameterList(
state: ResolveState,
lastParent: PsiElement?,
place: PsiElement
): Boolean {
return typeParameters.all { processor.execute(it, state) }
}
): Boolean = typeParameters.all { processor.execute(it, state) }
private val _typeParameters: Array<PsiTypeParameter> by lazyPub {
symbolWithTypeParameterList.typeParameters.mapIndexed { index, parameter ->
SymbolLightTypeParameter(
parent = this@SymbolLightTypeParameterList,
index = index,
typeParameterSymbol = parameter
)
}.toTypedArray()
symbolWithTypeParameterPointer.withSymbol(ktModule) {
it.typeParameters.mapIndexed { index, parameter ->
SymbolLightTypeParameter(
parent = this,
index = index,
typeParameterSymbol = parameter,
)
}.toTypedArray()
}
}
override fun getTypeParameters(): Array<PsiTypeParameter> = _typeParameters
override fun getTypeParameterIndex(typeParameter: PsiTypeParameter?): Int =
_typeParameters.indexOf(typeParameter)
override fun getTypeParameterIndex(typeParameter: PsiTypeParameter?): Int = _typeParameters.indexOf(typeParameter)
override fun toString(): String = "SymbolLightTypeParameterList"
override fun equals(other: Any?): Boolean =
this === other ||
(other is SymbolLightTypeParameterList && symbolWithTypeParameterList == other.symbolWithTypeParameterList)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SymbolLightTypeParameterList || other.ktModule != ktModule) return false
if (ktDeclaration != null) {
return other.ktDeclaration == ktDeclaration
}
override fun hashCode(): Int = symbolWithTypeParameterList.hashCode()
return other.ktDeclaration == null &&
compareSymbolPointers(ktModule, symbolWithTypeParameterPointer, other.symbolWithTypeParameterPointer) &&
other.owner == owner
}
override fun isEquivalentTo(another: PsiElement?): Boolean =
basicIsEquivalentTo(this, another)
override fun hashCode(): Int = ktDeclaration.hashCode() + 1
override fun isEquivalentTo(another: PsiElement?): Boolean = basicIsEquivalentTo(this, another)
override fun getParent(): PsiElement = owner
override fun getContainingFile(): PsiFile = parent.containingFile
override fun getText(): String? = ""
override fun getTextOffset(): Int = 0
override fun getStartOffsetInParent(): Int = 0
override fun getText(): String? = ktDeclaration?.typeParameterList?.text
override fun getTextOffset(): Int = ktDeclaration?.typeParameterList?.textOffset ?: -1
override fun getStartOffsetInParent(): Int = ktDeclaration?.typeParameterList?.startOffsetInParent ?: -1
}