From f5d8535dc593fe76a9f23261903929bdee6c328f Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Fri, 16 Jul 2021 20:42:53 +0300 Subject: [PATCH] [FIR] Add `aliasSource` to FirImport, FirImportImpl --- .../lightTree/converter/DeclarationsConverter.kt | 14 +++++++++++--- .../jetbrains/kotlin/fir/builder/RawFirBuilder.kt | 1 + .../kotlin/fir/declarations/FirErrorImport.kt | 1 + .../jetbrains/kotlin/fir/declarations/FirImport.kt | 1 + .../kotlin/fir/declarations/FirResolvedImport.kt | 1 + .../declarations/builder/FirErrorImportBuilder.kt | 3 +++ .../fir/declarations/builder/FirImportBuilder.kt | 2 ++ .../fir/declarations/impl/FirErrorImportImpl.kt | 1 + .../kotlin/fir/declarations/impl/FirImportImpl.kt | 1 + .../fir/declarations/impl/FirResolvedImportImpl.kt | 1 + .../tree/generator/ImplementationConfigurator.kt | 2 +- .../kotlin/fir/tree/generator/NodeConfigurator.kt | 1 + 12 files changed, 25 insertions(+), 4 deletions(-) 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 8a099c82b4a..375ab8403e8 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 @@ -169,10 +169,10 @@ class DeclarationsConverter( } } - private fun convertImportAlias(importAlias: LighterASTNode): String? { + private fun convertImportAlias(importAlias: LighterASTNode): Pair? { importAlias.forEachChildren { when (it.tokenType) { - IDENTIFIER -> return it.asText + IDENTIFIER -> return Pair(it.asText, it.toFirSourceElement()) } } @@ -186,11 +186,18 @@ class DeclarationsConverter( var importedFqName: FqName? = null var isAllUnder = false var aliasName: String? = null + var aliasSource: FirSourceElement? = null importDirective.forEachChildren { when (it.tokenType) { DOT_QUALIFIED_EXPRESSION, REFERENCE_EXPRESSION -> importedFqName = FqName(it.asText) MUL -> isAllUnder = true - IMPORT_ALIAS -> aliasName = convertImportAlias(it) + IMPORT_ALIAS -> { + val importAlias = convertImportAlias(it) + if (importAlias != null) { + aliasName = importAlias.first + aliasSource = importAlias.second + } + } } } @@ -199,6 +206,7 @@ class DeclarationsConverter( this.importedFqName = importedFqName this.isAllUnder = isAllUnder this.aliasName = aliasName?.let { Name.identifier(it) } + this.aliasSource = aliasSource } } 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 218d8dde519..fdb7d45add0 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 @@ -810,6 +810,7 @@ open class RawFirBuilder( importedFqName = importDirective.importedFqName isAllUnder = importDirective.isAllUnder aliasName = importDirective.aliasName?.let { Name.identifier(it) } + aliasSource = importDirective.alias?.nameIdentifier?.toFirSourceElement() } } for (declaration in file.declarations) { diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirErrorImport.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirErrorImport.kt index 37fa799c6cb..63bbbba9082 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirErrorImport.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirErrorImport.kt @@ -24,6 +24,7 @@ abstract class FirErrorImport : FirPureAbstractElement(), FirImport, FirDiagnost abstract override val importedFqName: FqName? abstract override val isAllUnder: Boolean abstract override val aliasName: Name? + abstract override val aliasSource: FirSourceElement? abstract override val diagnostic: ConeDiagnostic abstract val delegate: FirImport diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirImport.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirImport.kt index 205601e7c18..08b5b85ca91 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirImport.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirImport.kt @@ -21,6 +21,7 @@ interface FirImport : FirElement { val importedFqName: FqName? val isAllUnder: Boolean val aliasName: Name? + val aliasSource: FirSourceElement? override fun accept(visitor: FirVisitor, data: D): R = visitor.visitImport(this, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirResolvedImport.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirResolvedImport.kt index 5bb7b84c20c..54db585f81f 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirResolvedImport.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirResolvedImport.kt @@ -23,6 +23,7 @@ abstract class FirResolvedImport : FirPureAbstractElement(), FirImport { abstract override val importedFqName: FqName? abstract override val isAllUnder: Boolean abstract override val aliasName: Name? + abstract override val aliasSource: FirSourceElement? abstract val delegate: FirImport abstract val packageFqName: FqName abstract val relativeClassName: FqName? diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirErrorImportBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirErrorImportBuilder.kt index d0fa78c2550..e2fd17b2012 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirErrorImportBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirErrorImportBuilder.kt @@ -23,15 +23,18 @@ import org.jetbrains.kotlin.name.Name @FirBuilderDsl class FirErrorImportBuilder { + var aliasSource: FirSourceElement? = null lateinit var diagnostic: ConeDiagnostic lateinit var delegate: FirImport fun build(): FirErrorImport { return FirErrorImportImpl( + aliasSource, diagnostic, delegate, ) } + } @OptIn(ExperimentalContracts::class) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirImportBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirImportBuilder.kt index dda710f3155..a1f20f45eaa 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirImportBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirImportBuilder.kt @@ -26,6 +26,7 @@ class FirImportBuilder { var importedFqName: FqName? = null var isAllUnder: Boolean by kotlin.properties.Delegates.notNull() var aliasName: Name? = null + var aliasSource: FirSourceElement? = null fun build(): FirImport { return FirImportImpl( @@ -33,6 +34,7 @@ class FirImportBuilder { importedFqName, isAllUnder, aliasName, + aliasSource, ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorImportImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorImportImpl.kt index e9d08c52eb9..8b396792d5b 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorImportImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorImportImpl.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.visitors.* */ internal class FirErrorImportImpl( + override val aliasSource: FirSourceElement?, override val diagnostic: ConeDiagnostic, override var delegate: FirImport, ) : FirErrorImport() { diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirImportImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirImportImpl.kt index f9826ba348d..0ea806c61f5 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirImportImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirImportImpl.kt @@ -22,6 +22,7 @@ internal class FirImportImpl( override val importedFqName: FqName?, override val isAllUnder: Boolean, override val aliasName: Name?, + override val aliasSource: FirSourceElement?, ) : FirPureAbstractElement(), FirImport { override fun acceptChildren(visitor: FirVisitor, data: D) {} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirResolvedImportImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirResolvedImportImpl.kt index 2429bce03e2..8eb0f772327 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirResolvedImportImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirResolvedImportImpl.kt @@ -27,6 +27,7 @@ internal class FirResolvedImportImpl( override val importedFqName: FqName? get() = delegate.importedFqName override val isAllUnder: Boolean get() = delegate.isAllUnder override val aliasName: Name? get() = delegate.aliasName + override val aliasSource: FirSourceElement? get() = delegate.aliasSource override val resolvedClassId: ClassId? get() = relativeClassName?.let { ClassId(packageFqName, it, false) } override val importedName: Name? get() = importedFqName?.shortName() diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 1dbc7f5b9cb..d89e15173a0 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -45,7 +45,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() impl(import) impl(resolvedImport) { - delegateFields(listOf("aliasName", "importedFqName", "isAllUnder"), "delegate") + delegateFields(listOf("aliasName", "aliasSource", "importedFqName", "isAllUnder"), "delegate") default("source") { delegate = "delegate" 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 065a44e86f4..25b0d84f81d 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 @@ -407,6 +407,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +field("importedFqName", fqNameType, nullable = true) +booleanField("isAllUnder") +field("aliasName", nameType, nullable = true) + +field("aliasSource", sourceElementType, nullable = true) } resolvedImport.configure {