Minor: merge FirSamResolver and its only implementation

This commit is contained in:
pyos
2022-10-20 13:59:02 +02:00
committed by Space Team
parent 0d46dfc1ba
commit 1232346202
5 changed files with 16 additions and 21 deletions
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.fir.types.PublicTypeApproximator
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
import org.jetbrains.kotlin.fir.resolve.FirSamResolver
import org.jetbrains.kotlin.fir.types.*
internal class KtFirTypeInfoProvider(
@@ -23,7 +23,7 @@ internal class KtFirTypeInfoProvider(
override fun isFunctionalInterfaceType(type: KtType): Boolean {
val coneType = (type as KtFirType).coneType
val firSession = analysisSession.useSiteSession
val samResolver = FirSamResolverImpl(
val samResolver = FirSamResolver(
firSession,
analysisSession.getScopeSessionFor(firSession),
)
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
import org.jetbrains.kotlin.fir.resolve.FirSamResolver
import org.jetbrains.kotlin.fir.resolve.calls.FirFakeArgumentForCallableReference
import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType
@@ -59,7 +59,7 @@ internal class AdapterGenerator(
private val conversionScope: Fir2IrConversionScope
) : Fir2IrComponents by components {
private val samResolver = FirSamResolverImpl(session, scopeSession)
private val samResolver = FirSamResolver(session, scopeSession)
private val starProjectionApproximator = object : AbstractConeSubstitutor(session.typeContext) {
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
@@ -41,29 +41,23 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.Variance
abstract class FirSamResolver {
abstract fun shouldRunSamConversionForFunction(firFunction: FirFunction): Boolean
abstract fun getSamConstructor(firClassOrTypeAlias: FirClassLikeDeclaration): FirSimpleFunction?
abstract fun getFunctionTypeForPossibleSamType(type: ConeKotlinType): ConeKotlinType?
fun isSamType(type: ConeKotlinType): Boolean =
getFunctionTypeForPossibleSamType(type) != null
}
private val SAM_PARAMETER_NAME = Name.identifier("function")
data class SAMInfo<out C : ConeKotlinType>(internal val symbol: FirNamedFunctionSymbol, val type: C)
class FirSamResolverImpl(
class FirSamResolver(
private val session: FirSession,
private val scopeSession: ScopeSession,
private val outerClassManager: FirOuterClassManager? = null,
) : FirSamResolver() {
) {
private val resolvedFunctionType: NullableMap<FirRegularClass, SAMInfo<ConeLookupTagBasedType>?> = NullableMap()
private val samConstructorsCache = session.samConstructorStorage.samConstructors
private val samConversionTransformers = session.extensionService.samConversionTransformers
override fun getFunctionTypeForPossibleSamType(type: ConeKotlinType): ConeKotlinType? {
fun isSamType(type: ConeKotlinType): Boolean =
getFunctionTypeForPossibleSamType(type) != null
fun getFunctionTypeForPossibleSamType(type: ConeKotlinType): ConeKotlinType? {
return when (type) {
is ConeClassLikeType -> getFunctionTypeForPossibleSamType(type.fullyExpandedType(session))
is ConeFlexibleType -> {
@@ -97,7 +91,7 @@ class FirSamResolverImpl(
return functionType.withNullability(ConeNullability.create(type.isMarkedNullable), session.typeContext)
}
override fun getSamConstructor(firClassOrTypeAlias: FirClassLikeDeclaration): FirSimpleFunction? {
fun getSamConstructor(firClassOrTypeAlias: FirClassLikeDeclaration): FirSimpleFunction? {
if (firClassOrTypeAlias is FirTypeAlias) {
// Precompute the constructor for the base type to avoid deadlocks in the IDE.
firClassOrTypeAlias.expandedTypeRef.coneTypeSafe<ConeClassLikeType>()
@@ -268,7 +262,8 @@ class FirSamResolverImpl(
}
}
override fun shouldRunSamConversionForFunction(firFunction: FirFunction): Boolean {
@Suppress("UNUSED_PARAMETER")
fun shouldRunSamConversionForFunction(firFunction: FirFunction): Boolean {
// TODO: properly support, see org.jetbrains.kotlin.load.java.sam.JvmSamConversionTransformer.shouldRunSamConversionForFunction
return true
}
@@ -427,7 +422,7 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagB
}
class FirSamConstructorStorage(session: FirSession) : FirSessionComponent {
val samConstructors: FirCache<FirClassLikeSymbol<*>, FirNamedFunctionSymbol?, FirSamResolverImpl> =
val samConstructors: FirCache<FirClassLikeSymbol<*>, FirNamedFunctionSymbol?, FirSamResolver> =
session.firCachesFactory.createCache { classSymbol, samResolver ->
when (classSymbol) {
is FirRegularClassSymbol -> samResolver.buildSamConstructorForRegularClass(classSymbol)
@@ -74,7 +74,7 @@ class FirCallCompletionResultsWriterTransformer(
private val arrayOfCallTransformer = FirArrayOfCallTransformer()
private var enableArrayOfCallTransformation = false
private val samResolver: FirSamResolver = FirSamResolverImpl(session, ScopeSession())
private val samResolver: FirSamResolver = FirSamResolver(session, ScopeSession())
enum class Mode {
Normal, DelegatedPropertyCompletion
@@ -108,7 +108,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
override val syntheticCallGenerator: FirSyntheticCallGenerator = FirSyntheticCallGenerator(this)
override val doubleColonExpressionResolver: FirDoubleColonExpressionResolver = FirDoubleColonExpressionResolver(session)
override val outerClassManager: FirOuterClassManager = FirOuterClassManager(session, context.outerLocalClassForNested)
override val samResolver: FirSamResolver = FirSamResolverImpl(session, scopeSession, outerClassManager)
override val samResolver: FirSamResolver = FirSamResolver(session, scopeSession, outerClassManager)
override val integerLiteralAndOperatorApproximationTransformer: IntegerLiteralAndOperatorApproximationTransformer =
IntegerLiteralAndOperatorApproximationTransformer(session, scopeSession)
}