Skip to content

Commit 2f1e5a5

Browse files
committed
Migrate to DeclarationFinder API
1 parent bed61cc commit 2f1e5a5

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

mokkery-plugin/src/main/kotlin/dev/mokkery/plugin/ir/IrReferencer.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,26 @@ class IrFunctionById(
2424
private val id: CallableId,
2525
private val predicate: (IrSimpleFunctionSymbol) -> Boolean = { true }
2626
) : IrFunctionReferencer {
27-
override fun reference(context: IrPluginContext): IrSimpleFunction = context.referenceFunctions(id).first(predicate).owner
27+
override fun reference(context: IrPluginContext): IrSimpleFunction = context.finderForBuiltins()
28+
.findFunctions(id)
29+
.find(predicate)
30+
?.owner
31+
?: runtimeDependencyError(id.toString())
2832
}
2933

3034
class IrClassById(private val id: ClassId) : IrClassReferencer {
31-
override fun reference(context: IrPluginContext): IrClass = context.referenceClass(id)!!.owner
35+
override fun reference(context: IrPluginContext): IrClass = context.finderForBuiltins()
36+
.findClass(id)
37+
?.owner
38+
?: runtimeDependencyError(id.toString())
3239
}
3340

3441
class IrPropertyById(private val id: CallableId) : IrPropertyReferencer {
35-
override fun reference(context: IrPluginContext): IrProperty = context.referenceProperties(id).first().owner
42+
override fun reference(context: IrPluginContext): IrProperty = context.finderForBuiltins()
43+
.findProperties(id)
44+
.firstOrNull()
45+
?.owner
46+
?: runtimeDependencyError(id.toString())
3647
}
48+
49+
private fun runtimeDependencyError(id: String): Nothing = error("Declaration $id could not be found!")

mokkery-plugin/src/main/kotlin/dev/mokkery/plugin/ir/transformer/mock/stubs/ArrayStubStrategy.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ object ArrayStubStrategy : StubStrategy {
2525
}
2626
return stub {
2727
val arrayFunc = pluginContext
28-
.referenceFunctions(CallableId(Kotlin.kotlin, Name.identifier(name)))
28+
.finderForBuiltins()
29+
.findFunctions(CallableId(Kotlin.kotlin, Name.identifier(name)))
2930
.first()
3031
scope.builder.irCall(arrayFunc) {
3132
val typeArgs = (type as IrSimpleType).arguments

mokkery-plugin/src/main/kotlin/dev/mokkery/plugin/ir/transformer/mock/stubs/NullableStubStrategy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import org.jetbrains.kotlin.ir.util.isNullable
66

77
object NullableStubStrategy : StubStrategy {
88

9-
context(context: StubStrategyScope)
9+
context(scope: StubStrategyScope)
1010
override fun provide(type: IrType): Stub? = when {
11-
type.isNullable() -> stub(context.builder.irNull(type))
11+
type.isNullable() -> stub(scope.builder.irNull(type))
1212
else -> null
1313
}
1414
}

0 commit comments

Comments
 (0)