[SLC] drop KtAnalysisSession from SymbolLightTypeParameter
^KT-54051
This commit is contained in:
committed by
Space Team
parent
af73bb9bf3
commit
012152e7b6
+73
-50
@@ -14,39 +14,56 @@ import com.intellij.psi.impl.light.LightElement
|
|||||||
import com.intellij.psi.javadoc.PsiDocComment
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
import com.intellij.psi.search.SearchScope
|
import com.intellij.psi.search.SearchScope
|
||||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.isValid
|
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||||
|
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.psiSafe
|
import org.jetbrains.kotlin.analysis.api.symbols.psiSafe
|
||||||
|
import org.jetbrains.kotlin.analysis.api.symbols.sourcePsiSafe
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtErrorType
|
import org.jetbrains.kotlin.analysis.api.types.KtErrorType
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
|
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
|
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
|
||||||
|
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||||
import org.jetbrains.kotlin.asJava.classes.KotlinSuperTypeListBuilder
|
import org.jetbrains.kotlin.asJava.classes.KotlinSuperTypeListBuilder
|
||||||
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.classes.lazyPub
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
|
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.basicIsEquivalentTo
|
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.invalidAccess
|
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.mapType
|
|
||||||
import org.jetbrains.kotlin.name.StandardClassIds
|
import org.jetbrains.kotlin.name.StandardClassIds
|
||||||
import org.jetbrains.kotlin.psi.KtTypeParameter
|
import org.jetbrains.kotlin.psi.KtTypeParameter
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
context(KtAnalysisSession)
|
internal class SymbolLightTypeParameter private constructor(
|
||||||
internal class SymbolLightTypeParameter(
|
|
||||||
private val parent: SymbolLightTypeParameterList,
|
private val parent: SymbolLightTypeParameterList,
|
||||||
private val index: Int,
|
private val index: Int,
|
||||||
private val typeParameterSymbol: KtTypeParameterSymbol
|
private val typeParameterSymbolPointer: KtSymbolPointer<KtTypeParameterSymbol>,
|
||||||
|
private val typeParameterDeclaration: KtTypeParameter?,
|
||||||
|
override val kotlinOrigin: KtTypeParameter?,
|
||||||
) : LightElement(parent.manager, KotlinLanguage.INSTANCE), PsiTypeParameter,
|
) : LightElement(parent.manager, KotlinLanguage.INSTANCE), PsiTypeParameter,
|
||||||
KtLightDeclaration<KtTypeParameter, PsiTypeParameter> {
|
KtLightDeclaration<KtTypeParameter, PsiTypeParameter> {
|
||||||
|
|
||||||
override val givenAnnotations: List<KtLightAbstractAnnotation>? get() = invalidAccess()
|
constructor(parent: SymbolLightTypeParameterList, index: Int, typeParameterSymbol: KtTypeParameterSymbol) : this(
|
||||||
|
parent = parent,
|
||||||
|
index = index,
|
||||||
|
typeParameterSymbolPointer = typeParameterSymbol.createPointer(),
|
||||||
|
typeParameterDeclaration = typeParameterSymbol.sourcePsiSafe(),
|
||||||
|
kotlinOrigin = typeParameterSymbol.psiSafe(),
|
||||||
|
)
|
||||||
|
|
||||||
override val kotlinOrigin: KtTypeParameter? = typeParameterSymbol.psiSafe()
|
private val ktModule: KtModule get() = parent.ktModule
|
||||||
|
|
||||||
override fun copy(): PsiElement =
|
private inline fun <T> withTypeParameterSymbol(crossinline action: KtAnalysisSession.(KtTypeParameterSymbol) -> T): T =
|
||||||
SymbolLightTypeParameter(parent, index, typeParameterSymbol)
|
typeParameterSymbolPointer.withSymbol(ktModule, action)
|
||||||
|
|
||||||
|
override val givenAnnotations: List<KtLightAbstractAnnotation> get() = invalidAccess()
|
||||||
|
|
||||||
|
override fun copy(): PsiElement = SymbolLightTypeParameter(
|
||||||
|
parent,
|
||||||
|
index,
|
||||||
|
typeParameterSymbolPointer,
|
||||||
|
typeParameterDeclaration,
|
||||||
|
kotlinOrigin,
|
||||||
|
)
|
||||||
|
|
||||||
override fun accept(visitor: PsiElementVisitor) {
|
override fun accept(visitor: PsiElementVisitor) {
|
||||||
if (visitor is JavaElementVisitor) {
|
if (visitor is JavaElementVisitor) {
|
||||||
@@ -57,33 +74,33 @@ internal class SymbolLightTypeParameter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val _extendsList: PsiReferenceList by lazyPub {
|
private val _extendsList: PsiReferenceList by lazyPub {
|
||||||
|
|
||||||
val listBuilder = KotlinSuperTypeListBuilder(
|
val listBuilder = KotlinSuperTypeListBuilder(
|
||||||
kotlinOrigin = null,
|
kotlinOrigin = null,
|
||||||
manager = manager,
|
manager = manager,
|
||||||
language = language,
|
language = language,
|
||||||
role = PsiReferenceList.Role.EXTENDS_LIST
|
role = PsiReferenceList.Role.EXTENDS_LIST
|
||||||
)
|
)
|
||||||
typeParameterSymbol.upperBounds
|
|
||||||
.filter { type ->
|
withTypeParameterSymbol { typeParameterSymbol ->
|
||||||
when (type) {
|
typeParameterSymbol.upperBounds
|
||||||
is KtNonErrorClassType -> type.classId != StandardClassIds.Any
|
.filter { type ->
|
||||||
is KtErrorType -> false
|
when (type) {
|
||||||
else -> true
|
is KtNonErrorClassType -> type.classId != StandardClassIds.Any
|
||||||
|
is KtErrorType -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.mapNotNull {
|
||||||
.mapNotNull {
|
mapType(it, this@SymbolLightTypeParameter, KtTypeMappingMode.GENERIC_ARGUMENT)
|
||||||
mapType(it, this@SymbolLightTypeParameter, KtTypeMappingMode.GENERIC_ARGUMENT)
|
}
|
||||||
}
|
.forEach { listBuilder.addReference(it) }
|
||||||
.forEach { listBuilder.addReference(it) }
|
}
|
||||||
|
|
||||||
listBuilder
|
listBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getExtendsList(): PsiReferenceList = _extendsList
|
override fun getExtendsList(): PsiReferenceList = _extendsList
|
||||||
|
override fun getExtendsListTypes(): Array<PsiClassType> = PsiClassImplUtil.getExtendsListTypes(this)
|
||||||
override fun getExtendsListTypes(): Array<PsiClassType> =
|
|
||||||
PsiClassImplUtil.getExtendsListTypes(this)
|
|
||||||
|
|
||||||
//PsiClass simple implementation
|
//PsiClass simple implementation
|
||||||
override fun getImplementsList(): PsiReferenceList? = null
|
override fun getImplementsList(): PsiReferenceList? = null
|
||||||
@@ -100,12 +117,10 @@ internal class SymbolLightTypeParameter(
|
|||||||
override fun findFieldByName(name: String?, checkBases: Boolean): PsiField? = null
|
override fun findFieldByName(name: String?, checkBases: Boolean): PsiField? = null
|
||||||
override fun findMethodBySignature(patternMethod: PsiMethod?, checkBases: Boolean): PsiMethod? = null
|
override fun findMethodBySignature(patternMethod: PsiMethod?, checkBases: Boolean): PsiMethod? = null
|
||||||
override fun findMethodsBySignature(patternMethod: PsiMethod?, checkBases: Boolean): Array<PsiMethod> = PsiMethod.EMPTY_ARRAY
|
override fun findMethodsBySignature(patternMethod: PsiMethod?, checkBases: Boolean): Array<PsiMethod> = PsiMethod.EMPTY_ARRAY
|
||||||
override fun findMethodsAndTheirSubstitutorsByName(name: String?, checkBases: Boolean)
|
override fun findMethodsAndTheirSubstitutorsByName(name: String?, checkBases: Boolean): List<Pair<PsiMethod, PsiSubstitutor>> =
|
||||||
: MutableList<Pair<PsiMethod, PsiSubstitutor>> = mutableListOf()
|
emptyList()
|
||||||
|
|
||||||
override fun getAllMethodsAndTheirSubstitutors()
|
|
||||||
: MutableList<Pair<PsiMethod, PsiSubstitutor>> = mutableListOf()
|
|
||||||
|
|
||||||
|
override fun getAllMethodsAndTheirSubstitutors(): List<Pair<PsiMethod, PsiSubstitutor>> = emptyList()
|
||||||
override fun findInnerClassByName(name: String?, checkBases: Boolean): PsiClass? = null
|
override fun findInnerClassByName(name: String?, checkBases: Boolean): PsiClass? = null
|
||||||
override fun getLBrace(): PsiElement? = null
|
override fun getLBrace(): PsiElement? = null
|
||||||
override fun getRBrace(): PsiElement? = null
|
override fun getRBrace(): PsiElement? = null
|
||||||
@@ -117,7 +132,7 @@ internal class SymbolLightTypeParameter(
|
|||||||
override fun getNameIdentifier(): PsiIdentifier? = null
|
override fun getNameIdentifier(): PsiIdentifier? = null
|
||||||
override fun getModifierList(): PsiModifierList? = null
|
override fun getModifierList(): PsiModifierList? = null
|
||||||
override fun hasModifierProperty(name: String): Boolean = false
|
override fun hasModifierProperty(name: String): Boolean = false
|
||||||
override fun getOwner(): PsiTypeParameterListOwner? = parent.owner
|
override fun getOwner(): PsiTypeParameterListOwner = parent.owner
|
||||||
override fun getParent(): PsiElement = parent
|
override fun getParent(): PsiElement = parent
|
||||||
override fun getAnnotations(): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY
|
override fun getAnnotations(): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY
|
||||||
override fun getContainingClass(): PsiClass? = null
|
override fun getContainingClass(): PsiClass? = null
|
||||||
@@ -138,34 +153,42 @@ internal class SymbolLightTypeParameter(
|
|||||||
override fun addAnnotation(qualifiedName: String): PsiAnnotation = cannotModify()
|
override fun addAnnotation(qualifiedName: String): PsiAnnotation = cannotModify()
|
||||||
//End of PsiClass simple implementation
|
//End of PsiClass simple implementation
|
||||||
|
|
||||||
override fun getText(): String = kotlinOrigin?.text ?: ""
|
private val _name: String by lazy {
|
||||||
override fun getName(): String? = typeParameterSymbol.name.asString()
|
typeParameterDeclaration?.name ?: withTypeParameterSymbol { it.name.asString() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getName(): String = _name
|
||||||
|
|
||||||
override fun getIndex(): Int = index
|
override fun getIndex(): Int = index
|
||||||
override fun getApplicableAnnotations(): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY //TODO
|
override fun getApplicableAnnotations(): Array<PsiAnnotation> = PsiAnnotation.EMPTY_ARRAY //TODO
|
||||||
|
|
||||||
override fun toString(): String = "SymbolLightTypeParameter:$name"
|
override fun toString(): String = "SymbolLightTypeParameter:$name"
|
||||||
|
|
||||||
override fun getNavigationElement(): PsiElement =
|
override fun getNavigationElement(): PsiElement = kotlinOrigin ?: parent.navigationElement
|
||||||
kotlinOrigin ?: parent.navigationElement
|
|
||||||
|
|
||||||
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
|
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
|
||||||
|
|
||||||
override fun getUseScope(): SearchScope =
|
override fun getUseScope(): SearchScope = kotlinOrigin?.useScope ?: parent.useScope
|
||||||
kotlinOrigin?.useScope ?: parent.useScope
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean {
|
||||||
this === other ||
|
if (this === other) return true
|
||||||
(other is SymbolLightTypeParameter && index == other.index && typeParameterSymbol == other.typeParameterSymbol)
|
if (other !is SymbolLightTypeParameter || other.ktModule != ktModule || other.index != index) return false
|
||||||
|
if (typeParameterDeclaration != null) {
|
||||||
|
return other.typeParameterDeclaration == typeParameterDeclaration
|
||||||
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int = typeParameterSymbol.hashCode() + index
|
return other.typeParameterDeclaration == null &&
|
||||||
|
other.kotlinOrigin == kotlinOrigin &&
|
||||||
|
compareSymbolPointers(ktModule, typeParameterSymbolPointer, other.typeParameterSymbolPointer) &&
|
||||||
|
other.parent == parent
|
||||||
|
}
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement): Boolean =
|
override fun hashCode(): Int = typeParameterDeclaration?.hashCode() ?: name.hashCode()
|
||||||
basicIsEquivalentTo(this, another)
|
override fun isEquivalentTo(another: PsiElement): Boolean = basicIsEquivalentTo(this, another)
|
||||||
|
|
||||||
override fun getTextRange(): TextRange? = kotlinOrigin?.textRange
|
override fun getText(): String? = typeParameterDeclaration?.text
|
||||||
|
override fun getTextRange(): TextRange? = typeParameterDeclaration?.textRange
|
||||||
override fun getContainingFile(): PsiFile = parent.containingFile
|
override fun getContainingFile(): PsiFile = parent.containingFile
|
||||||
override fun getTextOffset(): Int = kotlinOrigin?.startOffset ?: super.getTextOffset()
|
override fun getTextOffset(): Int = typeParameterDeclaration?.startOffset ?: -1
|
||||||
override fun getStartOffsetInParent(): Int = kotlinOrigin?.startOffsetInParent ?: super.getStartOffsetInParent()
|
override fun getStartOffsetInParent(): Int = typeParameterDeclaration?.startOffsetInParent ?: -1
|
||||||
|
|
||||||
override fun isValid(): Boolean = super.isValid() && typeParameterSymbol.isValid()
|
override fun isValid(): Boolean = super.isValid() && typeParameterDeclaration?.isValid ?: typeParameterSymbolPointer.isValid(ktModule)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user