@@ -121,13 +121,14 @@ class CborSymbolProcessor(
121
121
}
122
122
123
123
emptyLine()
124
- block(" fun ${deserializerName(classDeclaration)} (dataItem: DataItem): $baseName " ) {
124
+ val deserializer = deserializerName(classDeclaration, true )
125
+ block(" fun $deserializer (dataItem: DataItem): $baseName " ) {
125
126
val typeKey = getTypeKey(annotation)
126
127
line(" val type = dataItem[\" $typeKey \" ].asTstr" )
127
128
block(" return when (type)" ) {
128
129
for (subclass in subclasses) {
129
130
val typeId = getTypeId(classDeclaration, subclass)
130
- line(" \" $typeId \" -> ${deserializerName(subclass)} (dataItem)" )
131
+ line(" \" $typeId \" -> ${deserializerName(subclass, false )} (dataItem)" )
131
132
}
132
133
line(" else -> throw IllegalArgumentException(\" wrong type: \$ type\" )" )
133
134
}
@@ -200,7 +201,8 @@ class CborSymbolProcessor(
200
201
val dataItem = varName(" dataItem" )
201
202
202
203
emptyLine()
203
- block(" fun ${deserializerName(classDeclaration)} ($dataItem : DataItem): $baseName " ) {
204
+ val deserializer = deserializerName(classDeclaration, true )
205
+ block(" fun $deserializer ($dataItem : DataItem): $baseName " ) {
204
206
val constructorParameters = mutableListOf<String >()
205
207
classDeclaration.getAllProperties().forEach { property ->
206
208
val fieldName = property.simpleName.asString()
@@ -314,10 +316,16 @@ class CborSymbolProcessor(
314
316
return null
315
317
}
316
318
317
- private fun deserializerName (classDeclaration : KSClassDeclaration ): String {
319
+ private fun deserializerName (
320
+ classDeclaration : KSClassDeclaration , forDeclaration : Boolean ): String {
318
321
val baseName = classDeclaration.simpleName.asString()
319
322
return if (hasCompanion(classDeclaration)) {
320
- " ${baseName} .Companion.fromDataItem"
323
+ if (forDeclaration) {
324
+ " ${baseName} .Companion.fromDataItem"
325
+ } else {
326
+ // for call
327
+ " ${baseName} .fromDataItem"
328
+ }
321
329
} else {
322
330
" ${baseName} _fromDataItem"
323
331
}
@@ -334,7 +342,8 @@ class CborSymbolProcessor(
334
342
type : KSType
335
343
): String {
336
344
val declaration = type.declaration
337
- when (declaration.qualifiedName!! .asString()) {
345
+ val qualifiedName = declaration.qualifiedName!! .asString()
346
+ when (qualifiedName) {
338
347
" kotlin.collections.Map" ->
339
348
with (codeBuilder) {
340
349
val map = varName(" map" )
@@ -388,6 +397,10 @@ class CborSymbolProcessor(
388
397
) {
389
398
" $code .name"
390
399
} else {
400
+ codeBuilder.importQualifiedName(qualifiedName)
401
+ if (findAnnotation(declaration, annotationSerializable) != null ) {
402
+ codeBuilder.importFunctionName(" toDataItem" , declaration.packageName.asString())
403
+ }
391
404
" $code .toDataItem"
392
405
}
393
406
}
@@ -461,7 +474,12 @@ class CborSymbolProcessor(
461
474
" ${typeRef(codeBuilder, type)} .valueOf($code .asTstr)"
462
475
} else {
463
476
codeBuilder.importQualifiedName(qualifiedName)
464
- " ${deserializerName(declaration as KSClassDeclaration )} ($code )"
477
+ val deserializer = deserializerName(declaration as KSClassDeclaration , false )
478
+ if (findAnnotation(declaration, annotationSerializable) != null ) {
479
+ val shortName = deserializer.substring(deserializer.lastIndexOf(" ." ) + 1 )
480
+ codeBuilder.importFunctionName(shortName, declaration.packageName.asString())
481
+ }
482
+ " ${deserializer} ($code )"
465
483
}
466
484
}
467
485
}
0 commit comments