@@ -1568,7 +1568,7 @@ open class KotlinFileExtractor(
1568
1568
}
1569
1569
}
1570
1570
1571
- private fun findFunction (cls : IrClass , name : String ): IrFunction ? = cls.declarations.find { it is IrFunction && it .name.asString() == name } as IrFunction ?
1571
+ private fun findFunction (cls : IrClass , name : String ): IrFunction ? = cls.declarations.findSubType< IrDeclaration , IrFunction > { it.name.asString() == name }
1572
1572
1573
1573
val jvmIntrinsicsClass by lazy {
1574
1574
val result = pluginContext.referenceClass(FqName (" kotlin.jvm.internal.Intrinsics" ))?.owner
@@ -1625,22 +1625,21 @@ open class KotlinFileExtractor(
1625
1625
}
1626
1626
1627
1627
val stringValueOfObjectMethod by lazy {
1628
- val result = javaLangString?.declarations?.find {
1629
- it is IrFunction &&
1628
+ val result = javaLangString?.declarations?.findSubType<IrDeclaration ,IrFunction > {
1630
1629
it.name.asString() == " valueOf" &&
1631
1630
it.valueParameters.size == 1 &&
1632
1631
it.valueParameters[0 ].type == pluginContext.irBuiltIns.anyNType
1633
- } as IrFunction ?
1632
+ }
1634
1633
if (result == null ) {
1635
1634
logger.error(" Couldn't find declaration java.lang.String.valueOf(Object)" )
1636
1635
}
1637
1636
result
1638
1637
}
1639
1638
1640
1639
val objectCloneMethod by lazy {
1641
- val result = javaLangObject?.declarations?.find {
1642
- it is IrFunction && it .name.asString() == " clone"
1643
- } as IrFunction ?
1640
+ val result = javaLangObject?.declarations?.findSubType< IrDeclaration , IrFunction > {
1641
+ it.name.asString() == " clone"
1642
+ }
1644
1643
if (result == null ) {
1645
1644
logger.error(" Couldn't find declaration java.lang.Object.clone(...)" )
1646
1645
}
@@ -1654,10 +1653,9 @@ open class KotlinFileExtractor(
1654
1653
}
1655
1654
1656
1655
val kotlinNoWhenBranchMatchedConstructor by lazy {
1657
- val result = kotlinNoWhenBranchMatchedExn?.declarations?.find {
1658
- it is IrConstructor &&
1656
+ val result = kotlinNoWhenBranchMatchedExn?.declarations?.findSubType<IrDeclaration ,IrConstructor > {
1659
1657
it.valueParameters.isEmpty()
1660
- } as IrConstructor ?
1658
+ }
1661
1659
if (result == null ) {
1662
1660
logger.error(" Couldn't find no-arg constructor for kotlin.NoWhenBranchMatchedException" )
1663
1661
}
@@ -1777,13 +1775,13 @@ open class KotlinFileExtractor(
1777
1775
return
1778
1776
}
1779
1777
1780
- val func = ((c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.find { it is IrFunction && it.name.asString() == fnName }
1778
+ val func = ((c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.findSubType< IrDeclaration , IrFunction > { it.name.asString() == fnName }
1781
1779
if (func == null ) {
1782
1780
logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1783
1781
return
1784
1782
}
1785
1783
1786
- extractMethodAccess(func as IrFunction , false )
1784
+ extractMethodAccess(func, false )
1787
1785
}
1788
1786
1789
1787
fun binopReceiver (id : Label <out DbExpr >, receiver : IrExpression ? , receiverDescription : String ) {
@@ -2227,10 +2225,10 @@ open class KotlinFileExtractor(
2227
2225
logger.errorElement(" Argument to dataClassArrayMemberToString not a class" , c)
2228
2226
return
2229
2227
}
2230
- val realCallee = javaUtilArrays?.declarations?.find { decl ->
2231
- decl is IrFunction && decl .name.asString() == " toString" && decl.valueParameters.size == 1 &&
2228
+ val realCallee = javaUtilArrays?.declarations?.findSubType< IrDeclaration , IrFunction > { decl ->
2229
+ decl.name.asString() == " toString" && decl.valueParameters.size == 1 &&
2232
2230
decl.valueParameters[0 ].type.classOrNull?.let { it == realArrayClass } == true
2233
- } as IrFunction ?
2231
+ }
2234
2232
if (realCallee == null ) {
2235
2233
logger.errorElement(" Couldn't find a java.lang.Arrays.toString method matching class ${realArrayClass.owner.name} " , c)
2236
2234
} else {
@@ -2254,10 +2252,10 @@ open class KotlinFileExtractor(
2254
2252
logger.errorElement(" Argument to dataClassArrayMemberHashCode not a class" , c)
2255
2253
return
2256
2254
}
2257
- val realCallee = javaUtilArrays?.declarations?.find { decl ->
2258
- decl is IrFunction && decl .name.asString() == " hashCode" && decl.valueParameters.size == 1 &&
2255
+ val realCallee = javaUtilArrays?.declarations?.findSubType< IrDeclaration , IrFunction > { decl ->
2256
+ decl.name.asString() == " hashCode" && decl.valueParameters.size == 1 &&
2259
2257
decl.valueParameters[0 ].type.classOrNull?.let { it == realArrayClass } == true
2260
- } as IrFunction ?
2258
+ }
2261
2259
if (realCallee == null ) {
2262
2260
logger.errorElement(" Couldn't find a java.lang.Arrays.hashCode method matching class ${realArrayClass.owner.name} " , c)
2263
2261
} else {
@@ -4365,7 +4363,7 @@ open class KotlinFileExtractor(
4365
4363
return
4366
4364
}
4367
4365
4368
- val invokeMethod = functionType.classOrNull?.owner?.declarations?.filterIsInstance< IrFunction >()?.find { it.name.asString() == OperatorNameConventions .INVOKE .asString()}
4366
+ val invokeMethod = functionType.classOrNull?.owner?.declarations?.findSubType< IrDeclaration , IrFunction > { it.name.asString() == OperatorNameConventions .INVOKE .asString()}
4369
4367
if (invokeMethod == null ) {
4370
4368
logger.errorElement(" Couldn't find `invoke` method on functional interface." , e)
4371
4369
return
@@ -4376,7 +4374,7 @@ open class KotlinFileExtractor(
4376
4374
logger.errorElement(" Expected to find SAM conversion to IrClass. Found '${typeOwner.javaClass} ' instead. Can't implement SAM interface." , e)
4377
4375
return
4378
4376
}
4379
- val samMember = typeOwner.declarations.filterIsInstance< IrFunction >().find { it is IrOverridableMember && it.modality == Modality .ABSTRACT }
4377
+ val samMember = typeOwner.declarations.findSubType< IrDeclaration , IrFunction > { it is IrOverridableMember && it.modality == Modality .ABSTRACT }
4380
4378
if (samMember == null ) {
4381
4379
logger.errorElement(" Couldn't find SAM member in type '${typeOwner.kotlinFqName.asString()} '. Can't implement SAM interface." , e)
4382
4380
return
@@ -4565,7 +4563,7 @@ open class KotlinFileExtractor(
4565
4563
val superCallId = tw.getFreshIdLabel<DbSuperconstructorinvocationstmt >()
4566
4564
tw.writeStmts_superconstructorinvocationstmt(superCallId, constructorBlockId, 0 , ids.constructor )
4567
4565
4568
- val baseConstructor = baseClass.owner.declarations.find { it is IrFunction && it.symbol is IrConstructorSymbol }
4566
+ val baseConstructor = baseClass.owner.declarations.findSubType< IrDeclaration , IrFunction > { it.symbol is IrConstructorSymbol }
4569
4567
val baseConstructorId = useFunction<DbConstructor >(baseConstructor as IrFunction )
4570
4568
4571
4569
tw.writeHasLocation(superCallId, locId)
0 commit comments