@@ -182,6 +182,11 @@ class DataCompatProcessor(
182
182
for (entry in propertyMap) {
183
183
addProperty(
184
184
PropertySpec .builder(entry.key.toString(), entry.value)
185
+ .addKdoc(
186
+ """
187
+ |Represents ${getKDocProperty(kdocPropertyList, entry.key.toString())}
188
+ """ .trimMargin()
189
+ )
185
190
.initializer(entry.key.toString())
186
191
.build()
187
192
)
@@ -191,6 +196,11 @@ class DataCompatProcessor(
191
196
addFunction(
192
197
FunSpec .builder(" toString" )
193
198
.addModifiers(KModifier .OVERRIDE )
199
+ .addKdoc(
200
+ """
201
+ Overloaded toString function.
202
+ """ .trimIndent()
203
+ )
194
204
// using triple quote for long strings
195
205
.addStatement(
196
206
propertyMap.keys.joinToString(
@@ -205,6 +215,11 @@ class DataCompatProcessor(
205
215
// Function equals
206
216
val equalsBuilder = FunSpec .builder(" equals" )
207
217
.addModifiers(KModifier .OVERRIDE )
218
+ .addKdoc(
219
+ """
220
+ Overloaded equals function.
221
+ """ .trimIndent()
222
+ )
208
223
.addParameter(" other" , ANY .copy(nullable = true ))
209
224
.addStatement(" if (this === other) return true" )
210
225
.addStatement(" if (javaClass != other?.javaClass) return false" )
@@ -223,6 +238,11 @@ class DataCompatProcessor(
223
238
// Function hashCode
224
239
addFunction(
225
240
FunSpec .builder(" hashCode" )
241
+ .addKdoc(
242
+ """
243
+ Overloaded hashCode function based on all class properties.
244
+ """ .trimIndent()
245
+ )
226
246
.addModifiers(KModifier .OVERRIDE )
227
247
.addStatement(
228
248
propertyMap.keys.joinToString(
@@ -265,15 +285,20 @@ class DataCompatProcessor(
265
285
val builderBuilder = TypeSpec .classBuilder(" Builder" )
266
286
for (property in propertyMap) {
267
287
val propertyName = property.key.toString()
268
-
269
288
val nullableType = property.value.copy(nullable = true )
289
+ val kDocProperty = getKDocProperty(kdocPropertyList, propertyName)
270
290
builderBuilder.addProperty(
271
291
PropertySpec .builder(propertyName, nullableType)
272
292
.initializer(
273
293
CodeBlock .builder()
274
294
.add(defaultValuesMap[classDeclaration]?.get(propertyName) ? : " null" )
275
295
.build()
276
296
)
297
+ .addKdoc(
298
+ """
299
+ |Represents $kDocProperty
300
+ """ .trimMargin()
301
+ )
277
302
.addAnnotation(
278
303
AnnotationSpec .builder(JvmSynthetic ::class )
279
304
.useSiteTarget(AnnotationSpec .UseSiteTarget .SET )
@@ -283,16 +308,6 @@ class DataCompatProcessor(
283
308
.build()
284
309
)
285
310
286
- var kDocProperty = kdocPropertyList
287
- .filter { it.startsWith(" $propertyName " ) }
288
- .joinToString {
289
- it.substringAfter(" $propertyName " ).lowercase(Locale .getDefault())
290
- }
291
-
292
- if (kDocProperty.isEmpty()) {
293
- kDocProperty = propertyName
294
- }
295
-
296
311
builderBuilder.addFunction(
297
312
FunSpec
298
313
.builder(
@@ -356,7 +371,7 @@ class DataCompatProcessor(
356
371
|
357
372
|${
358
373
kdocPropertyList.joinToString(
359
- prefix = " $KDOC_PROPERTY_ANNOTATION " ,
374
+ prefix = if (kdocPropertyList.isEmpty()) " " else " $KDOC_PROPERTY_ANNOTATION " ,
360
375
separator = " \n $KDOC_PROPERTY_ANNOTATION "
361
376
)
362
377
}
@@ -454,6 +469,19 @@ class DataCompatProcessor(
454
469
455
470
private fun KSClassDeclaration.isDataClass () = modifiers.contains(Modifier .DATA )
456
471
472
+ private fun getKDocProperty (kdocPropertyList : List <String >, propertyName : String ): String {
473
+ var kDocProperty = kdocPropertyList
474
+ .filter { it.startsWith(" $propertyName " ) }
475
+ .joinToString {
476
+ it.substringAfter(" $propertyName " ).lowercase(Locale .getDefault())
477
+ }
478
+
479
+ if (kDocProperty.isEmpty()) {
480
+ kDocProperty = propertyName
481
+ }
482
+ return kDocProperty
483
+ }
484
+
457
485
private companion object {
458
486
private const val CLASS_NAME_DROP_LAST_CHARACTERS = 4
459
487
private const val KDOC_PROPERTY_ANNOTATION = " @property"
0 commit comments