FIR: make class delegation field a fake source

Previously, the FirFieldImpl generated from class delegation has a real
source. This causes troubles in the IDE. This change adds a new fake
source kind for class delegation fields.
This commit is contained in:
Tianyu Geng
2021-04-22 14:56:43 -07:00
committed by TeamCityServer
parent 0b8b20eda0
commit d09be811f0
3 changed files with 7 additions and 2 deletions
@@ -1574,7 +1574,7 @@ class DeclarationsConverter(
val delegateName = Name.special("<\$\$delegate_${delegateFields.size}>")
delegateFields.add(
buildField {
source = firExpression!!.source
source = firExpression!!.source?.fakeElement(FirFakeSourceElementKind.ClassDelegationField)
declarationSiteSession = baseSession
origin = FirDeclarationOrigin.Synthetic
name = delegateName
@@ -566,7 +566,8 @@ open class RawFirBuilder(
val delegateExpression = { superTypeListEntry.delegateExpression }.toFirExpression("Should have delegate")
container.superTypeRefs += type
val delegateName = Name.special("<\$\$delegate_${delegateFields.size}>")
val delegateSource = superTypeListEntry.delegateExpression?.toFirSourceElement()
val delegateSource =
superTypeListEntry.delegateExpression?.toFirSourceElement(FirFakeSourceElementKind.ClassDelegationField)
val delegateField = buildField {
source = delegateSource
declarationSiteSession = baseSession
@@ -170,6 +170,10 @@ sealed class FirFakeSourceElementKind : FirSourceElementKind() {
// for java annotations constructor implicit parameters are generated
// with a fake source which refers to declared annotation methods
object ImplicitAnnotationAnnotationConstructorParameter : FirFakeSourceElementKind()
// for the implicit field storing the delegated object for class delegation
// with a fake source that refers to the KtExpression that creates the delegate
object ClassDelegationField : FirFakeSourceElementKind()
}
sealed class FirSourceElement {