[FIR] provide correct origin and source to default backing field
Now it is aligned with default accessors Covered by analysis/analysis-api/testData/symbols/symbolByReference/accessorField.kt test ^KT-57648 ^KT-55723
This commit is contained in:
committed by
Space Team
parent
ae4b0c6fe1
commit
add47aa041
+5
-1
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.toKtPsiSourceElement
|
||||
|
||||
internal class StubBasedFirDeserializationContext(
|
||||
val moduleData: FirModuleData,
|
||||
@@ -313,12 +314,15 @@ internal class StubBasedFirMemberDeserializer(
|
||||
allAnnotations.filter { it.useSiteTarget == AnnotationUseSiteTarget.FIELD || it.useSiteTarget == AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD }
|
||||
backingField = FirDefaultPropertyBackingField(
|
||||
c.moduleData,
|
||||
initialOrigin,
|
||||
source = property.toKtPsiSourceElement(KtFakeSourceElementKind.DefaultAccessor),
|
||||
backingFieldAnnotations.toMutableList(),
|
||||
returnTypeRef,
|
||||
isVar,
|
||||
symbol,
|
||||
status
|
||||
status,
|
||||
)
|
||||
|
||||
if (getter != null) {
|
||||
this.getter = loadPropertyGetter(
|
||||
getter,
|
||||
|
||||
+4
-1
@@ -415,12 +415,15 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
)
|
||||
backingField = FirDefaultPropertyBackingField(
|
||||
c.moduleData,
|
||||
FirDeclarationOrigin.Library,
|
||||
source = null,
|
||||
backingFieldAnnotations,
|
||||
returnTypeRef,
|
||||
isVar,
|
||||
symbol,
|
||||
status
|
||||
status,
|
||||
)
|
||||
|
||||
if (hasGetter) {
|
||||
this.getter = loadPropertyGetter(
|
||||
proto,
|
||||
|
||||
+9
-1
@@ -105,9 +105,17 @@ public class PropertyBuildingContext(
|
||||
} else {
|
||||
require(setterVisibility == null) { "isVar = false but setterVisibility is specified. Did you forget to set isVar = true?" }
|
||||
}
|
||||
|
||||
if (hasBackingField) {
|
||||
backingField = FirDefaultPropertyBackingField(
|
||||
session.moduleData, mutableListOf(), returnTypeRef, isVar, symbol, status,
|
||||
session.moduleData,
|
||||
key.origin,
|
||||
source = null,
|
||||
mutableListOf(),
|
||||
returnTypeRef,
|
||||
isVar,
|
||||
symbol,
|
||||
status,
|
||||
resolvePhase = FirResolvePhase.BODY_RESOLVE,
|
||||
)
|
||||
}
|
||||
|
||||
+5
-1
@@ -1196,7 +1196,8 @@ class DeclarationsConverter(
|
||||
symbol, modifiers, returnType, isVar,
|
||||
if (isLocal) emptyList() else modifiers.annotations.filter {
|
||||
it.useSiteTarget == FIELD || it.useSiteTarget == PROPERTY_DELEGATE_FIELD
|
||||
}
|
||||
},
|
||||
property,
|
||||
)
|
||||
|
||||
if (isLocal) {
|
||||
@@ -1481,6 +1482,7 @@ class DeclarationsConverter(
|
||||
propertyReturnType: FirTypeRef,
|
||||
isVar: Boolean,
|
||||
annotationsFromProperty: List<FirAnnotationCall>,
|
||||
property: LighterASTNode,
|
||||
): FirBackingField {
|
||||
var modifiers = Modifier()
|
||||
var returnType: FirTypeRef = implicitType
|
||||
@@ -1519,6 +1521,8 @@ class DeclarationsConverter(
|
||||
} else {
|
||||
FirDefaultPropertyBackingField(
|
||||
moduleData = baseModuleData,
|
||||
origin = FirDeclarationOrigin.Source,
|
||||
source = property.toFirSourceElement(KtFakeSourceElementKind.DefaultAccessor),
|
||||
annotations = annotationsFromProperty.toMutableList(),
|
||||
returnTypeRef = propertyReturnType.copyWithNewSourceKind(KtFakeSourceElementKind.DefaultAccessor),
|
||||
isVar = isVar,
|
||||
|
||||
+6
-1
@@ -134,8 +134,12 @@ class ValueParameter(
|
||||
isOverride = modifiers.hasOverride()
|
||||
isConst = modifiers.hasConst()
|
||||
}
|
||||
|
||||
val defaultAccessorSource = propertySource?.fakeElement(KtFakeSourceElementKind.DefaultAccessor)
|
||||
backingField = FirDefaultPropertyBackingField(
|
||||
moduleData = moduleData,
|
||||
origin = FirDeclarationOrigin.Source,
|
||||
source = defaultAccessorSource,
|
||||
annotations = modifiers.annotations.filter {
|
||||
it.useSiteTarget == FIELD || it.useSiteTarget == PROPERTY_DELEGATE_FIELD
|
||||
}.toMutableList(),
|
||||
@@ -144,10 +148,11 @@ class ValueParameter(
|
||||
propertySymbol = symbol,
|
||||
status = status.copy(),
|
||||
)
|
||||
|
||||
annotations += modifiers.annotations.filter {
|
||||
it.useSiteTarget == null || it.useSiteTarget == PROPERTY
|
||||
}
|
||||
val defaultAccessorSource = propertySource?.fakeElement(KtFakeSourceElementKind.DefaultAccessor)
|
||||
|
||||
getter = FirDefaultPropertyGetter(
|
||||
defaultAccessorSource,
|
||||
moduleData,
|
||||
|
||||
@@ -567,6 +567,8 @@ open class RawFirBuilder(
|
||||
} else {
|
||||
FirDefaultPropertyBackingField(
|
||||
moduleData = baseModuleData,
|
||||
origin = FirDeclarationOrigin.Source,
|
||||
source = property.toFirSourceElement(KtFakeSourceElementKind.DefaultAccessor),
|
||||
annotations = annotationsFromProperty.toMutableList(),
|
||||
returnTypeRef = propertyReturnType.copyWithNewSourceKind(KtFakeSourceElementKind.DefaultAccessor),
|
||||
isVar = property.isVar,
|
||||
@@ -649,8 +651,11 @@ open class RawFirBuilder(
|
||||
isVar = isMutable
|
||||
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
||||
isLocal = false
|
||||
val defaultAccessorSource = propertySource.fakeElement(KtFakeSourceElementKind.DefaultAccessor)
|
||||
backingField = FirDefaultPropertyBackingField(
|
||||
moduleData = baseModuleData,
|
||||
origin = FirDeclarationOrigin.Source,
|
||||
source = defaultAccessorSource,
|
||||
annotations = parameterAnnotations.filter {
|
||||
it.useSiteTarget == FIELD || it.useSiteTarget == PROPERTY_DELEGATE_FIELD
|
||||
}.toMutableList(),
|
||||
@@ -661,7 +666,6 @@ open class RawFirBuilder(
|
||||
)
|
||||
|
||||
this.status = status
|
||||
val defaultAccessorSource = propertySource.fakeElement(KtFakeSourceElementKind.DefaultAccessor)
|
||||
getter = FirDefaultPropertyGetter(
|
||||
defaultAccessorSource,
|
||||
baseModuleData,
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BACKING_FIELD
|
||||
import org.jetbrains.kotlin.fir.FirImplementationDetail
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
@@ -20,6 +21,8 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
@OptIn(FirImplementationDetail::class)
|
||||
class FirDefaultPropertyBackingField(
|
||||
moduleData: FirModuleData,
|
||||
origin: FirDeclarationOrigin,
|
||||
source: KtSourceElement?,
|
||||
annotations: MutableList<FirAnnotation>,
|
||||
returnTypeRef: FirTypeRef,
|
||||
isVar: Boolean,
|
||||
@@ -27,10 +30,10 @@ class FirDefaultPropertyBackingField(
|
||||
status: FirDeclarationStatus,
|
||||
resolvePhase: FirResolvePhase = FirResolvePhase.RAW_FIR,
|
||||
) : FirBackingFieldImpl(
|
||||
source = null,
|
||||
source = source,
|
||||
moduleData = moduleData,
|
||||
resolvePhase = resolvePhase,
|
||||
origin = FirDeclarationOrigin.Synthetic,
|
||||
origin = origin,
|
||||
attributes = FirDeclarationAttributes(),
|
||||
returnTypeRef = returnTypeRef,
|
||||
receiverParameter = null,
|
||||
|
||||
Reference in New Issue
Block a user