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
This commit is contained in:
Zac Sweers
2019-12-05 22:37:26 +01:00
committed by GitHub
parent 791ff3211e
commit 14cb9e4bbb

View File

@@ -60,19 +60,27 @@ internal class AdapterGenerator(
private val DEFAULT_CONSTRUCTOR_MARKER_TYPE_BLOCK = CodeBlock.of( private val DEFAULT_CONSTRUCTOR_MARKER_TYPE_BLOCK = CodeBlock.of(
"%T.DEFAULT_CONSTRUCTOR_MARKER", Util::class) "%T.DEFAULT_CONSTRUCTOR_MARKER", Util::class)
private val COMMON_SUPPRESS = AnnotationSpec.builder(Suppress::class) private val COMMON_SUPPRESS = arrayOf(
.addMember("%S, %S, %S, %S", // https://github.com/square/moshi/issues/1023
// https://github.com/square/moshi/issues/1023 "DEPRECATION",
"DEPRECATION", // Because we look it up reflectively
// Because we look it up reflectively "unused",
"unused", // Because we include underscores
// Because we include underscores "ClassName",
"ClassName", // Because we generate redundant `out` variance for some generics and there's no way
// Because we generate redundant `out` variance for some generics and there's no way // for us to know when it's redundant.
// for us to know when it's redundant. "REDUNDANT_PROJECTION",
"REDUNDANT_PROJECTION" // NameAllocator will just add underscores to differentiate names, which Kotlin doesn't
) // like for stylistic reasons.
.build() "LocalVariableName"
).let { suppressions ->
AnnotationSpec.builder(Suppress::class)
.addMember(
suppressions.indices.joinToString { "%S" },
*suppressions
)
.build()
}
} }
private val nonTransientProperties = propertyList.filterNot { it.isTransient } private val nonTransientProperties = propertyList.filterNot { it.isTransient }