Suppress common warnings in generated classes (#1028)

* Suppress common warnings in generated classes

Followup from #1023 (Resolves #1023 too). Since we can't do targeted deprecation suppressions, we can just stick with blanket deprecations suppressions for now. This also suppresses a couple other common issues with all our generated adapters.

Have just eyeballed the results for now, can add a proper test as a followup once #1014 is in

* Add redundant projection and re-enable -Werror

* Add tests for deprecation suppression

With -Werror enabled now we can actually check this
This commit is contained in:
Zac Sweers
2019-11-17 09:40:49 -05:00
committed by Jesse Wilson
parent f7dbde2114
commit f49f677bfc
4 changed files with 40 additions and 9 deletions

View File

@@ -115,11 +115,7 @@
</executions>
<configuration>
<args>
<!--
Disabled for now because we generate redundant `out` variance for some generics,
but there's no way for us to know when it's redundant.
-->
<!-- <arg>-Werror</arg>-->
<arg>-Werror</arg>
<arg>-Xuse-experimental=kotlin.ExperimentalStdlibApi</arg>
<arg>-XXLanguage:+InlineClasses</arg>
</args>

View File

@@ -513,6 +513,7 @@ class DualKotlinTest(useReflection: Boolean) {
assertThat(result).isEqualTo(instance)
}
@Suppress("REDUNDANT_NULLABLE")
@JsonClass(generateAdapter = true)
data class TypeAliasNullability(
val aShouldBeNonNull: A,

View File

@@ -1169,6 +1169,22 @@ class GeneratedAdaptersTest {
val instance = adapter.fromJson("""{"_links": "link", "_ids": "id" }""")!!
assertThat(instance).isEqualTo(ClassWithFieldJson("link").apply { ids = "id" })
}
/*
* These are a smoke test for https://github.com/square/moshi/issues/1023 to ensure that we
* suppress deprecation warnings for using deprecated properties or classes.
*
* Ideally when stubs are fixed to actually included Deprecated annotations, we could then only
* generate a deprecation suppression as needed and on targeted usages.
* https://youtrack.jetbrains.com/issue/KT-34951
*/
@Deprecated("Deprecated for reasons")
@JsonClass(generateAdapter = true)
data class DeprecatedClass(val foo: String)
@JsonClass(generateAdapter = true)
data class DeprecatedProperty(@Deprecated("Deprecated for reasons") val foo: String)
}
// Regression test for https://github.com/square/moshi/issues/1022