@@ -77,6 +77,7 @@ class DataCompatProcessor(
77
77
val implementedInterfaces = classDeclaration
78
78
.superTypes
79
79
.filter { (it.resolve().declaration as ? KSClassDeclaration )?.classKind == ClassKind .INTERFACE }
80
+ val imports = ArrayList <String >()
80
81
81
82
// Map KSP properties with KoltinPoet TypeNames
82
83
val propertyMap = mutableMapOf<KSPropertyDeclaration , TypeName >()
@@ -219,9 +220,13 @@ class DataCompatProcessor(
219
220
val builderBuilder = TypeSpec .classBuilder(" Builder" )
220
221
for (property in propertyMap) {
221
222
val propertyName = property.key.toString()
222
- val defaultValue = property.key.annotations
223
+ val defaultAnnotationsParams = property.key.annotations
223
224
.firstOrNull { it.annotationType.resolve().toString() == Default ::class .simpleName }
224
- ?.arguments?.first()
225
+ ?.arguments
226
+ val defaultValue = defaultAnnotationsParams?.first()
227
+ defaultAnnotationsParams?.getOrNull(1 )?.value?.let {
228
+ imports.addAll(it as ArrayList <String >)
229
+ }
225
230
val nullableType = property.value.copy(nullable = true )
226
231
builderBuilder.addProperty(
227
232
PropertySpec .builder(propertyName, nullableType)
@@ -350,6 +355,14 @@ class DataCompatProcessor(
350
355
.addType(classBuilder.build())
351
356
.addFunction(initializerFunctionBuilder.build())
352
357
358
+ imports.forEach {
359
+ fileBuilder
360
+ .addImport(
361
+ it.split(" ." ).dropLast(1 ).joinToString(" ." ),
362
+ it.split(" ." ).last()
363
+ )
364
+ }
365
+
353
366
fileBuilder.build().writeTo(codeGenerator = codeGenerator, aggregating = false )
354
367
}
355
368
0 commit comments