FIR: Get rid of PSI dependency in the :fir:resolve module
This commit is contained in:
@@ -14,10 +14,9 @@ dependencies {
|
||||
api(project(":compiler:fir:tree"))
|
||||
api(kotlinxCollectionsImmutable())
|
||||
implementation(project(":core:util.runtime"))
|
||||
implementation(project(":compiler:psi"))
|
||||
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) }
|
||||
compileOnly(intellijCoreDep()) { includeJars("guava", rootProject = rootProject) }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.resolve.typeForQualifier
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
|
||||
const val ROOT_PREFIX_FOR_IDE_RESOLUTION_MODE = "_root_ide_package_"
|
||||
|
||||
@@ -92,7 +91,7 @@ class FirQualifiedNameResolver(private val components: BodyResolveComponents) {
|
||||
}
|
||||
|
||||
return buildResolvedQualifier {
|
||||
this.source = getWholeQualifierSource(source, qualifierPartsToDrop)
|
||||
this.source = source?.getWholeQualifierSourceIfPossible(qualifierPartsToDrop)
|
||||
packageFqName = resolved.packageFqName
|
||||
relativeClassFqName = resolved.relativeClassFqName
|
||||
symbol = resolved.classSymbol
|
||||
@@ -104,12 +103,4 @@ class FirQualifiedNameResolver(private val components: BodyResolveComponents) {
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getWholeQualifierSource(qualifierStartSource: FirSourceElement?, stepsToWholeQualifier: Int): FirSourceElement? {
|
||||
if (qualifierStartSource !is FirRealPsiSourceElement<*>) return qualifierStartSource
|
||||
|
||||
val qualifierStart = qualifierStartSource.psi
|
||||
val wholeQualifier = qualifierStart.parentsWithSelf.drop(stepsToWholeQualifier).first()
|
||||
return wholeQualifier.toFirPsiSourceElement()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,3 +56,20 @@ fun <R : FirTypeRef> R.copyWithNewSourceKind(newKind: FirFakeSourceElementKind):
|
||||
} as R
|
||||
}
|
||||
|
||||
/**
|
||||
* Let's take `a.b.c.call()` expression as an example.
|
||||
*
|
||||
* This function allows to transform `SourceElement(psi = 'a')` to `SourceElement(psi = 'a.b.c')`
|
||||
* ([stepsToWholeQualifier] should be = 2 for that).
|
||||
*
|
||||
* @receiver original source element
|
||||
* @param stepsToWholeQualifier distance between the original psi and the whole qualifier psi
|
||||
*/
|
||||
fun FirSourceElement.getWholeQualifierSourceIfPossible(stepsToWholeQualifier: Int): FirSourceElement {
|
||||
if (this !is FirRealPsiSourceElement<*>) return this
|
||||
|
||||
val qualifiersChain = generateSequence(psi) { it.parent }
|
||||
val wholeQualifier = qualifiersChain.drop(stepsToWholeQualifier).first()
|
||||
|
||||
return wholeQualifier.toFirPsiSourceElement() as FirRealPsiSourceElement
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user