From 654ed3caf6cd6dda5bf13ab477426af80bf85e1d Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Thu, 19 Aug 2021 23:30:26 +0300 Subject: [PATCH] [FIR] Add propertySymbol to property accessors --- .../deserialization/FirMemberDeserializer.kt | 207 +++++++++++------- .../converter/DeclarationsConverter.kt | 9 +- .../fir/lightTree/fir/ValueParameter.kt | 6 +- .../kotlin/fir/builder/RawFirBuilder.kt | 23 +- .../kotlin/fir/builder/ConversionUtils.kt | 2 + .../fir/declarations/FirPropertyAccessor.kt | 2 + .../builder/FirPropertyAccessorBuilder.kt | 4 + .../impl/FirPropertyAccessorImpl.kt | 2 + .../impl/FirDefaultPropertyAccessor.kt | 12 +- .../synthetic/FirSyntheticPropertyAccessor.kt | 4 + .../fir/tree/generator/NodeConfigurator.kt | 3 + .../kotlin/fir/tree/generator/Types.kt | 3 + 12 files changed, 188 insertions(+), 89 deletions(-) diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt index 2de0ae55464..f2c7fa2c11f 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* +import org.jetbrains.kotlin.fir.toEffectiveVisibility import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.types.computeTypeAttributes @@ -218,6 +219,111 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { } } + private fun loadPropertyGetter( + proto: ProtoBuf.Property, + classSymbol: FirClassSymbol<*>?, + defaultAccessorFlags: Int, + returnTypeRef: FirTypeRef, + propertySymbol: FirPropertySymbol, + local: FirDeserializationContext, + propertyModality: Modality, + ): FirPropertyAccessor { + val getterFlags = if (proto.hasGetterFlags()) proto.getterFlags else defaultAccessorFlags + val visibility = ProtoEnumFlags.visibility(Flags.VISIBILITY.get(getterFlags)) + val accessorModality = ProtoEnumFlags.modality(Flags.MODALITY.get(getterFlags)) + val effectiveVisibility = visibility.toEffectiveVisibility(classSymbol) + return if (Flags.IS_NOT_DEFAULT.get(getterFlags)) { + buildPropertyAccessor { + moduleData = c.moduleData + origin = FirDeclarationOrigin.Library + this.returnTypeRef = returnTypeRef + resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES + isGetter = true + status = FirResolvedDeclarationStatusImpl(visibility, accessorModality, effectiveVisibility).apply { + isInline = Flags.IS_INLINE_ACCESSOR.get(getterFlags) + isExternal = Flags.IS_EXTERNAL_ACCESSOR.get(getterFlags) + } + this.symbol = FirPropertyAccessorSymbol() + dispatchReceiverType = c.dispatchReceiver + this.propertySymbol = propertySymbol + }.apply { + versionRequirementsTable = c.versionRequirementTable + } + } else { + FirDefaultPropertyGetter( + null, + c.moduleData, + FirDeclarationOrigin.Library, + returnTypeRef, + visibility, + propertySymbol, + propertyModality, + effectiveVisibility + ) + }.apply { + (annotations as MutableList) += + c.annotationDeserializer.loadPropertyGetterAnnotations( + c.containerSource, proto, local.nameResolver, local.typeTable, getterFlags + ) + } + } + + private fun loadPropertySetter( + proto: ProtoBuf.Property, + classProto: ProtoBuf.Class? = null, + classSymbol: FirClassSymbol<*>?, + defaultAccessorFlags: Int, + returnTypeRef: FirTypeRef, + propertySymbol: FirPropertySymbol, + local: FirDeserializationContext, + propertyModality: Modality, + ): FirPropertyAccessor { + val setterFlags = if (proto.hasSetterFlags()) proto.setterFlags else defaultAccessorFlags + val visibility = ProtoEnumFlags.visibility(Flags.VISIBILITY.get(setterFlags)) + val accessorModality = ProtoEnumFlags.modality(Flags.MODALITY.get(setterFlags)) + val effectiveVisibility = visibility.toEffectiveVisibility(classSymbol) + return if (Flags.IS_NOT_DEFAULT.get(setterFlags)) { + buildPropertyAccessor { + moduleData = c.moduleData + origin = FirDeclarationOrigin.Library + this.returnTypeRef = FirImplicitUnitTypeRef(source) + resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES + isGetter = false + status = FirResolvedDeclarationStatusImpl(visibility, accessorModality, effectiveVisibility).apply { + isInline = Flags.IS_INLINE_ACCESSOR.get(setterFlags) + isExternal = Flags.IS_EXTERNAL_ACCESSOR.get(setterFlags) + } + this.symbol = FirPropertyAccessorSymbol() + dispatchReceiverType = c.dispatchReceiver + valueParameters += local.memberDeserializer.valueParameters( + listOf(proto.setterValueParameter), + proto, + AbstractAnnotationDeserializer.CallableKind.PROPERTY_SETTER, + classProto + ) + this.propertySymbol = propertySymbol + }.apply { + versionRequirementsTable = c.versionRequirementTable + } + } else { + FirDefaultPropertySetter( + null, + c.moduleData, + FirDeclarationOrigin.Library, + returnTypeRef, + visibility, + propertySymbol, + propertyModality, + effectiveVisibility + ) + }.apply { + (annotations as MutableList) += + c.annotationDeserializer.loadPropertySetterAnnotations( + c.containerSource, proto, local.nameResolver, local.typeTable, setterFlags + ) + } + } + fun loadProperty( proto: ProtoBuf.Property, classProto: ProtoBuf.Class? = null, @@ -251,82 +357,6 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { val propertyModality = ProtoEnumFlags.modality(Flags.MODALITY.get(flags)) - val getter = if (hasGetter) { - val getterFlags = if (proto.hasGetterFlags()) proto.getterFlags else defaultAccessorFlags - val visibility = ProtoEnumFlags.visibility(Flags.VISIBILITY.get(getterFlags)) - val accessorModality = ProtoEnumFlags.modality(Flags.MODALITY.get(getterFlags)) - val effectiveVisibility = visibility.toEffectiveVisibility(classSymbol) - if (Flags.IS_NOT_DEFAULT.get(getterFlags)) { - buildPropertyAccessor { - moduleData = c.moduleData - origin = FirDeclarationOrigin.Library - this.returnTypeRef = returnTypeRef - resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES - isGetter = true - status = FirResolvedDeclarationStatusImpl(visibility, accessorModality, effectiveVisibility).apply { - isInline = Flags.IS_INLINE_ACCESSOR.get(getterFlags) - isExternal = Flags.IS_EXTERNAL_ACCESSOR.get(getterFlags) - } - this.symbol = FirPropertyAccessorSymbol() - dispatchReceiverType = c.dispatchReceiver - }.apply { - versionRequirementsTable = c.versionRequirementTable - } - } else { - FirDefaultPropertyGetter( - null, c.moduleData, FirDeclarationOrigin.Library, returnTypeRef, visibility, propertyModality, effectiveVisibility - ) - }.apply { - (annotations as MutableList) += - c.annotationDeserializer.loadPropertyGetterAnnotations( - c.containerSource, proto, local.nameResolver, local.typeTable, getterFlags - ) - } - } else { - null - } - - val setter = if (Flags.HAS_SETTER.get(flags)) { - val setterFlags = if (proto.hasSetterFlags()) proto.setterFlags else defaultAccessorFlags - val visibility = ProtoEnumFlags.visibility(Flags.VISIBILITY.get(setterFlags)) - val accessorModality = ProtoEnumFlags.modality(Flags.MODALITY.get(setterFlags)) - val effectiveVisibility = visibility.toEffectiveVisibility(classSymbol) - if (Flags.IS_NOT_DEFAULT.get(setterFlags)) { - buildPropertyAccessor { - moduleData = c.moduleData - origin = FirDeclarationOrigin.Library - this.returnTypeRef = FirImplicitUnitTypeRef(source) - resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES - isGetter = false - status = FirResolvedDeclarationStatusImpl(visibility, accessorModality, effectiveVisibility).apply { - isInline = Flags.IS_INLINE_ACCESSOR.get(setterFlags) - isExternal = Flags.IS_EXTERNAL_ACCESSOR.get(setterFlags) - } - this.symbol = FirPropertyAccessorSymbol() - dispatchReceiverType = c.dispatchReceiver - valueParameters += local.memberDeserializer.valueParameters( - listOf(proto.setterValueParameter), - proto, - AbstractAnnotationDeserializer.CallableKind.PROPERTY_SETTER, - classProto - ) - }.apply { - versionRequirementsTable = c.versionRequirementTable - } - } else { - FirDefaultPropertySetter( - null, c.moduleData, FirDeclarationOrigin.Library, returnTypeRef, visibility, propertyModality, effectiveVisibility - ) - }.apply { - (annotations as MutableList) += - c.annotationDeserializer.loadPropertySetterAnnotations( - c.containerSource, proto, local.nameResolver, local.typeTable, setterFlags - ) - } - } else { - null - } - val isVar = Flags.IS_VAR.get(flags) return buildProperty { moduleData = c.moduleData @@ -362,8 +392,29 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { c.annotationDeserializer.loadPropertyDelegatedFieldAnnotations( c.containerSource, proto, local.nameResolver, local.typeTable ) - this.getter = getter - this.setter = setter + if (hasGetter) { + this.getter = loadPropertyGetter( + proto, + classSymbol, + defaultAccessorFlags, + returnTypeRef, + symbol, + local, + propertyModality + ) + } + if (Flags.HAS_SETTER.get(flags)) { + this.setter = loadPropertySetter( + proto, + classProto, + classSymbol, + defaultAccessorFlags, + returnTypeRef, + symbol, + local, + propertyModality + ) + } this.containerSource = c.containerSource this.initializer = c.constDeserializer.loadConstant(proto, symbol.callableId, c.nameResolver) deprecation = annotations.getDeprecationInfosFromAnnotations(c.session.languageVersionSettings.apiVersion, false) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index f62b178b3a2..a46aa6b943f 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -1130,14 +1130,14 @@ class DeclarationsConverter( isExternal = modifiers.hasExternal() } - val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, modifiers) } + val convertedAccessors = accessors.map { convertGetterOrSetter(it, returnType, propertyVisibility, symbol, modifiers) } this.getter = convertedAccessors.find { it.isGetter } ?: FirDefaultPropertyGetter( property.toFirSourceElement(FirFakeSourceElementKind.DefaultAccessor), moduleData, FirDeclarationOrigin.Source, returnType, - propertyVisibility + propertyVisibility, symbol, ).also { it.status = defaultAccessorStatus() it.initContainingClassAttr() @@ -1150,7 +1150,7 @@ class DeclarationsConverter( moduleData, FirDeclarationOrigin.Source, returnType, - propertyVisibility + propertyVisibility, symbol, ).also { it.status = defaultAccessorStatus() it.initContainingClassAttr() @@ -1252,6 +1252,7 @@ class DeclarationsConverter( getterOrSetter: LighterASTNode, propertyTypeRef: FirTypeRef, propertyVisibility: Visibility, + propertySymbol: FirPropertySymbol, propertyModifiers: Modifier ): FirPropertyAccessor { var modifiers = Modifier() @@ -1299,6 +1300,7 @@ class DeclarationsConverter( FirDeclarationOrigin.Source, propertyTypeRefToUse, accessorVisibility, + propertySymbol, isGetter ) .also { accessor -> @@ -1331,6 +1333,7 @@ class DeclarationsConverter( this.contractDescription = it } context.firFunctionTargets.removeLast() + this.propertySymbol = propertySymbol }.also { target.bind(it) it.initContainingClassAttr() diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt index c21d7ee1705..b436702b8d9 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt @@ -81,14 +81,16 @@ class ValueParameter( moduleData, FirDeclarationOrigin.Source, type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor), - modifiers.getVisibility() + modifiers.getVisibility(), + symbol, ) setter = if (this.isVar) FirDefaultPropertySetter( defaultAccessorSource, moduleData, FirDeclarationOrigin.Source, type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor), - modifiers.getVisibility() + modifiers.getVisibility(), + symbol, ) else null }.apply { if (firValueParameter.isVararg) { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index a50ba96295f..40e917b5711 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -368,6 +368,7 @@ open class RawFirBuilder( private fun KtPropertyAccessor?.toFirPropertyAccessor( property: KtProperty, propertyTypeRef: FirTypeRef, + propertySymbol: FirPropertySymbol, isGetter: Boolean, ): FirPropertyAccessor? { val accessorVisibility = @@ -418,6 +419,7 @@ open class RawFirBuilder( contractDescription?.let { this.contractDescription = it } + this.propertySymbol = propertySymbol }.also { it.initContainingClassAttr() bindFunctionTarget(accessorTarget, it) @@ -435,6 +437,7 @@ open class RawFirBuilder( FirDeclarationOrigin.Source, propertyTypeRefToUse, accessorVisibility, + propertySymbol, isGetter ) .also { @@ -515,14 +518,16 @@ open class RawFirBuilder( baseModuleData, FirDeclarationOrigin.Source, type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor), - visibility + visibility, + symbol, ) setter = if (isMutable) FirDefaultPropertySetter( defaultAccessorSource, baseModuleData, FirDeclarationOrigin.Source, type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor), - visibility + visibility, + symbol, ) else null extractAnnotationsTo(this) @@ -1450,8 +1455,18 @@ open class RawFirBuilder( dispatchReceiverType = currentDispatchReceiverType() extractTypeParametersTo(this, symbol) withCapturedTypeParameters(true, this.typeParameters) { - getter = this@toFirProperty.getter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = true) - setter = this@toFirProperty.setter.toFirPropertyAccessor(this@toFirProperty, propertyType, isGetter = false) + getter = this@toFirProperty.getter.toFirPropertyAccessor( + this@toFirProperty, + propertyType, + propertySymbol = symbol, + isGetter = true + ) + setter = this@toFirProperty.setter.toFirPropertyAccessor( + this@toFirProperty, + propertyType, + propertySymbol = symbol, + isGetter = false + ) status = FirDeclarationStatusImpl(visibility, modality).apply { isExpect = hasExpectModifier() || this@RawFirBuilder.context.containerIsExpect diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index d8a5b74d00e..b095573fc79 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -442,6 +442,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( if (annotations != null) { this.annotations.addAll(annotations) } + propertySymbol = this@generateAccessorsByDelegate.symbol }.also { returnTarget.bind(it) } @@ -495,6 +496,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( if (annotations != null) { this.annotations.addAll(annotations) } + propertySymbol = this@generateAccessorsByDelegate.symbol } } } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt index a9de4405540..eb9a3368302 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirPropertyAccessor.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -40,6 +41,7 @@ abstract class FirPropertyAccessor : FirFunction(), FirContractDescriptionOwner, abstract override val body: FirBlock? abstract override val contractDescription: FirContractDescription abstract override val symbol: FirPropertyAccessorSymbol + abstract val propertySymbol: FirPropertySymbol? abstract val isGetter: Boolean abstract val isSetter: Boolean abstract override val annotations: List diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt index 1196d51bf5c..873b8aad3b1 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyAccessorBuilder.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.visitors.* @@ -54,6 +55,7 @@ class FirPropertyAccessorBuilder : FirFunctionBuilder, FirAnnotationContainerBui override var body: FirBlock? = null var contractDescription: FirContractDescription = FirEmptyContractDescription lateinit var symbol: FirPropertyAccessorSymbol + var propertySymbol: FirPropertySymbol? = null var isGetter: Boolean by kotlin.properties.Delegates.notNull() override val annotations: MutableList = mutableListOf() val typeParameters: MutableList = mutableListOf() @@ -75,6 +77,7 @@ class FirPropertyAccessorBuilder : FirFunctionBuilder, FirAnnotationContainerBui body, contractDescription, symbol, + propertySymbol, isGetter, annotations, typeParameters, @@ -111,6 +114,7 @@ inline fun buildPropertyAccessorCopy(original: FirPropertyAccessor, init: FirPro copyBuilder.body = original.body copyBuilder.contractDescription = original.contractDescription copyBuilder.symbol = original.symbol + copyBuilder.propertySymbol = original.propertySymbol copyBuilder.isGetter = original.isGetter copyBuilder.annotations.addAll(original.annotations) copyBuilder.typeParameters.addAll(original.typeParameters) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt index b094dda47ae..e86c30bcd22 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -48,6 +49,7 @@ open class FirPropertyAccessorImpl @FirImplementationDetail constructor( override var body: FirBlock?, override var contractDescription: FirContractDescription, override val symbol: FirPropertyAccessorSymbol, + override val propertySymbol: FirPropertySymbol?, override val isGetter: Boolean, override val annotations: MutableList, override val typeParameters: MutableList, diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt index edae05e1d51..ab514dca0ce 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.builder.buildDefaultSetterValueParameter import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef @@ -28,6 +29,7 @@ abstract class FirDefaultPropertyAccessor( origin: FirDeclarationOrigin, propertyTypeRef: FirTypeRef, valueParameters: MutableList, + propertySymbol: FirPropertySymbol, isGetter: Boolean, visibility: Visibility, modality: Modality = Modality.FINAL, @@ -51,6 +53,7 @@ abstract class FirDefaultPropertyAccessor( body = null, contractDescription = FirEmptyContractDescription, symbol, + propertySymbol, isGetter, annotations = mutableListOf(), typeParameters = mutableListOf(), @@ -70,12 +73,13 @@ abstract class FirDefaultPropertyAccessor( origin: FirDeclarationOrigin, propertyTypeRef: FirTypeRef, visibility: Visibility, + propertySymbol: FirPropertySymbol, isGetter: Boolean ): FirDefaultPropertyAccessor { return if (isGetter) { - FirDefaultPropertyGetter(source, moduleData, origin, propertyTypeRef, visibility, Modality.FINAL) + FirDefaultPropertyGetter(source, moduleData, origin, propertyTypeRef, visibility, propertySymbol, Modality.FINAL) } else { - FirDefaultPropertySetter(source, moduleData, origin, propertyTypeRef, visibility, Modality.FINAL) + FirDefaultPropertySetter(source, moduleData, origin, propertyTypeRef, visibility, propertySymbol, Modality.FINAL) } } } @@ -87,6 +91,7 @@ class FirDefaultPropertyGetter( origin: FirDeclarationOrigin, propertyTypeRef: FirTypeRef, visibility: Visibility, + propertySymbol: FirPropertySymbol, modality: Modality = Modality.FINAL, effectiveVisibility: EffectiveVisibility? = null, symbol: FirPropertyAccessorSymbol = FirPropertyAccessorSymbol() @@ -96,6 +101,7 @@ class FirDefaultPropertyGetter( origin, propertyTypeRef, valueParameters = mutableListOf(), + propertySymbol, isGetter = true, visibility = visibility, modality = modality, @@ -109,6 +115,7 @@ class FirDefaultPropertySetter( origin: FirDeclarationOrigin, propertyTypeRef: FirTypeRef, visibility: Visibility, + propertySymbol: FirPropertySymbol, modality: Modality = Modality.FINAL, effectiveVisibility: EffectiveVisibility? = null, symbol: FirPropertyAccessorSymbol = FirPropertyAccessorSymbol() @@ -126,6 +133,7 @@ class FirDefaultPropertySetter( this@builder.symbol = FirValueParameterSymbol(Name.special("")) } ), + propertySymbol, isGetter = false, visibility = visibility, modality = modality, diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt index 5d3dcb0b8d8..94f9bcb5cba 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticPropertyAccessor.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -74,6 +75,9 @@ class FirSyntheticPropertyAccessor( bind(this@FirSyntheticPropertyAccessor) } + // NB: unused + override val propertySymbol: FirPropertySymbol? = null + override val controlFlowGraphReference: FirControlFlowGraphReference? = null override val contractDescription: FirContractDescription = FirEmptyContractDescription diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index e8465d8d519..045b8bd712f 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -324,6 +324,9 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild propertyAccessor.configure { +symbol("FirPropertyAccessorSymbol") + +field("propertySymbol", firPropertySymbolType, nullable = true).apply { + withBindThis = false + } +booleanField("isGetter") +booleanField("isSetter") +annotations diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt index d47a8ea55cd..7e6a0e26450 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/Types.kt @@ -94,3 +94,6 @@ val functionCallOrigin = type("fir.expressions", "FirFunctionCallOrigin") val resolvedDeclarationStatusImplType = type("fir.declarations.impl", "FirResolvedDeclarationStatusImpl") val deprecationsPerUseSiteType = type("fir.declarations", "DeprecationsPerUseSite") + +val firPropertySymbolType = type("fir.symbols.impl", "FirPropertySymbol") +