[FIR IDE] Add symbol kind to Kt accessor symbols

This commit is contained in:
Igor Yakovlev
2021-03-24 17:08:24 +01:00
parent ff9edb8776
commit a428cc6eb4
9 changed files with 15 additions and 24 deletions
@@ -13,7 +13,8 @@ sealed class KtPropertyAccessorSymbol : KtCallableSymbol(),
KtPossibleMemberSymbol,
KtSymbolWithModality,
KtSymbolWithVisibility,
KtAnnotatedSymbol {
KtAnnotatedSymbol,
KtSymbolWithKind {
final override val callableIdIfNonLocal: CallableId? get() = null
@@ -22,7 +23,7 @@ sealed class KtPropertyAccessorSymbol : KtCallableSymbol(),
abstract val isOverride: Boolean
abstract val hasBody: Boolean
abstract val symbolKind: KtSymbolKind
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.ACCESSOR
abstract override fun createPointer(): KtSymbolPointer<KtPropertyAccessorSymbol>
}
@@ -15,6 +15,6 @@ interface KtSymbolWithKind : KtSymbol {
}
enum class KtSymbolKind {
TOP_LEVEL, MEMBER, LOCAL
TOP_LEVEL, MEMBER, LOCAL, ACCESSOR
}
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolKind
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
internal class KtFirSymbolContainingDeclarationProvider(
@@ -46,9 +47,13 @@ internal class KtFirSymbolContainingDeclarationProvider(
private fun getContainingDeclarationForKotlinInSourceSymbol(symbol: KtSymbolWithKind): KtSymbolWithKind = with(analysisSession) {
require(symbol.origin == KtSymbolOrigin.SOURCE || symbol.origin == KtSymbolOrigin.SOURCE_MEMBER_GENERATED)
val psi = symbol.getPsi()
check(psi is KtDeclaration) { "PSI of kotlin declaration should be KtDeclaration" }
val psi = when (val psi = symbol.getPsi()) {
is KtDeclaration -> psi
is KtObjectLiteralExpression -> psi.objectDeclaration
else -> error { "PSI of kotlin declaration should be KtDeclaration but was ${psi::class.simpleName}" }
}
val containingDeclaration = when (symbol.origin) {
KtSymbolOrigin.SOURCE -> psi.parentOfType()
?: error("Containing declaration should present for non-toplevel declaration")
@@ -56,7 +61,6 @@ internal class KtFirSymbolContainingDeclarationProvider(
else -> error("Unsupported declaration origin ${symbol.origin}")
}
return with(analysisSession) {
val containingSymbol = containingDeclaration.getSymbol()
check(containingSymbol is KtSymbolWithKind)
@@ -107,6 +107,7 @@ internal class KtFirFunctionSymbol(
fir.createSignature()
)
}
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors fun is not supported yet")
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(
callableIdIfNonLocal?.toString() ?: name.asString()
)
@@ -118,6 +118,7 @@ internal class KtFirKotlinPropertySymbol(
fir.createSignature()
)
}
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors is not supported yet")
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(name.asString())
}
}
@@ -46,14 +46,6 @@ internal class KtFirPropertyGetterSymbol(
override val isOverride: Boolean get() = firRef.withFir { it.isOverride }
override val hasBody: Boolean get() = firRef.withFir { it.body != null }
override val symbolKind: KtSymbolKind
get() = firRef.withFir { fir ->
when (fir.symbol.callableId.classId) {
null -> KtSymbolKind.TOP_LEVEL
else -> KtSymbolKind.MEMBER
}
}
override val annotatedType: KtTypeAndAnnotations by cached {
firRef.returnTypeAndAnnotations(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, builder)
}
@@ -62,14 +62,6 @@ internal class KtFirPropertySetterSymbol(
firRef.returnTypeAndAnnotations(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, builder)
}
override val symbolKind: KtSymbolKind
get() = firRef.withFir { fir ->
when (fir.symbol.callableId.classId) {
null -> KtSymbolKind.TOP_LEVEL
else -> KtSymbolKind.MEMBER
}
}
override val dispatchType: KtType? by cached {
firRef.dispatchReceiverTypeAndAnnotations(builder)
}
@@ -41,7 +41,7 @@ KtFirPropertyGetterSymbol:
isOverride: false
modality: FINAL
origin: SOURCE
symbolKind: TOP_LEVEL
symbolKind: ACCESSOR
visibility: Public
KtFirKotlinPropertySymbol:
@@ -39,7 +39,7 @@ KtFirPropertyGetterSymbol:
isOverride: false
modality: FINAL
origin: SOURCE
symbolKind: TOP_LEVEL
symbolKind: ACCESSOR
visibility: Public
KtFirKotlinPropertySymbol: