Analysis API: Use stub FirDataFlowAnalyzer when getting candidates.

This commit is contained in:
Mark Punzalan
2022-02-08 08:08:39 +00:00
committed by Ilya Kirillov
parent 3f3873dc50
commit f1623347d8
4 changed files with 34 additions and 8 deletions
@@ -7,9 +7,17 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.resolver
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer
import org.jetbrains.kotlin.fir.resolve.dfa.LogicSystem
import org.jetbrains.kotlin.fir.resolve.dfa.PersistentFlow
import org.jetbrains.kotlin.fir.resolve.dfa.PropertyStability
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirBodyResolveTransformer
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
internal fun createStubBodyResolveComponents(firSession: FirSession): FirAbstractBodyResolveTransformer.BodyResolveTransformerComponents {
val scopeSession = ScopeSession()
@@ -22,10 +30,33 @@ internal fun createStubBodyResolveComponents(firSession: FirSession): FirAbstrac
scopeSession = scopeSession,
)
return FirAbstractBodyResolveTransformer.BodyResolveTransformerComponents(
return StubBodyResolveTransformerComponents(
firSession,
scopeSession,
stubBodyResolveTransformer,
stubBodyResolveTransformer.context,
)
}
private class StubBodyResolveTransformerComponents(
session: FirSession,
scopeSession: ScopeSession,
transformer: FirBodyResolveTransformer,
context: BodyResolveContext
) : FirAbstractBodyResolveTransformer.BodyResolveTransformerComponents(
session,
scopeSession,
transformer,
context,
) {
override val dataFlowAnalyzer: FirDataFlowAnalyzer<*>
get() = object : FirDataFlowAnalyzer<PersistentFlow>(this@StubBodyResolveTransformerComponents, context.dataFlowAnalyzerContext) {
override val logicSystem: LogicSystem<PersistentFlow>
get() = error("Should not be called")
override fun getTypeUsingSmartcastInfo(
symbol: FirBasedSymbol<*>,
expression: FirExpression
): Pair<PropertyStability, MutableList<ConeKotlinType>>? = null
}
}
@@ -322,11 +322,6 @@ private inline fun <T : FirExpression> BodyResolveComponents.transformExpression
smartcastBuilder: () -> FirWrappedExpressionWithSmartcastBuilder<T>,
smartcastToNullBuilder: () -> FirWrappedExpressionWithSmartcastToNullBuilder<T>
): FirWrappedExpressionWithSmartcastBuilder<T>? {
// No need to check for smartcast if the expression was already resolved.
containingDeclarations.lastOrNull()?.let { closestDeclaration ->
if (closestDeclaration.resolvePhase >= FirResolvePhase.BODY_RESOLVE) return null
}
val (stability, typesFromSmartCast) = smartcastExtractor(expression) ?: return null
val smartcastStability = stability.impliedSmartcastStability
?: if (dataFlowAnalyzer.isAccessToUnstableLocalVariable(expression)) {
@@ -193,7 +193,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
return getTypeUsingSmartcastInfo(symbol, qualifiedAccessExpression)
}
private fun getTypeUsingSmartcastInfo(
protected open fun getTypeUsingSmartcastInfo(
symbol: FirBasedSymbol<*>,
expression: FirExpression
): Pair<PropertyStability, MutableList<ConeKotlinType>>? {
@@ -73,7 +73,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
val ResolutionMode.expectedType: FirTypeRef?
get() = expectedType(components)
class BodyResolveTransformerComponents(
open class BodyResolveTransformerComponents(
override val session: FirSession,
override val scopeSession: ScopeSession,
val transformer: FirBodyResolveTransformer,