[FIR] Consistently use _function_ instead of _functional_ in names of classes and functions
This commit is contained in:
committed by
Space Team
parent
f268ab8858
commit
89c42e20c9
+6
-6
@@ -9,19 +9,19 @@ import org.jetbrains.kotlin.builtins.CompanionObjectMapping
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.FqNames
|
||||
import org.jetbrains.kotlin.builtins.functions.BuiltInFunctionArity
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
|
||||
object JavaToKotlinClassMap {
|
||||
private val NUMBERED_FUNCTION_PREFIX: String =
|
||||
FunctionalTypeKind.Function.packageFqName.toString() + "." + FunctionalTypeKind.Function.classNamePrefix
|
||||
FunctionTypeKind.Function.packageFqName.toString() + "." + FunctionTypeKind.Function.classNamePrefix
|
||||
private val NUMBERED_K_FUNCTION_PREFIX: String =
|
||||
FunctionalTypeKind.KFunction.packageFqName.toString() + "." + FunctionalTypeKind.KFunction.classNamePrefix
|
||||
FunctionTypeKind.KFunction.packageFqName.toString() + "." + FunctionTypeKind.KFunction.classNamePrefix
|
||||
private val NUMBERED_SUSPEND_FUNCTION_PREFIX: String =
|
||||
FunctionalTypeKind.SuspendFunction.packageFqName.toString() + "." + FunctionalTypeKind.SuspendFunction.classNamePrefix
|
||||
FunctionTypeKind.SuspendFunction.packageFqName.toString() + "." + FunctionTypeKind.SuspendFunction.classNamePrefix
|
||||
private val NUMBERED_K_SUSPEND_FUNCTION_PREFIX: String =
|
||||
FunctionalTypeKind.KSuspendFunction.packageFqName.toString() + "." + FunctionalTypeKind.KSuspendFunction.classNamePrefix
|
||||
FunctionTypeKind.KSuspendFunction.packageFqName.toString() + "." + FunctionTypeKind.KSuspendFunction.classNamePrefix
|
||||
|
||||
private val FUNCTION_N_CLASS_ID: ClassId = ClassId.topLevel(FqName("kotlin.jvm.functions.FunctionN"))
|
||||
val FUNCTION_N_FQ_NAME: FqName = FUNCTION_N_CLASS_ID.asSingleFqName()
|
||||
@@ -97,7 +97,7 @@ object JavaToKotlinClassMap {
|
||||
addKotlinToJava(FqName(NUMBERED_K_FUNCTION_PREFIX + i), K_FUNCTION_CLASS_ID)
|
||||
}
|
||||
for (i in 0 until BuiltInFunctionArity.BIG_ARITY - 1) {
|
||||
val kSuspendFunction = FunctionalTypeKind.KSuspendFunction
|
||||
val kSuspendFunction = FunctionTypeKind.KSuspendFunction
|
||||
val kSuspendFun = kSuspendFunction.packageFqName.toString() + "." + kSuspendFunction.classNamePrefix
|
||||
addKotlinToJava(FqName(kSuspendFun + i), K_FUNCTION_CLASS_ID)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.FqNames.reflect
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
@@ -252,7 +252,7 @@ object StandardNames {
|
||||
|
||||
@JvmStatic
|
||||
fun getKFunctionFqName(parameterCount: Int): FqNameUnsafe {
|
||||
return reflect(FunctionalTypeKind.KFunction.classNamePrefix + parameterCount)
|
||||
return reflect(FunctionTypeKind.KFunction.classNamePrefix + parameterCount)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -263,7 +263,7 @@ object StandardNames {
|
||||
|
||||
@JvmStatic
|
||||
fun getSuspendFunctionName(parameterCount: Int): String {
|
||||
return FunctionalTypeKind.SuspendFunction.classNamePrefix + parameterCount
|
||||
return FunctionTypeKind.SuspendFunction.classNamePrefix + parameterCount
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -273,7 +273,7 @@ object StandardNames {
|
||||
|
||||
@JvmStatic
|
||||
fun getKSuspendFunctionName(parameterCount: Int): FqNameUnsafe {
|
||||
return reflect(FunctionalTypeKind.KSuspendFunction.classNamePrefix + parameterCount)
|
||||
return reflect(FunctionTypeKind.KSuspendFunction.classNamePrefix + parameterCount)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
+21
-21
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
/**
|
||||
* [FunctionalTypeKind] describes a family of various similar functional types (like kotlin.FunctionN)
|
||||
* [FunctionTypeKind] describes a family of various similar functional types (like kotlin.FunctionN)
|
||||
* All types in the same family have corresponding shape of classId: [packageFqName].[classNamePrefix]N,
|
||||
* where `N` is an arity of function
|
||||
*
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
* Note that if you provide some new functional type kind it's your responsibility to handle all references to it in backend
|
||||
* with [IrGenerationExtension] implementation
|
||||
*/
|
||||
abstract class FunctionalTypeKind internal constructor(
|
||||
abstract class FunctionTypeKind internal constructor(
|
||||
val packageFqName: FqName,
|
||||
val classNamePrefix: String,
|
||||
val isReflectType: Boolean,
|
||||
@@ -69,7 +69,7 @@ abstract class FunctionalTypeKind internal constructor(
|
||||
*
|
||||
* Should be overridden for reflect kinds
|
||||
*/
|
||||
open fun nonReflectKind(): FunctionalTypeKind {
|
||||
open fun nonReflectKind(): FunctionTypeKind {
|
||||
return if (isReflectType) error("Should be overridden explicitly") else this
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ abstract class FunctionalTypeKind internal constructor(
|
||||
*
|
||||
* Should be overridden for non reflect kinds
|
||||
*/
|
||||
open fun reflectKind(): FunctionalTypeKind {
|
||||
open fun reflectKind(): FunctionTypeKind {
|
||||
return if (isReflectType) this else error("Should be overridden explicitly")
|
||||
}
|
||||
|
||||
@@ -93,16 +93,16 @@ abstract class FunctionalTypeKind internal constructor(
|
||||
|
||||
// ------------------------------------------- Builtin functional kinds -------------------------------------------
|
||||
|
||||
object Function : FunctionalTypeKind(
|
||||
object Function : FunctionTypeKind(
|
||||
StandardNames.BUILT_INS_PACKAGE_FQ_NAME,
|
||||
"Function",
|
||||
isReflectType = false,
|
||||
annotationOnInvokeClassId = null
|
||||
) {
|
||||
override fun reflectKind(): FunctionalTypeKind = KFunction
|
||||
override fun reflectKind(): FunctionTypeKind = KFunction
|
||||
}
|
||||
|
||||
object SuspendFunction : FunctionalTypeKind(
|
||||
object SuspendFunction : FunctionTypeKind(
|
||||
StandardNames.COROUTINES_PACKAGE_FQ_NAME,
|
||||
"SuspendFunction",
|
||||
isReflectType = false,
|
||||
@@ -111,39 +111,39 @@ abstract class FunctionalTypeKind internal constructor(
|
||||
override val prefixForTypeRender: String
|
||||
get() = "suspend"
|
||||
|
||||
override fun reflectKind(): FunctionalTypeKind = KSuspendFunction
|
||||
override fun reflectKind(): FunctionTypeKind = KSuspendFunction
|
||||
}
|
||||
|
||||
object KFunction : FunctionalTypeKind(
|
||||
object KFunction : FunctionTypeKind(
|
||||
StandardNames.KOTLIN_REFLECT_FQ_NAME,
|
||||
"KFunction",
|
||||
isReflectType = true,
|
||||
annotationOnInvokeClassId = null
|
||||
) {
|
||||
override fun nonReflectKind(): FunctionalTypeKind = Function
|
||||
override fun nonReflectKind(): FunctionTypeKind = Function
|
||||
}
|
||||
|
||||
object KSuspendFunction : FunctionalTypeKind(
|
||||
object KSuspendFunction : FunctionTypeKind(
|
||||
StandardNames.KOTLIN_REFLECT_FQ_NAME,
|
||||
"KSuspendFunction",
|
||||
isReflectType = true,
|
||||
annotationOnInvokeClassId = null
|
||||
) {
|
||||
override fun nonReflectKind(): FunctionalTypeKind = SuspendFunction
|
||||
override fun nonReflectKind(): FunctionTypeKind = SuspendFunction
|
||||
}
|
||||
}
|
||||
|
||||
val FunctionalTypeKind.isBuiltin: Boolean
|
||||
val FunctionTypeKind.isBuiltin: Boolean
|
||||
get() = when (this) {
|
||||
FunctionalTypeKind.Function,
|
||||
FunctionalTypeKind.SuspendFunction,
|
||||
FunctionalTypeKind.KFunction,
|
||||
FunctionalTypeKind.KSuspendFunction -> true
|
||||
FunctionTypeKind.Function,
|
||||
FunctionTypeKind.SuspendFunction,
|
||||
FunctionTypeKind.KFunction,
|
||||
FunctionTypeKind.KSuspendFunction -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
val FunctionalTypeKind.isSuspendType: Boolean
|
||||
get() = this.nonReflectKind() == FunctionalTypeKind.SuspendFunction
|
||||
val FunctionTypeKind.isSuspendOrKSuspendFunction: Boolean
|
||||
get() = this.nonReflectKind() == FunctionTypeKind.SuspendFunction
|
||||
|
||||
val FunctionalTypeKind.isRegularFunction: Boolean
|
||||
get() = this.nonReflectKind() == FunctionalTypeKind.Function
|
||||
val FunctionTypeKind.isBasicFunctionOrKFunction: Boolean
|
||||
get() = this.nonReflectKind() == FunctionTypeKind.Function
|
||||
+8
-8
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
@RequiresOptIn
|
||||
annotation class AllowedToUsedOnlyInK1
|
||||
|
||||
class FunctionalTypeKindExtractor(kinds: List<FunctionalTypeKind>) {
|
||||
class FunctionTypeKindExtractor(kinds: List<FunctionTypeKind>) {
|
||||
companion object {
|
||||
/**
|
||||
* This instance should be used only in:
|
||||
@@ -19,19 +19,19 @@ class FunctionalTypeKindExtractor(kinds: List<FunctionalTypeKind>) {
|
||||
*/
|
||||
@JvmStatic
|
||||
@AllowedToUsedOnlyInK1
|
||||
val Default = FunctionalTypeKindExtractor(
|
||||
val Default = FunctionTypeKindExtractor(
|
||||
listOf(
|
||||
FunctionalTypeKind.Function,
|
||||
FunctionalTypeKind.SuspendFunction,
|
||||
FunctionalTypeKind.KFunction,
|
||||
FunctionalTypeKind.KSuspendFunction,
|
||||
FunctionTypeKind.Function,
|
||||
FunctionTypeKind.SuspendFunction,
|
||||
FunctionTypeKind.KFunction,
|
||||
FunctionTypeKind.KSuspendFunction,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private val knownKindsByPackageFqName = kinds.groupBy { it.packageFqName }
|
||||
|
||||
fun getFunctionalClassKind(packageFqName: FqName, className: String): FunctionalTypeKind? {
|
||||
fun getFunctionalClassKind(packageFqName: FqName, className: String): FunctionTypeKind? {
|
||||
return getFunctionalClassKindWithArity(packageFqName, className)?.kind
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class FunctionalTypeKindExtractor(kinds: List<FunctionalTypeKind>) {
|
||||
return packageFqName in knownKindsByPackageFqName
|
||||
}
|
||||
|
||||
data class KindWithArity(val kind: FunctionalTypeKind, val arity: Int)
|
||||
data class KindWithArity(val kind: FunctionTypeKind, val arity: Int)
|
||||
|
||||
private fun toInt(s: String): Int? {
|
||||
if (s.isEmpty()) return null
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types.model
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeInfo
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -165,7 +165,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
|
||||
fun KotlinTypeMarker.isUnit(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.isBuiltinFunctionalTypeOrSubtype(): Boolean
|
||||
fun KotlinTypeMarker.isBuiltinFunctionTypeOrSubtype(): Boolean
|
||||
|
||||
fun createCapturedType(
|
||||
constructorProjection: TypeArgumentMarker,
|
||||
@@ -252,17 +252,17 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
|
||||
fun KotlinTypeMarker.isFunctionOrKFunctionWithAnySuspendability(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.functionalTypeKind(): FunctionalTypeKind?
|
||||
fun KotlinTypeMarker.functionTypeKind(): FunctionTypeKind?
|
||||
|
||||
fun KotlinTypeMarker.isExtensionFunctionType(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker>
|
||||
fun KotlinTypeMarker.extractArgumentsForFunctionTypeOrSubtype(): List<KotlinTypeMarker>
|
||||
|
||||
fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker
|
||||
fun KotlinTypeMarker.getFunctionTypeFromSupertypes(): KotlinTypeMarker
|
||||
|
||||
fun getNonReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionalTypeKind): TypeConstructorMarker
|
||||
fun getNonReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionTypeKind): TypeConstructorMarker
|
||||
|
||||
fun getReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionalTypeKind): TypeConstructorMarker
|
||||
fun getReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionTypeKind): TypeConstructorMarker
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory;
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind;
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.AdditionalClassPartsProvider;
|
||||
@@ -315,7 +315,7 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getKSuspendFunction(int parameterCount) {
|
||||
Name name = Name.identifier(FunctionalTypeKind.KSuspendFunction.INSTANCE.getClassNamePrefix() + parameterCount);
|
||||
Name name = Name.identifier(FunctionTypeKind.KSuspendFunction.INSTANCE.getClassNamePrefix() + parameterCount);
|
||||
return getBuiltInClassByFqName(COROUTINES_PACKAGE_FQ_NAME.child(name));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
package org.jetbrains.kotlin.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.BUILT_INS_PACKAGE_NAME
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKindExtractor
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKindExtractor
|
||||
import org.jetbrains.kotlin.builtins.functions.AllowedToUsedOnlyInK1
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -59,20 +59,20 @@ val KotlinType.isBuiltinFunctionalTypeOrSubtype: Boolean
|
||||
fun KotlinType.isFunctionTypeOrSubtype(predicate: (KotlinType) -> Boolean): Boolean =
|
||||
isTypeOrSubtypeOf { it.isFunctionType && predicate(it) }
|
||||
|
||||
val KotlinType.functionalTypeKind: FunctionalTypeKind?
|
||||
get() = constructor.declarationDescriptor?.getFunctionalClassKind()
|
||||
val KotlinType.functionTypeKind: FunctionTypeKind?
|
||||
get() = constructor.declarationDescriptor?.getFunctionTypeKind()
|
||||
|
||||
val KotlinType.isFunctionType: Boolean
|
||||
get() = functionalTypeKind == FunctionalTypeKind.Function
|
||||
get() = functionTypeKind == FunctionTypeKind.Function
|
||||
|
||||
val KotlinType.isKFunctionType: Boolean
|
||||
get() = functionalTypeKind == FunctionalTypeKind.KFunction
|
||||
get() = functionTypeKind == FunctionTypeKind.KFunction
|
||||
|
||||
val KotlinType.isSuspendFunctionType: Boolean
|
||||
get() = functionalTypeKind == FunctionalTypeKind.SuspendFunction
|
||||
get() = functionTypeKind == FunctionTypeKind.SuspendFunction
|
||||
|
||||
val KotlinType.isKSuspendFunctionType: Boolean
|
||||
get() = functionalTypeKind == FunctionalTypeKind.KSuspendFunction
|
||||
get() = functionTypeKind == FunctionTypeKind.KSuspendFunction
|
||||
|
||||
val KotlinType.isFunctionOrSuspendFunctionType: Boolean
|
||||
get() = isFunctionType || isSuspendFunctionType
|
||||
@@ -85,17 +85,17 @@ val KotlinType.isBuiltinFunctionalType: Boolean
|
||||
|
||||
val DeclarationDescriptor.isBuiltinFunctionalClassDescriptor: Boolean
|
||||
get() {
|
||||
val functionalClassKind = getFunctionalClassKind()
|
||||
return functionalClassKind == FunctionalTypeKind.Function ||
|
||||
functionalClassKind == FunctionalTypeKind.SuspendFunction
|
||||
val functionalClassKind = getFunctionTypeKind()
|
||||
return functionalClassKind == FunctionTypeKind.Function ||
|
||||
functionalClassKind == FunctionTypeKind.SuspendFunction
|
||||
}
|
||||
|
||||
fun isBuiltinFunctionClass(classId: ClassId): Boolean {
|
||||
if (!classId.startsWith(StandardNames.BUILT_INS_PACKAGE_NAME)) return false
|
||||
|
||||
val kind = classId.asSingleFqName().toUnsafe().getFunctionalClassKind()
|
||||
return kind == FunctionalTypeKind.Function ||
|
||||
kind == FunctionalTypeKind.SuspendFunction
|
||||
val kind = classId.asSingleFqName().toUnsafe().getFunctionTypeKind()
|
||||
return kind == FunctionTypeKind.Function ||
|
||||
kind == FunctionTypeKind.SuspendFunction
|
||||
}
|
||||
|
||||
val KotlinType.isNonExtensionFunctionType: Boolean
|
||||
@@ -116,21 +116,21 @@ private val KotlinType.isTypeAnnotatedWithExtensionFunctionType: Boolean
|
||||
*/
|
||||
fun isNumberedFunctionClassFqName(fqName: FqNameUnsafe): Boolean {
|
||||
return fqName.startsWith(BUILT_INS_PACKAGE_NAME) &&
|
||||
fqName.getFunctionalClassKind() == FunctionalTypeKind.Function
|
||||
fqName.getFunctionTypeKind() == FunctionTypeKind.Function
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.getFunctionalClassKind(): FunctionalTypeKind? {
|
||||
fun DeclarationDescriptor.getFunctionTypeKind(): FunctionTypeKind? {
|
||||
if (this !is ClassDescriptor) return null
|
||||
if (!KotlinBuiltIns.isUnderKotlinPackage(this)) return null
|
||||
|
||||
return fqNameUnsafe.getFunctionalClassKind()
|
||||
return fqNameUnsafe.getFunctionTypeKind()
|
||||
}
|
||||
|
||||
@OptIn(AllowedToUsedOnlyInK1::class)
|
||||
private fun FqNameUnsafe.getFunctionalClassKind(): FunctionalTypeKind? {
|
||||
private fun FqNameUnsafe.getFunctionTypeKind(): FunctionTypeKind? {
|
||||
if (!isSafe || isRoot) return null
|
||||
|
||||
return FunctionalTypeKindExtractor.Default.getFunctionalClassKind(toSafe().parent(), shortName().asString())
|
||||
return FunctionTypeKindExtractor.Default.getFunctionalClassKind(toSafe().parent(), shortName().asString())
|
||||
}
|
||||
|
||||
fun KotlinType.contextFunctionTypeParamsCount(): Int {
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ class BuiltInFictitiousFunctionClassFactory(
|
||||
val string = name.asString()
|
||||
return (string.startsWith("Function") || string.startsWith("KFunction") ||
|
||||
string.startsWith("SuspendFunction") || string.startsWith("KSuspendFunction")) // an optimization
|
||||
&& FunctionalTypeKindExtractor.Default.getFunctionalClassKindWithArity(packageFqName, string) != null
|
||||
&& FunctionTypeKindExtractor.Default.getFunctionalClassKindWithArity(packageFqName, string) != null
|
||||
}
|
||||
|
||||
@OptIn(AllowedToUsedOnlyInK1::class)
|
||||
@@ -49,7 +49,7 @@ class BuiltInFictitiousFunctionClassFactory(
|
||||
if ("Function" !in className) return null // An optimization
|
||||
|
||||
val packageFqName = classId.packageFqName
|
||||
val (kind, arity) = FunctionalTypeKindExtractor.Default.getFunctionalClassKindWithArity(packageFqName, className) ?: return null
|
||||
val (kind, arity) = FunctionTypeKindExtractor.Default.getFunctionalClassKindWithArity(packageFqName, className) ?: return null
|
||||
|
||||
|
||||
val builtInsFragments = module.getPackage(packageFqName).fragments.filterIsInstance<BuiltInsPackageFragment>()
|
||||
|
||||
+10
-10
@@ -29,10 +29,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled
|
||||
* This allows to use both 'invoke' and reflection API on function references obtained by '::'.
|
||||
*/
|
||||
class FunctionClassDescriptor(
|
||||
private val storageManager: StorageManager,
|
||||
private val containingDeclaration: PackageFragmentDescriptor,
|
||||
val functionKind: FunctionalTypeKind,
|
||||
val arity: Int
|
||||
private val storageManager: StorageManager,
|
||||
private val containingDeclaration: PackageFragmentDescriptor,
|
||||
val functionKind: FunctionTypeKind,
|
||||
val arity: Int
|
||||
) : AbstractClassDescriptor(storageManager, functionKind.numberedClassName(arity)) {
|
||||
|
||||
private val typeConstructor = FunctionTypeConstructor()
|
||||
@@ -96,14 +96,14 @@ class FunctionClassDescriptor(
|
||||
override fun computeSupertypes(): Collection<KotlinType> {
|
||||
// For K{Suspend}Function{n}, add corresponding numbered {Suspend}Function{n} class, e.g. {Suspend}Function2 for K{Suspend}Function2
|
||||
val supertypes = when (functionKind) {
|
||||
FunctionalTypeKind.Function -> // Function$N <: Function
|
||||
FunctionTypeKind.Function -> // Function$N <: Function
|
||||
listOf(functionClassId)
|
||||
FunctionalTypeKind.KFunction -> // KFunction$N <: KFunction
|
||||
listOf(kFunctionClassId, ClassId(BUILT_INS_PACKAGE_FQ_NAME, FunctionalTypeKind.Function.numberedClassName(arity)))
|
||||
FunctionalTypeKind.SuspendFunction -> // SuspendFunction$N<...> <: Function
|
||||
FunctionTypeKind.KFunction -> // KFunction$N <: KFunction
|
||||
listOf(kFunctionClassId, ClassId(BUILT_INS_PACKAGE_FQ_NAME, FunctionTypeKind.Function.numberedClassName(arity)))
|
||||
FunctionTypeKind.SuspendFunction -> // SuspendFunction$N<...> <: Function
|
||||
listOf(functionClassId)
|
||||
FunctionalTypeKind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction
|
||||
listOf(kFunctionClassId, ClassId(COROUTINES_PACKAGE_FQ_NAME, FunctionalTypeKind.SuspendFunction.numberedClassName(arity)))
|
||||
FunctionTypeKind.KSuspendFunction -> // KSuspendFunction$N<...> <: KFunction
|
||||
listOf(kFunctionClassId, ClassId(COROUTINES_PACKAGE_FQ_NAME, FunctionTypeKind.SuspendFunction.numberedClassName(arity)))
|
||||
else -> shouldNotBeCalled()
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ class FunctionClassScope(
|
||||
) : GivenFunctionsMemberScope(storageManager, containingClass) {
|
||||
override fun computeDeclaredFunctions(): List<FunctionDescriptor> =
|
||||
when ((containingClass as FunctionClassDescriptor).functionKind) {
|
||||
FunctionalTypeKind.Function -> listOf(FunctionInvokeDescriptor.create(containingClass, isSuspend = false))
|
||||
FunctionalTypeKind.SuspendFunction -> listOf(FunctionInvokeDescriptor.create(containingClass, isSuspend = true))
|
||||
FunctionTypeKind.Function -> listOf(FunctionInvokeDescriptor.create(containingClass, isSuspend = false))
|
||||
FunctionTypeKind.SuspendFunction -> listOf(FunctionInvokeDescriptor.create(containingClass, isSuspend = true))
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.types.checker
|
||||
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.FqNames
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -411,7 +411,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return KotlinBuiltIns.isUnit(this)
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isBuiltinFunctionalTypeOrSubtype(): Boolean {
|
||||
override fun KotlinTypeMarker.isBuiltinFunctionTypeOrSubtype(): Boolean {
|
||||
require(this is UnwrappedType, this::errorMessage)
|
||||
return isBuiltinFunctionalTypeOrSubtype
|
||||
}
|
||||
@@ -855,34 +855,34 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return this.isBuiltinExtensionFunctionalType
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.extractArgumentsForFunctionalTypeOrSubtype(): List<KotlinTypeMarker> {
|
||||
override fun KotlinTypeMarker.extractArgumentsForFunctionTypeOrSubtype(): List<KotlinTypeMarker> {
|
||||
require(this is KotlinType, this::errorMessage)
|
||||
return this.getPureArgumentsForFunctionalTypeOrSubtype()
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker {
|
||||
override fun KotlinTypeMarker.getFunctionTypeFromSupertypes(): KotlinTypeMarker {
|
||||
require(this is KotlinType)
|
||||
return this.extractFunctionalTypeFromSupertypes()
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.functionalTypeKind(): FunctionalTypeKind? {
|
||||
override fun KotlinTypeMarker.functionTypeKind(): FunctionTypeKind? {
|
||||
require(this is KotlinType)
|
||||
return this.functionalTypeKind
|
||||
return this.functionTypeKind
|
||||
}
|
||||
|
||||
override fun getNonReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionalTypeKind): TypeConstructorMarker {
|
||||
override fun getNonReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionTypeKind): TypeConstructorMarker {
|
||||
return getFunctionDescriptor(
|
||||
builtIns,
|
||||
parametersNumber,
|
||||
isSuspendFunction = kind.nonReflectKind() == FunctionalTypeKind.SuspendFunction
|
||||
isSuspendFunction = kind.nonReflectKind() == FunctionTypeKind.SuspendFunction
|
||||
).typeConstructor
|
||||
}
|
||||
|
||||
override fun getReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionalTypeKind): TypeConstructorMarker {
|
||||
override fun getReflectFunctionTypeConstructor(parametersNumber: Int, kind: FunctionTypeKind): TypeConstructorMarker {
|
||||
return getKFunctionDescriptor(
|
||||
builtIns,
|
||||
parametersNumber,
|
||||
isSuspendFunction = kind.reflectKind() == FunctionalTypeKind.KSuspendFunction
|
||||
isSuspendFunction = kind.reflectKind() == FunctionTypeKind.KSuspendFunction
|
||||
).typeConstructor
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user