FIR: Get rid of PSI dependency in the :fir:resolve module

This commit is contained in:
Roman Golyshev
2021-02-19 07:20:06 +00:00
committed by Space
parent 6b453d9b23
commit 74bdb2398e
3 changed files with 19 additions and 12 deletions
@@ -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
}