Analysis API FIR/FE1.0: fix backing field rendering & resolving
This commit is contained in:
+4
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.base.KtFe10Symbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescSyntheticFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.KtFe10DescSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.classId
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getSymbolDescriptor
|
||||
@@ -23,6 +24,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.getRe
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.PublicApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.nameOrAnonymous
|
||||
@@ -119,13 +121,14 @@ internal class KtFe10TypeProvider(
|
||||
return TypeUtils.getAllSupertypes(type.type).map { it.toKtType(analysisContext) }
|
||||
}
|
||||
|
||||
override fun getDispatchReceiverType(symbol: KtPossibleMemberSymbol): KtType? {
|
||||
override fun getDispatchReceiverType(symbol: KtCallableSymbol): KtType? {
|
||||
assertIsValidAndAccessible()
|
||||
require(symbol is KtFe10Symbol)
|
||||
|
||||
val descriptor = when (symbol) {
|
||||
is KtFe10DescSymbol<*> -> symbol.descriptor as? CallableDescriptor
|
||||
is KtFe10PsiSymbol<*, *> -> symbol.descriptor as? CallableDescriptor
|
||||
is KtFe10DescSyntheticFieldSymbol -> symbol.descriptor
|
||||
else -> error("No callable descriptor on $symbol")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
|
||||
internal class KtFe10DescSyntheticFieldSymbol(
|
||||
private val descriptor: SyntheticFieldDescriptor,
|
||||
val descriptor: SyntheticFieldDescriptor,
|
||||
override val analysisContext: Fe10AnalysisContext
|
||||
) : KtBackingFieldSymbol(), KtFe10Symbol {
|
||||
override val owningProperty: KtKotlinPropertySymbol
|
||||
|
||||
+1
@@ -389,6 +389,7 @@ internal fun getSymbolDescriptor(symbol: KtSymbol): DeclarationDescriptor? {
|
||||
return when (symbol) {
|
||||
is KtFe10DescSymbol<*> -> symbol.descriptor
|
||||
is KtFe10PsiSymbol<*, *> -> symbol.descriptor
|
||||
is KtFe10DescSyntheticFieldSymbol -> symbol.descriptor
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
@@ -279,6 +280,7 @@ internal class KtFe10Renderer(
|
||||
|
||||
private fun KtFe10RendererConsumer.renderCallable(descriptor: CallableDescriptor) {
|
||||
when (descriptor) {
|
||||
is SyntheticFieldDescriptor -> renderSyntheticFieldDescriptor()
|
||||
is PropertyGetterDescriptor -> renderPropertyAccessor(descriptor)
|
||||
is PropertySetterDescriptor -> renderPropertyAccessor(descriptor)
|
||||
is PropertyDescriptor -> renderProperty(descriptor)
|
||||
@@ -290,6 +292,10 @@ internal class KtFe10Renderer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtFe10RendererConsumer.renderSyntheticFieldDescriptor() {
|
||||
append("field")
|
||||
}
|
||||
|
||||
private fun KtFe10RendererConsumer.renderPropertyAccessor(descriptor: PropertyAccessorDescriptor) {
|
||||
if (options.renderDeclarationHeader) {
|
||||
renderAnnotations(descriptor)
|
||||
@@ -440,7 +446,12 @@ internal class KtFe10Renderer(
|
||||
return
|
||||
}
|
||||
val isSingleLineAnnotations = declaration is ValueParameterDescriptor || declaration is TypeParameterDescriptor
|
||||
renderFe10Annotations(declaration.annotations, isSingleLineAnnotations, predicate)
|
||||
renderFe10Annotations(
|
||||
declaration.annotations,
|
||||
isSingleLineAnnotations,
|
||||
renderAnnotationWithShortNames = options.typeRendererOptions.shortQualifiedNames,
|
||||
predicate
|
||||
)
|
||||
}
|
||||
|
||||
private fun KtFe10RendererConsumer.renderModifiers(descriptor: DeclarationDescriptor) {
|
||||
|
||||
+1
-1
@@ -304,7 +304,7 @@ internal class KtSymbolByFirBuilder private constructor(
|
||||
|
||||
fun buildBackingFieldSymbol(fir: FirBackingField): KtFirBackingFieldSymbol {
|
||||
return backingFieldCache.cache(fir) {
|
||||
KtFirBackingFieldSymbol(fir.propertySymbol.fir, resolveState, token, this@KtSymbolByFirBuilder)
|
||||
KtFirBackingFieldSymbol(fir, resolveState, token, this@KtSymbolByFirBuilder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -35,10 +35,16 @@ internal class FirIdeRenderer private constructor(
|
||||
is FirConstructor -> renderConstructor(declaration)
|
||||
is FirPropertyAccessor -> renderPropertyAccessor(declaration)
|
||||
is FirSimpleFunction -> renderSimpleFunction(declaration)
|
||||
is FirBackingField -> renderBackingField()
|
||||
is FirEnumEntry -> renderEnumEntry(declaration)
|
||||
is FirProperty -> renderProperty(declaration)
|
||||
is FirValueParameter -> renderValueParameter(declaration)
|
||||
is FirField -> TODO()
|
||||
is FirField -> renderPropertyOrField(declaration)
|
||||
is FirErrorFunction -> error("FirErrorFunction should not be rendered")
|
||||
is FirErrorProperty -> error("FirErrorProperty should not be rendered")
|
||||
is FirAnonymousInitializer -> error("FirAnonymousInitializer should not be rendered")
|
||||
is FirFile -> error("FirFile should not be rendered")
|
||||
is FirTypeParameter -> renderTypeParameter(declaration)
|
||||
is FirAnonymousFunction -> TODO()
|
||||
is FirErrorFunction -> Unit
|
||||
is FirErrorProperty -> Unit
|
||||
@@ -46,6 +52,10 @@ internal class FirIdeRenderer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun PrettyPrinter.renderBackingField() {
|
||||
append("field")
|
||||
}
|
||||
|
||||
private fun PrettyPrinter.renderProperty(property: FirProperty) {
|
||||
renderAnnotationsAndModifiers(property)
|
||||
renderValVarPrefix(property)
|
||||
|
||||
+1
@@ -69,6 +69,7 @@ internal abstract class FirIdeRendererBase(
|
||||
is FirTypeParameter -> declaration.name
|
||||
is FirTypeAlias -> declaration.name
|
||||
is FirEnumEntry -> declaration.name
|
||||
is FirField -> declaration.name
|
||||
else -> TODO("Unexpected declaration ${declaration::class.qualifiedName}")
|
||||
}
|
||||
append(name.render())
|
||||
|
||||
+16
-12
@@ -5,33 +5,38 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.symbols
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirModuleResolveState
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirBackingFieldSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firRef
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirModuleResolveState
|
||||
import org.jetbrains.kotlin.fir.declarations.FirBackingField
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
|
||||
internal class KtFirBackingFieldSymbol(
|
||||
propertyFir: FirProperty,
|
||||
fir: FirBackingField,
|
||||
resolveState: FirModuleResolveState,
|
||||
override val token: ValidityToken,
|
||||
private val builder: KtSymbolByFirBuilder
|
||||
) : KtBackingFieldSymbol() {
|
||||
private val propertyFirRef = firRef(propertyFir, resolveState)
|
||||
) : KtBackingFieldSymbol(), KtFirSymbol<FirBackingField> {
|
||||
override val firRef = firRef(fir, resolveState)
|
||||
|
||||
override val origin: KtSymbolOrigin
|
||||
get() = withValidityAssertion { super<KtBackingFieldSymbol>.origin }
|
||||
|
||||
override val returnType: KtType by cached {
|
||||
propertyFirRef.returnType(FirResolvePhase.TYPES, builder)
|
||||
firRef.returnType(FirResolvePhase.TYPES, builder)
|
||||
}
|
||||
|
||||
override val owningProperty: KtKotlinPropertySymbol by propertyFirRef.withFirAndCache { fir ->
|
||||
builder.buildSymbol(fir) as KtKotlinPropertySymbol
|
||||
override val owningProperty: KtKotlinPropertySymbol by firRef.withFirAndCache { fir ->
|
||||
builder.buildSymbol(fir.propertySymbol.fir) as KtKotlinPropertySymbol
|
||||
}
|
||||
|
||||
override fun createPointer(): KtSymbolPointer<KtBackingFieldSymbol> {
|
||||
@@ -44,11 +49,10 @@ internal class KtFirBackingFieldSymbol(
|
||||
|
||||
other as KtFirBackingFieldSymbol
|
||||
|
||||
if (this.token != other.token) return false
|
||||
return this.propertyFirRef == other.propertyFirRef
|
||||
return this.firRef == other.firRef
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return propertyFirRef.hashCode() * 31 + token.hashCode()
|
||||
return firRef.hashCode() * 31 + token.hashCode()
|
||||
}
|
||||
}
|
||||
+35
-20
@@ -237,30 +237,45 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui
|
||||
return firDeclarationToResolve
|
||||
}
|
||||
}
|
||||
if (firDeclarationToResolve is FirSyntheticPropertyAccessor) {
|
||||
lazyResolveDeclaration(
|
||||
firDeclarationToResolve.delegate,
|
||||
moduleFileCache,
|
||||
scopeSession,
|
||||
toPhase,
|
||||
checkPCE,
|
||||
skipLocalDeclaration
|
||||
)
|
||||
return firDeclarationToResolve
|
||||
when (firDeclarationToResolve) {
|
||||
is FirSyntheticPropertyAccessor -> {
|
||||
lazyResolveDeclaration(
|
||||
firDeclarationToResolve.delegate,
|
||||
moduleFileCache,
|
||||
scopeSession,
|
||||
toPhase,
|
||||
checkPCE,
|
||||
skipLocalDeclaration
|
||||
)
|
||||
return firDeclarationToResolve
|
||||
}
|
||||
|
||||
is FirBackingField -> {
|
||||
lazyResolveDeclaration(
|
||||
firDeclarationToResolve.propertySymbol.fir,
|
||||
moduleFileCache,
|
||||
scopeSession,
|
||||
toPhase,
|
||||
checkPCE,
|
||||
skipLocalDeclaration
|
||||
)
|
||||
}
|
||||
|
||||
is FirFile -> {
|
||||
lazyResolveFileDeclaration(
|
||||
firFile = firDeclarationToResolve,
|
||||
moduleFileCache = moduleFileCache,
|
||||
toPhase = toPhase,
|
||||
scopeSession = scopeSession,
|
||||
checkPCE = checkPCE,
|
||||
)
|
||||
return firDeclarationToResolve
|
||||
}
|
||||
}
|
||||
|
||||
if (!firDeclarationToResolve.isValidForResolve()) return firDeclarationToResolve
|
||||
if (firDeclarationToResolve.resolvePhase >= toPhase) return firDeclarationToResolve
|
||||
|
||||
if (firDeclarationToResolve is FirFile) {
|
||||
lazyResolveFileDeclaration(
|
||||
firFile = firDeclarationToResolve,
|
||||
moduleFileCache = moduleFileCache,
|
||||
toPhase = toPhase,
|
||||
scopeSession = scopeSession,
|
||||
checkPCE = checkPCE,
|
||||
)
|
||||
return firDeclarationToResolve
|
||||
}
|
||||
|
||||
val requestedDeclarationDesignation = firDeclarationToResolve.tryCollectDesignationWithFile()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user