FIR IDE: do not require containing declaration for getting overridden symbols

This commit is contained in:
Ilya Kirillov
2021-02-02 18:43:04 +01:00
parent 0fbb5c60c9
commit aed728c4d8
3 changed files with 19 additions and 0 deletions
@@ -56,9 +56,13 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
abstract fun createContextDependentCopy(originalKtFile: KtFile, fakeKtElement: KtElement): KtAnalysisSession
//TODO get rid of it
fun KtCallableSymbol.getOverriddenSymbols(containingDeclaration: KtClassOrObjectSymbol): List<KtCallableSymbol> =
symbolDeclarationOverridesProvider.getOverriddenSymbols(this, containingDeclaration)
fun KtCallableSymbol.getOverriddenSymbols(): List<KtCallableSymbol> =
symbolDeclarationOverridesProvider.getOverriddenSymbols(this)
fun KtCallableSymbol.getIntersectionOverriddenSymbols(): Collection<KtCallableSymbol> =
symbolDeclarationOverridesProvider.getIntersectionOverriddenSymbols(this)
@@ -75,6 +79,8 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
infix fun KtType.isSubTypeOf(superType: KtType): Boolean = subtypingComponent.isSubTypeOf(this, superType)
infix fun KtType.isNotSubTypeOf(superType: KtType): Boolean = !subtypingComponent.isSubTypeOf(this, superType)
fun PsiElement.getExpectedType(): KtType? = expressionTypeProvider.getExpectedType(this)
val builtinTypes: KtBuiltinTypes get() = typeProvider.builtinTypes
@@ -18,6 +18,13 @@ abstract class KtSymbolDeclarationOverridesProvider : KtAnalysisSessionComponent
containingDeclaration: KtClassOrObjectSymbol
): List<KtCallableSymbol>
/**
* Returns symbols that overridden by requested
*/
abstract fun <T : KtSymbol> getOverriddenSymbols(
callableSymbol: T,
): List<KtCallableSymbol>
/**
* If [symbol] origin is [org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbolOrigin.INTERSECTION_OVERRIDE]
* Then returns the symbols which [symbol] overrides, otherwise empty collection
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirClassOrObjectSymbol
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
internal class KtFirSymbolDeclarationOverridesProvider(
override val analysisSession: KtFirAnalysisSession,
@@ -70,6 +71,11 @@ internal class KtFirSymbolDeclarationOverridesProvider(
}
}
override fun <T : KtSymbol> getOverriddenSymbols(callableSymbol: T): List<KtCallableSymbol> = with(analysisSession) {
val containingDeclaration = (callableSymbol as? KtSymbolWithKind)?.getContainingSymbol() as? KtClassOrObjectSymbol ?: return emptyList()
getOverriddenSymbols(callableSymbol, containingDeclaration)
}
override fun getIntersectionOverriddenSymbols(symbol: KtCallableSymbol): Collection<KtCallableSymbol> {
require(symbol is KtFirSymbol<*>)
if (symbol.origin != KtSymbolOrigin.INTERSECTION_OVERRIDE) return emptyList()