FIR IDE: API to determine if the given KtType is a functional interface type
This commit is contained in:
committed by
Ilya Kirillov
parent
b7a99eca55
commit
dca8789659
+7
@@ -12,10 +12,17 @@ import org.jetbrains.kotlin.idea.frontend.api.types.*
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
|
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
|
||||||
|
public abstract fun isFunctionalInterfaceType(type: KtType): Boolean
|
||||||
public abstract fun canBeNull(type: KtType): Boolean
|
public abstract fun canBeNull(type: KtType): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||||
|
/**
|
||||||
|
* Returns true if this type is a functional interface type, a.k.a. SAM type, e.g., Runnable.
|
||||||
|
*/
|
||||||
|
public val KtType.isFunctionalInterfaceType: Boolean
|
||||||
|
get() = analysisSession.typeInfoProvider.isFunctionalInterfaceType(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a public value of this type can potentially be null. This means this type is not a subtype of [Any]. However, it does not
|
* Returns true if a public value of this type can potentially be null. This means this type is not a subtype of [Any]. However, it does not
|
||||||
* mean one can assign `null` to a variable of this type because it may be unknown if this type can accept `null`. For example, a public value
|
* mean one can assign `null` to a variable of this type because it may be unknown if this type can accept `null`. For example, a public value
|
||||||
|
|||||||
+9
-1
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.frontend.api.fir.components
|
package org.jetbrains.kotlin.idea.frontend.api.fir.components
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.types.canBeNull
|
import org.jetbrains.kotlin.fir.types.canBeNull
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.components.KtTypeInfoProvider
|
import org.jetbrains.kotlin.idea.frontend.api.components.KtTypeInfoProvider
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
|
import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
|
||||||
@@ -17,5 +19,11 @@ internal class KtFirTypeInfoProvider(
|
|||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
) : KtTypeInfoProvider(), KtFirAnalysisSessionComponent {
|
) : KtTypeInfoProvider(), KtFirAnalysisSessionComponent {
|
||||||
|
|
||||||
|
override fun isFunctionalInterfaceType(type: KtType): Boolean {
|
||||||
|
val coneType = (type as KtFirType).coneType
|
||||||
|
val samResolver = FirSamResolverImpl(analysisSession.rootModuleSession, ScopeSession())
|
||||||
|
return samResolver.getFunctionTypeForPossibleSamType(coneType) != null
|
||||||
|
}
|
||||||
|
|
||||||
override fun canBeNull(type: KtType): Boolean = (type as KtFirType).coneType.canBeNull
|
override fun canBeNull(type: KtType): Boolean = (type as KtFirType).coneType.canBeNull
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user