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