Skip to content

Commit 5ef8835

Browse files
Merge pull request #297 from InsertKoinIO/fix_nested_type_generation
Fix class scanning for parent type declaration
2 parents 2d48dbf + 3cab6df commit 5ef8835

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

examples/other-ksp/src/main/kotlin/org/koin/example/supertype/Types.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ public interface D
1616

1717
@Single
1818
public class C : B(),D
19+
20+
21+
class MyType {
22+
23+
@Single
24+
class MyChildType
25+
}

examples/other-ksp/src/test/kotlin/org.koin.example/TestModule.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.koin.example.supertype.A
3434
import org.koin.example.supertype.B
3535
import org.koin.example.supertype.C
3636
import org.koin.example.supertype.D
37+
import org.koin.example.supertype.MyType
3738
import org.koin.example.supertype.SuperTypesModule
3839
import org.koin.ksp.generated.defaultModule
3940
import org.koin.ksp.generated.module
@@ -127,6 +128,8 @@ class TestModule {
127128

128129
assertEquals(2,koin.get<StuffList>(named("another-counter")).list.size)
129130
assertEquals("another-counter",koin.get<StuffCounter>().name)
131+
132+
assertNotNull(koin.getOrNull<MyType.MyChildType>())
130133
}
131134

132135

projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ClassComponentScanner.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class ClassComponentScanner(
2727

2828
fun createClassDefinition(element: KSAnnotated): KoinMetaData.Definition {
2929
val ksClassDeclaration = (element as KSClassDeclaration)
30-
val packageName = ksClassDeclaration.getPackageName().filterForbiddenKeywords()
30+
val parent = ksClassDeclaration.parentDeclaration?.simpleName?.asString()
31+
val packageName = (ksClassDeclaration.getPackageName() + (parent?.let { ".$it" } ?: "")).filterForbiddenKeywords()
3132
val className = ksClassDeclaration.simpleName.asString()
33+
3234
val qualifier = ksClassDeclaration.getQualifier()
3335
val annotations = element.getKoinAnnotations()
3436
val scopeAnnotation = annotations.getScopeAnnotation()

0 commit comments

Comments
 (0)