FIR IDE: add APIs about FunctionClassKind

This commit is contained in:
Jinseong Jeon
2021-11-03 16:26:12 -07:00
committed by Ilya Kirillov
parent d029e84b96
commit 6d150fb7a5
16 changed files with 202 additions and 1 deletions
@@ -12,10 +12,12 @@ import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
import org.jetbrains.kotlin.name.ClassId
public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
public abstract fun isFunctionalInterfaceType(type: KtType): Boolean
public abstract fun getFunctionClassKind(type: KtType): FunctionClassKind?
public abstract fun canBeNull(type: KtType): Boolean
}
@@ -26,6 +28,24 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
public val KtType.isFunctionalInterfaceType: Boolean
get() = analysisSession.typeInfoProvider.isFunctionalInterfaceType(this)
/**
* Returns [FunctionClassKind] of the given [KtType]
*/
public val KtType.functionClassKind: FunctionClassKind?
get() = analysisSession.typeInfoProvider.getFunctionClassKind(this)
public val KtType.isFunctionType: Boolean
get() = functionClassKind == FunctionClassKind.Function
public val KtType.isKFunctionType: Boolean
get() = functionClassKind == FunctionClassKind.KFunction
public val KtType.isSuspendFunctionType: Boolean
get() = functionClassKind == FunctionClassKind.SuspendFunction
public val KtType.isKSuspendFunctionType: Boolean
get() = functionClassKind == FunctionClassKind.KSuspendFunction
/**
* 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
@@ -0,0 +1,7 @@
fun <T, R> foo(p: T, mapper : (T) -> R): R {
mapper(p)
}
fun bar() {
foo(1, x<caret>y)
}
@@ -0,0 +1,3 @@
expression: xy
expected type: (T) -> R
functionClassKind: Function
@@ -0,0 +1,11 @@
// WITH_REFLECT
import kotlin.reflect.KFunction1
fun <T, R> foo(p: T, mapper : (T) -> R): R {
mapper(p)
}
fun bar() {
foo(1, x<caret>y as KFunction1<Int, String>)
}
@@ -0,0 +1,3 @@
expression: xy
expected type: (kotlin.Int) -> kotlin.String
functionClassKind: KFunction
@@ -0,0 +1,11 @@
// WITH_REFLECT
import kotlin.reflect.KSuspendFunction0
fun foo(pause : suspend () -> Unit) {
pause()
}
fun bar() {
foo(x<caret>y as KSuspendFunction0<Unit>)
}
@@ -0,0 +1,3 @@
expression: xy
expected type: suspend () -> kotlin.Unit
functionClassKind: KSuspendFunction
@@ -0,0 +1,7 @@
fun foo(pause : suspend () -> Unit) {
pause()
}
fun bar() {
foo(x<caret>y)
}
@@ -0,0 +1,3 @@
expression: xy
expected type: suspend () -> kotlin.Unit
functionClassKind: SuspendFunction