@@ -1903,11 +1903,7 @@ open class KotlinFileExtractor(
1903
1903
tw.writeCallableBinding(id, methodLabel)
1904
1904
}
1905
1905
1906
- private val defaultConstructorMarkerClass by lazy {
1907
- val result = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.DefaultConstructorMarker" ))?.owner
1908
- result?.let { extractExternalClassLater(it) }
1909
- result
1910
- }
1906
+ private val defaultConstructorMarkerClass by lazy { referenceExternalClass(" kotlin.jvm.internal.DefaultConstructorMarker" ) }
1911
1907
1912
1908
private val defaultConstructorMarkerType by lazy {
1913
1909
defaultConstructorMarkerClass?.typeWith()
@@ -2269,11 +2265,7 @@ open class KotlinFileExtractor(
2269
2265
2270
2266
private fun findFunction (cls : IrClass , name : String ): IrFunction ? = cls.declarations.findSubType<IrFunction > { it.name.asString() == name }
2271
2267
2272
- val jvmIntrinsicsClass by lazy {
2273
- val result = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.Intrinsics" ))?.owner
2274
- result?.let { extractExternalClassLater(it) }
2275
- result
2276
- }
2268
+ val jvmIntrinsicsClass by lazy { referenceExternalClass(" kotlin.jvm.internal.Intrinsics" ) }
2277
2269
2278
2270
private fun findJdkIntrinsicOrWarn (name : String , warnAgainstElement : IrElement ): IrFunction ? {
2279
2271
val result = jvmIntrinsicsClass?.let { findFunction(it, name) }
@@ -2319,11 +2311,7 @@ open class KotlinFileExtractor(
2319
2311
return prop
2320
2312
}
2321
2313
2322
- val javaLangString by lazy {
2323
- val result = pluginContext.referenceClass(FqName (" java.lang.String" ))?.owner
2324
- result?.let { extractExternalClassLater(it) }
2325
- result
2326
- }
2314
+ val javaLangString by lazy { referenceExternalClass(" java.lang.String" ) }
2327
2315
2328
2316
val stringValueOfObjectMethod by lazy {
2329
2317
val result = javaLangString?.declarations?.findSubType<IrFunction > {
@@ -2347,11 +2335,7 @@ open class KotlinFileExtractor(
2347
2335
result
2348
2336
}
2349
2337
2350
- val kotlinNoWhenBranchMatchedExn by lazy {
2351
- val result = pluginContext.referenceClass(FqName (" kotlin.NoWhenBranchMatchedException" ))?.owner
2352
- result?.let { extractExternalClassLater(it) }
2353
- result
2354
- }
2338
+ val kotlinNoWhenBranchMatchedExn by lazy {referenceExternalClass(" kotlin.NoWhenBranchMatchedException" ) }
2355
2339
2356
2340
val kotlinNoWhenBranchMatchedConstructor by lazy {
2357
2341
val result = kotlinNoWhenBranchMatchedExn?.declarations?.findSubType<IrConstructor > {
@@ -2363,11 +2347,7 @@ open class KotlinFileExtractor(
2363
2347
result
2364
2348
}
2365
2349
2366
- val javaUtilArrays by lazy {
2367
- val result = pluginContext.referenceClass(FqName (" java.util.Arrays" ))?.owner
2368
- result?.let { extractExternalClassLater(it) }
2369
- result
2370
- }
2350
+ val javaUtilArrays by lazy { referenceExternalClass(" java.util.Arrays" ) }
2371
2351
2372
2352
private fun isFunction (target : IrFunction , pkgName : String , classNameLogged : String , classNamePredicate : (String ) -> Boolean , vararg fNames : String , isNullable : Boolean? = false) =
2373
2353
fNames.any { isFunction(target, pkgName, classNameLogged, classNamePredicate, it, isNullable) }
@@ -4633,6 +4613,8 @@ open class KotlinFileExtractor(
4633
4613
}
4634
4614
}
4635
4615
4616
+ private val propertyRefType by lazy { referenceExternalClass(" kotlin.jvm.internal.PropertyReference" )?.typeWith() }
4617
+
4636
4618
private fun extractPropertyReference (
4637
4619
exprKind : String ,
4638
4620
propertyReferenceExpr : IrCallableReference <out IrSymbol >,
@@ -4696,8 +4678,7 @@ open class KotlinFileExtractor(
4696
4678
4697
4679
val declarationParent = peekDeclStackAsDeclarationParent(propertyReferenceExpr) ? : return
4698
4680
// The base class could be `Any`. `PropertyReference` is used to keep symmetry with function references.
4699
- val baseClass = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.PropertyReference" ))?.owner?.typeWith()
4700
- ? : pluginContext.irBuiltIns.anyType
4681
+ val baseClass = propertyRefType ? : pluginContext.irBuiltIns.anyType
4701
4682
4702
4683
val classId = extractGeneratedClass(ids, listOf (baseClass, kPropertyType), locId, propertyReferenceExpr, declarationParent)
4703
4684
@@ -4791,6 +4772,8 @@ open class KotlinFileExtractor(
4791
4772
}
4792
4773
}
4793
4774
4775
+ private val functionRefType by lazy { referenceExternalClass(" kotlin.jvm.internal.FunctionReference" )?.typeWith() }
4776
+
4794
4777
private fun extractFunctionReference (
4795
4778
functionReferenceExpr : IrFunctionReference ,
4796
4779
parent : StmtExprParent ,
@@ -4905,8 +4888,7 @@ open class KotlinFileExtractor(
4905
4888
} else {
4906
4889
val declarationParent = peekDeclStackAsDeclarationParent(functionReferenceExpr) ? : return
4907
4890
// `FunctionReference` base class is required, because that's implementing `KFunction`.
4908
- val baseClass = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.FunctionReference" ))?.owner?.typeWith()
4909
- ? : pluginContext.irBuiltIns.anyType
4891
+ val baseClass = functionRefType ? : pluginContext.irBuiltIns.anyType
4910
4892
4911
4893
val classId = extractGeneratedClass(ids, listOf (baseClass, fnInterfaceType), locId, functionReferenceExpr, declarationParent, null , { it.valueParameters.size == 1 }) {
4912
4894
// The argument to FunctionReference's constructor is the function arity.
@@ -4952,34 +4934,14 @@ open class KotlinFileExtractor(
4952
4934
}
4953
4935
}
4954
4936
4955
- private fun getFunctionalInterfaceType (functionNTypeArguments : List <IrType >): IrSimpleType ? {
4956
- if (functionNTypeArguments.size > BuiltInFunctionArity .BIG_ARITY ) {
4957
- val funName = " kotlin.jvm.functions.FunctionN"
4958
- val theFun = pluginContext.referenceClass(FqName (funName))
4959
- if (theFun == null ) {
4960
- logger.warn(" Cannot find $funName for getFunctionalInterfaceType" )
4961
- return null
4962
- } else {
4963
- return theFun.typeWith(functionNTypeArguments.last())
4964
- }
4965
- } else {
4966
- return functionN(pluginContext)(functionNTypeArguments.size - 1 ).typeWith(functionNTypeArguments)
4967
- }
4968
- }
4937
+ private fun getFunctionalInterfaceType (functionNTypeArguments : List <IrType >) =
4938
+ getFunctionalInterfaceTypeWithTypeArgs(functionNTypeArguments.map { makeTypeProjection(it, Variance .INVARIANT ) })
4969
4939
4970
- private fun getFunctionalInterfaceTypeWithTypeArgs (functionNTypeArguments : List <IrTypeArgument >): IrSimpleType ? =
4971
- if (functionNTypeArguments.size > BuiltInFunctionArity .BIG_ARITY ) {
4972
- val funName = " kotlin.jvm.functions.FunctionN"
4973
- val theFun = pluginContext.referenceClass(FqName (funName))
4974
- if (theFun == null ) {
4975
- logger.warn(" Cannot find $funName for getFunctionalInterfaceTypeWithTypeArgs" )
4976
- null
4977
- } else {
4978
- theFun.typeWithArguments(listOf (functionNTypeArguments.last()))
4979
- }
4980
- } else {
4940
+ private fun getFunctionalInterfaceTypeWithTypeArgs (functionNTypeArguments : List <IrTypeArgument >) =
4941
+ if (functionNTypeArguments.size > BuiltInFunctionArity .BIG_ARITY )
4942
+ referenceExternalClass(" kotlin.jvm.functions.FunctionN" )?.symbol?.typeWithArguments(listOf (functionNTypeArguments.last()))
4943
+ else
4981
4944
functionN(pluginContext)(functionNTypeArguments.size - 1 ).symbol.typeWithArguments(functionNTypeArguments)
4982
- }
4983
4945
4984
4946
private data class FunctionLabels (
4985
4947
val methodId : Label <DbMethod >,
0 commit comments