Followups from #896 (#907)

* Simplify parameterProperties and parameterProperties

* Match only on synthetic constructors

* Limit synthetic constructor keeps to kotlin classes
This commit is contained in:
Zac Sweers
2019-09-11 04:55:24 -04:00
committed by GitHub
parent ea300997a1
commit c820314107
2 changed files with 5 additions and 10 deletions

View File

@@ -36,8 +36,8 @@ import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.internal.Util
import java.lang.reflect.Constructor
import com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor
import java.lang.reflect.Constructor
import java.lang.reflect.Type
private val MOSHI_UTIL = Util::class.asClassName()
@@ -226,13 +226,8 @@ internal class AdapterGenerator(
result.addStatement("%N.endObject()", readerParam)
var separator = "\n"
var useDefaultsConstructor = false
val parameterProperties = propertyList.asSequence()
.filter { it.hasConstructorParameter }
.onEach {
useDefaultsConstructor = useDefaultsConstructor || it.hasDefault
}
.toList()
val parameterProperties = propertyList.filter { it.hasConstructorParameter }
val useDefaultsConstructor = parameterProperties.any { it.hasDefault }
val resultName = nameAllocator.newName("result")
val hasNonConstructorProperties = nonTransientProperties.any { !it.hasConstructorParameter }