FIR IDE: remove duplicating withFirResolvedToBodyResolve

This commit is contained in:
Ilya Kirillov
2020-11-26 10:57:33 +01:00
parent 3141fead0d
commit 65a7ee5012
2 changed files with 11 additions and 12 deletions
@@ -61,7 +61,7 @@ internal class KtFirCompletionCandidateChecker(
private inline fun <reified T : KtFirSymbol<F>, F : FirDeclaration, R> KtCallableSymbol.withResolvedFirOfType(
noinline action: (F) -> R,
): R? = this.safeAs<T>()?.firRef?.withFirResolvedToBodyResolve(action)
): R? = this.safeAs<T>()?.firRef?.withFir(phase = FirResolvePhase.BODY_RESOLVE, action)
private fun checkExtension(
candidateSymbol: FirCallableDeclaration<*>,
@@ -25,17 +25,16 @@ internal class FirRefWithValidityCheck<D : FirDeclaration>(fir: D, resolveState:
val resolveState = resolveStateWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirModuleResolveState")
fir.resolvedFirToPhase(phase, resolveState)
return resolveState.withFirDeclaration(fir) { action(it) }
}
inline fun <R> withFirResolvedToBodyResolve(action: (fir: D) -> R): R {
token.assertIsValid()
val fir = firWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirElement")
val resolveState = resolveStateWeakRef.get()
?: throw EntityWasGarbageCollectedException("FirModuleResolveState")
fir.resolvedFirToPhase(FirResolvePhase.BODY_RESOLVE, resolveState)
return action(resolveState.withFirDeclaration(fir) { it })
return when (phase) {
FirResolvePhase.BODY_RESOLVE -> {
/*
The BODY_RESOLVE phase is the maximum possible phase we can resolve our declaration to
So there is not need to run whole `action` under read lock
*/
action(resolveState.withFirDeclaration(fir) { it })
}
else -> resolveState.withFirDeclaration(fir) { action(it) }
}
}
val resolveState