@@ -1584,7 +1584,7 @@ open class KotlinFileExtractor(
1584
1584
}
1585
1585
}
1586
1586
1587
- private fun findFunction (cls : IrClass , name : String ): IrFunction ? = cls.declarations.find { it is IrFunction && it .name.asString() == name } as IrFunction ?
1587
+ private fun findFunction (cls : IrClass , name : String ): IrFunction ? = cls.declarations.findSubType< IrFunction > { it.name.asString() == name }
1588
1588
1589
1589
val jvmIntrinsicsClass by lazy {
1590
1590
val result = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.Intrinsics" ))?.owner
@@ -1641,22 +1641,21 @@ open class KotlinFileExtractor(
1641
1641
}
1642
1642
1643
1643
val stringValueOfObjectMethod by lazy {
1644
- val result = javaLangString?.declarations?.find {
1645
- it is IrFunction &&
1644
+ val result = javaLangString?.declarations?.findSubType<IrFunction > {
1646
1645
it.name.asString() == " valueOf" &&
1647
1646
it.valueParameters.size == 1 &&
1648
1647
it.valueParameters[0 ].type == pluginContext.irBuiltIns.anyNType
1649
- } as IrFunction ?
1648
+ }
1650
1649
if (result == null ) {
1651
1650
logger.error(" Couldn't find declaration java.lang.String.valueOf(Object)" )
1652
1651
}
1653
1652
result
1654
1653
}
1655
1654
1656
1655
val objectCloneMethod by lazy {
1657
- val result = javaLangObject?.declarations?.find {
1658
- it is IrFunction && it .name.asString() == " clone"
1659
- } as IrFunction ?
1656
+ val result = javaLangObject?.declarations?.findSubType< IrFunction > {
1657
+ it.name.asString() == " clone"
1658
+ }
1660
1659
if (result == null ) {
1661
1660
logger.error(" Couldn't find declaration java.lang.Object.clone(...)" )
1662
1661
}
@@ -1670,10 +1669,9 @@ open class KotlinFileExtractor(
1670
1669
}
1671
1670
1672
1671
val kotlinNoWhenBranchMatchedConstructor by lazy {
1673
- val result = kotlinNoWhenBranchMatchedExn?.declarations?.find {
1674
- it is IrConstructor &&
1672
+ val result = kotlinNoWhenBranchMatchedExn?.declarations?.findSubType<IrConstructor > {
1675
1673
it.valueParameters.isEmpty()
1676
- } as IrConstructor ?
1674
+ }
1677
1675
if (result == null ) {
1678
1676
logger.error(" Couldn't find no-arg constructor for kotlin.NoWhenBranchMatchedException" )
1679
1677
}
@@ -1798,13 +1796,13 @@ open class KotlinFileExtractor(
1798
1796
return
1799
1797
}
1800
1798
1801
- val func = ((c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.find { it is IrFunction && it.name.asString() == fnName }
1799
+ val func = ((c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.findSubType< IrFunction > { it.name.asString() == fnName }
1802
1800
if (func == null ) {
1803
1801
logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1804
1802
return
1805
1803
}
1806
1804
1807
- extractMethodAccess(func as IrFunction , false )
1805
+ extractMethodAccess(func, false )
1808
1806
}
1809
1807
1810
1808
fun binopReceiver (id : Label <out DbExpr >, receiver : IrExpression ? , receiverDescription : String ) {
@@ -2273,10 +2271,10 @@ open class KotlinFileExtractor(
2273
2271
logger.errorElement(" Argument to dataClassArrayMemberToString not a class" , c)
2274
2272
return
2275
2273
}
2276
- val realCallee = javaUtilArrays?.declarations?.find { decl ->
2277
- decl is IrFunction && decl .name.asString() == " toString" && decl.valueParameters.size == 1 &&
2274
+ val realCallee = javaUtilArrays?.declarations?.findSubType< IrFunction > { decl ->
2275
+ decl.name.asString() == " toString" && decl.valueParameters.size == 1 &&
2278
2276
decl.valueParameters[0 ].type.classOrNull?.let { it == realArrayClass } == true
2279
- } as IrFunction ?
2277
+ }
2280
2278
if (realCallee == null ) {
2281
2279
logger.errorElement(" Couldn't find a java.lang.Arrays.toString method matching class ${realArrayClass.owner.name} " , c)
2282
2280
} else {
@@ -2300,10 +2298,10 @@ open class KotlinFileExtractor(
2300
2298
logger.errorElement(" Argument to dataClassArrayMemberHashCode not a class" , c)
2301
2299
return
2302
2300
}
2303
- val realCallee = javaUtilArrays?.declarations?.find { decl ->
2304
- decl is IrFunction && decl .name.asString() == " hashCode" && decl.valueParameters.size == 1 &&
2301
+ val realCallee = javaUtilArrays?.declarations?.findSubType< IrFunction > { decl ->
2302
+ decl.name.asString() == " hashCode" && decl.valueParameters.size == 1 &&
2305
2303
decl.valueParameters[0 ].type.classOrNull?.let { it == realArrayClass } == true
2306
- } as IrFunction ?
2304
+ }
2307
2305
if (realCallee == null ) {
2308
2306
logger.errorElement(" Couldn't find a java.lang.Arrays.hashCode method matching class ${realArrayClass.owner.name} " , c)
2309
2307
} else {
@@ -4452,7 +4450,7 @@ open class KotlinFileExtractor(
4452
4450
return
4453
4451
}
4454
4452
4455
- val invokeMethod = functionType.classOrNull?.owner?.declarations?.filterIsInstance <IrFunction >()?.find { it.name.asString() == OperatorNameConventions .INVOKE .asString()}
4453
+ val invokeMethod = functionType.classOrNull?.owner?.declarations?.findSubType <IrFunction > { it.name.asString() == OperatorNameConventions .INVOKE .asString()}
4456
4454
if (invokeMethod == null ) {
4457
4455
logger.errorElement(" Couldn't find `invoke` method on functional interface." , e)
4458
4456
return
@@ -4463,7 +4461,7 @@ open class KotlinFileExtractor(
4463
4461
logger.errorElement(" Expected to find SAM conversion to IrClass. Found '${typeOwner.javaClass} ' instead. Can't implement SAM interface." , e)
4464
4462
return
4465
4463
}
4466
- val samMember = typeOwner.declarations.filterIsInstance <IrFunction >().find { it is IrOverridableMember && it.modality == Modality .ABSTRACT }
4464
+ val samMember = typeOwner.declarations.findSubType <IrFunction > { it is IrOverridableMember && it.modality == Modality .ABSTRACT }
4467
4465
if (samMember == null ) {
4468
4466
logger.errorElement(" Couldn't find SAM member in type '${typeOwner.kotlinFqName.asString()} '. Can't implement SAM interface." , e)
4469
4467
return
@@ -4652,7 +4650,7 @@ open class KotlinFileExtractor(
4652
4650
val superCallId = tw.getFreshIdLabel<DbSuperconstructorinvocationstmt >()
4653
4651
tw.writeStmts_superconstructorinvocationstmt(superCallId, constructorBlockId, 0 , ids.constructor )
4654
4652
4655
- val baseConstructor = baseClass.owner.declarations.find { it is IrFunction && it.symbol is IrConstructorSymbol }
4653
+ val baseConstructor = baseClass.owner.declarations.findSubType< IrFunction > { it.symbol is IrConstructorSymbol }
4656
4654
val baseConstructorId = useFunction<DbConstructor >(baseConstructor as IrFunction )
4657
4655
4658
4656
tw.writeHasLocation(superCallId, locId)
0 commit comments