From f73cd638e6d31aa837ef252333d88f1bd41d8da4 Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Mon, 1 Mar 2021 03:36:26 -0500 Subject: [PATCH] Generate parameter name hints for readability in defaults constructor invocation (#95) --- .../zacsweers/moshix/ksp/shade/api/AdapterGenerator.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/moshi-ksp/moshi-ksp/src/main/kotlin/dev/zacsweers/moshix/ksp/shade/api/AdapterGenerator.kt b/moshi-ksp/moshi-ksp/src/main/kotlin/dev/zacsweers/moshix/ksp/shade/api/AdapterGenerator.kt index ae77aebe..14d0e30a 100644 --- a/moshi-ksp/moshi-ksp/src/main/kotlin/dev/zacsweers/moshix/ksp/shade/api/AdapterGenerator.kt +++ b/moshi-ksp/moshi-ksp/src/main/kotlin/dev/zacsweers/moshix/ksp/shade/api/AdapterGenerator.kt @@ -594,7 +594,12 @@ internal class AdapterGenerator( // We have to use the default primitive for the available type in order for // invokeDefaultConstructor to properly invoke it. Just using "null" isn't safe because // the transient type may be a primitive type. - result.addCode(input.type.rawType().defaultPrimitiveValue()) + // Inline a little comment for readability indicating which parameter is it's referring to + result.addCode( + "/*·%L·*/·%L", + input.parameter.name, + input.type.rawType().defaultPrimitiveValue() + ) } else { result.addCode("%N", (input as ParameterProperty).property.localName) } @@ -613,7 +618,7 @@ internal class AdapterGenerator( if (useDefaultsConstructor) { // Add the masks and a null instance for the trailing default marker instance - result.addCode(",\n%L,\nnull", maskNames.map { CodeBlock.of("%L", it) }.joinToCode(", ")) + result.addCode(",\n%L,\n/*·DefaultConstructorMarker·*/·null", maskNames.map { CodeBlock.of("%L", it) }.joinToCode(", ")) } result.addCode("\n»)\n")