File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed
mokkery-plugin/src/main/kotlin/dev/mokkery/plugin/ir Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff 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
3034class 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
3441class 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!" )
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ import org.jetbrains.kotlin.ir.util.isNullable
66
77object 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}
You can’t perform that action at this time.
0 commit comments