From 786cf9bd8b48578836b10cb12339f91e96f19291 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 19 Jun 2023 13:52:41 +0600 Subject: [PATCH] fix in koin generator --- CHANGELOG.md | 4 +++ koin/generator/src/main/kotlin/Processor.kt | 2 +- .../kotlin/GeneratedDefinitionsTest.kt | 25 +++++++++++++++++++ .../test/src/commonMain/kotlin/Test.kt | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 078986bb07b..1eb8c3a969d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.19.4 +* `Koin` + * `Generator` + * Fixes in new generic generator part + ## 0.19.3 * `Koin` diff --git a/koin/generator/src/main/kotlin/Processor.kt b/koin/generator/src/main/kotlin/Processor.kt index 0f7380e5c31..8f906e87074 100644 --- a/koin/generator/src/main/kotlin/Processor.kt +++ b/koin/generator/src/main/kotlin/Processor.kt @@ -127,7 +127,7 @@ class Processor( addModifiers(KModifier.INLINE) targetTypeAsGenericType ?.let { addTypeVariable(it) - returns(it) + returns(it.copy(nullable = nullable)) } ?: returns(targetType) addCode( "return " + (if (nullable) { diff --git a/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt b/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt index f71bd452576..0ec0aea444a 100644 --- a/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt +++ b/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt @@ -97,3 +97,28 @@ public inline fun Module.singleTest(createdAtStart: Boolean = */ public inline fun Module.factoryTest(noinline definition: Definition): KoinDefinition = factory(named("test"), definition = definition) + +/** + * @return Definition by key "testNullable" with [parameters] + */ +public inline fun Scope.testNullable(noinline parameters: ParametersDefinition? = + null): T? = getOrNull(named("testNullable"), parameters) + +/** + * @return Definition by key "testNullable" with [parameters] + */ +public inline fun Koin.testNullable(noinline parameters: ParametersDefinition? = + null): T? = getOrNull(named("testNullable"), parameters) + +/** + * Will register [definition] with [org.koin.core.module.Module.single] and key "testNullable" + */ +public inline fun Module.singleTestNullable(createdAtStart: Boolean = false, + noinline definition: Definition): KoinDefinition = single(named("testNullable"), + createdAtStart = createdAtStart, definition = definition) + +/** + * Will register [definition] with [org.koin.core.module.Module.factory] and key "testNullable" + */ +public inline fun Module.factoryTestNullable(noinline definition: Definition): + KoinDefinition = factory(named("testNullable"), definition = definition) diff --git a/koin/generator/test/src/commonMain/kotlin/Test.kt b/koin/generator/test/src/commonMain/kotlin/Test.kt index ee78929507d..7fb7fb290b2 100644 --- a/koin/generator/test/src/commonMain/kotlin/Test.kt +++ b/koin/generator/test/src/commonMain/kotlin/Test.kt @@ -1,5 +1,6 @@ @file:GenerateKoinDefinition("sampleInfo", Test::class, String::class, nullable = false) @file:GenerateGenericKoinDefinition("test", nullable = false) +@file:GenerateGenericKoinDefinition("testNullable", nullable = true) package dev.inmo.micro_utils.koin.generator.test import dev.inmo.micro_utils.koin.annotations.GenerateGenericKoinDefinition