From 14cb9e4bbb28c3ea9ca532bcf95666b7915b46b2 Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Thu, 5 Dec 2019 22:37:26 +0100 Subject: [PATCH] Add LocalVariableName to common suppressions (#1040) * Add LocalVariableName to common suppressions NameAllocator will add underscores to names, which kotlin doesn't like for stylistic reasons * Simplify structure a bit Keeping track of template counts is error prone and would have failed only at runtime --- .../kotlin/codegen/api/AdapterGenerator.kt | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt index 77953d9..3224bd3 100644 --- a/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt +++ b/kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt @@ -60,19 +60,27 @@ internal class AdapterGenerator( private val DEFAULT_CONSTRUCTOR_MARKER_TYPE_BLOCK = CodeBlock.of( "%T.DEFAULT_CONSTRUCTOR_MARKER", Util::class) - private val COMMON_SUPPRESS = AnnotationSpec.builder(Suppress::class) - .addMember("%S, %S, %S, %S", - // https://github.com/square/moshi/issues/1023 - "DEPRECATION", - // Because we look it up reflectively - "unused", - // Because we include underscores - "ClassName", - // Because we generate redundant `out` variance for some generics and there's no way - // for us to know when it's redundant. - "REDUNDANT_PROJECTION" - ) - .build() + private val COMMON_SUPPRESS = arrayOf( + // https://github.com/square/moshi/issues/1023 + "DEPRECATION", + // Because we look it up reflectively + "unused", + // Because we include underscores + "ClassName", + // Because we generate redundant `out` variance for some generics and there's no way + // for us to know when it's redundant. + "REDUNDANT_PROJECTION", + // NameAllocator will just add underscores to differentiate names, which Kotlin doesn't + // like for stylistic reasons. + "LocalVariableName" + ).let { suppressions -> + AnnotationSpec.builder(Suppress::class) + .addMember( + suppressions.indices.joinToString { "%S" }, + *suppressions + ) + .build() + } } private val nonTransientProperties = propertyList.filterNot { it.isTransient }