Minor: merge FirSamResolver and its only implementation
This commit is contained in:
+2
-2
@@ -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.lifetime.KtLifetimeToken
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
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.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
|
|
||||||
internal class KtFirTypeInfoProvider(
|
internal class KtFirTypeInfoProvider(
|
||||||
@@ -23,7 +23,7 @@ internal class KtFirTypeInfoProvider(
|
|||||||
override fun isFunctionalInterfaceType(type: KtType): Boolean {
|
override fun isFunctionalInterfaceType(type: KtType): Boolean {
|
||||||
val coneType = (type as KtFirType).coneType
|
val coneType = (type as KtFirType).coneType
|
||||||
val firSession = analysisSession.useSiteSession
|
val firSession = analysisSession.useSiteSession
|
||||||
val samResolver = FirSamResolverImpl(
|
val samResolver = FirSamResolver(
|
||||||
firSession,
|
firSession,
|
||||||
analysisSession.getScopeSessionFor(firSession),
|
analysisSession.getScopeSessionFor(firSession),
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.*
|
|||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
|
||||||
import org.jetbrains.kotlin.fir.render
|
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.FirFakeArgumentForCallableReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument
|
import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType
|
import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType
|
||||||
@@ -59,7 +59,7 @@ internal class AdapterGenerator(
|
|||||||
private val conversionScope: Fir2IrConversionScope
|
private val conversionScope: Fir2IrConversionScope
|
||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
|
|
||||||
private val samResolver = FirSamResolverImpl(session, scopeSession)
|
private val samResolver = FirSamResolver(session, scopeSession)
|
||||||
|
|
||||||
private val starProjectionApproximator = object : AbstractConeSubstitutor(session.typeContext) {
|
private val starProjectionApproximator = object : AbstractConeSubstitutor(session.typeContext) {
|
||||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
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.name.StandardClassIds
|
||||||
import org.jetbrains.kotlin.types.Variance
|
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")
|
private val SAM_PARAMETER_NAME = Name.identifier("function")
|
||||||
|
|
||||||
data class SAMInfo<out C : ConeKotlinType>(internal val symbol: FirNamedFunctionSymbol, val type: C)
|
data class SAMInfo<out C : ConeKotlinType>(internal val symbol: FirNamedFunctionSymbol, val type: C)
|
||||||
|
|
||||||
class FirSamResolverImpl(
|
class FirSamResolver(
|
||||||
private val session: FirSession,
|
private val session: FirSession,
|
||||||
private val scopeSession: ScopeSession,
|
private val scopeSession: ScopeSession,
|
||||||
private val outerClassManager: FirOuterClassManager? = null,
|
private val outerClassManager: FirOuterClassManager? = null,
|
||||||
) : FirSamResolver() {
|
) {
|
||||||
private val resolvedFunctionType: NullableMap<FirRegularClass, SAMInfo<ConeLookupTagBasedType>?> = NullableMap()
|
private val resolvedFunctionType: NullableMap<FirRegularClass, SAMInfo<ConeLookupTagBasedType>?> = NullableMap()
|
||||||
private val samConstructorsCache = session.samConstructorStorage.samConstructors
|
private val samConstructorsCache = session.samConstructorStorage.samConstructors
|
||||||
private val samConversionTransformers = session.extensionService.samConversionTransformers
|
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) {
|
return when (type) {
|
||||||
is ConeClassLikeType -> getFunctionTypeForPossibleSamType(type.fullyExpandedType(session))
|
is ConeClassLikeType -> getFunctionTypeForPossibleSamType(type.fullyExpandedType(session))
|
||||||
is ConeFlexibleType -> {
|
is ConeFlexibleType -> {
|
||||||
@@ -97,7 +91,7 @@ class FirSamResolverImpl(
|
|||||||
return functionType.withNullability(ConeNullability.create(type.isMarkedNullable), session.typeContext)
|
return functionType.withNullability(ConeNullability.create(type.isMarkedNullable), session.typeContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSamConstructor(firClassOrTypeAlias: FirClassLikeDeclaration): FirSimpleFunction? {
|
fun getSamConstructor(firClassOrTypeAlias: FirClassLikeDeclaration): FirSimpleFunction? {
|
||||||
if (firClassOrTypeAlias is FirTypeAlias) {
|
if (firClassOrTypeAlias is FirTypeAlias) {
|
||||||
// Precompute the constructor for the base type to avoid deadlocks in the IDE.
|
// Precompute the constructor for the base type to avoid deadlocks in the IDE.
|
||||||
firClassOrTypeAlias.expandedTypeRef.coneTypeSafe<ConeClassLikeType>()
|
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
|
// TODO: properly support, see org.jetbrains.kotlin.load.java.sam.JvmSamConversionTransformer.shouldRunSamConversionForFunction
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -427,7 +422,7 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagB
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FirSamConstructorStorage(session: FirSession) : FirSessionComponent {
|
class FirSamConstructorStorage(session: FirSession) : FirSessionComponent {
|
||||||
val samConstructors: FirCache<FirClassLikeSymbol<*>, FirNamedFunctionSymbol?, FirSamResolverImpl> =
|
val samConstructors: FirCache<FirClassLikeSymbol<*>, FirNamedFunctionSymbol?, FirSamResolver> =
|
||||||
session.firCachesFactory.createCache { classSymbol, samResolver ->
|
session.firCachesFactory.createCache { classSymbol, samResolver ->
|
||||||
when (classSymbol) {
|
when (classSymbol) {
|
||||||
is FirRegularClassSymbol -> samResolver.buildSamConstructorForRegularClass(classSymbol)
|
is FirRegularClassSymbol -> samResolver.buildSamConstructorForRegularClass(classSymbol)
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
private val arrayOfCallTransformer = FirArrayOfCallTransformer()
|
private val arrayOfCallTransformer = FirArrayOfCallTransformer()
|
||||||
private var enableArrayOfCallTransformation = false
|
private var enableArrayOfCallTransformation = false
|
||||||
|
|
||||||
private val samResolver: FirSamResolver = FirSamResolverImpl(session, ScopeSession())
|
private val samResolver: FirSamResolver = FirSamResolver(session, ScopeSession())
|
||||||
|
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
Normal, DelegatedPropertyCompletion
|
Normal, DelegatedPropertyCompletion
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
override val syntheticCallGenerator: FirSyntheticCallGenerator = FirSyntheticCallGenerator(this)
|
override val syntheticCallGenerator: FirSyntheticCallGenerator = FirSyntheticCallGenerator(this)
|
||||||
override val doubleColonExpressionResolver: FirDoubleColonExpressionResolver = FirDoubleColonExpressionResolver(session)
|
override val doubleColonExpressionResolver: FirDoubleColonExpressionResolver = FirDoubleColonExpressionResolver(session)
|
||||||
override val outerClassManager: FirOuterClassManager = FirOuterClassManager(session, context.outerLocalClassForNested)
|
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 =
|
override val integerLiteralAndOperatorApproximationTransformer: IntegerLiteralAndOperatorApproximationTransformer =
|
||||||
IntegerLiteralAndOperatorApproximationTransformer(session, scopeSession)
|
IntegerLiteralAndOperatorApproximationTransformer(session, scopeSession)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user