Check against non-nullable known primitives when rendering class… (#993)

* Check against non-nullable known primitives when rendering class blocks

`Int?` will not equal `Int` in KotlinPoet, so this was always falling through to the default `::class.java` code.

Resolves #991

* Nix comment

* Flesh out test to include all primitives
This commit is contained in:
Zac Sweers
2019-11-02 15:15:29 -04:00
committed by GitHub
parent c8c7121e76
commit fe34a577e7
2 changed files with 49 additions and 1 deletions

View File

@@ -71,7 +71,9 @@ internal fun TypeName.asTypeBlock(): CodeBlock {
return bound.asTypeBlock()
}
is ClassName -> {
return when (this) {
// Check against the non-nullable version for equality, but we'll keep the nullability in
// consideration when creating the CodeBlock if needed.
return when (copy(nullable = false)) {
BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE -> {
if (isNullable) {
// Remove nullable but keep the java object type