FIR: Get rid of PSI dependency in the :fir:resolve module
This commit is contained in:
@@ -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