mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
* Simplify parameterProperties and parameterProperties * Match only on synthetic constructors * Limit synthetic constructor keeps to kotlin classes
This commit is contained in:
@@ -36,8 +36,8 @@ import com.squareup.moshi.JsonReader
|
|||||||
import com.squareup.moshi.JsonWriter
|
import com.squareup.moshi.JsonWriter
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.internal.Util
|
import com.squareup.moshi.internal.Util
|
||||||
import java.lang.reflect.Constructor
|
|
||||||
import com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor
|
import com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor
|
||||||
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
private val MOSHI_UTIL = Util::class.asClassName()
|
private val MOSHI_UTIL = Util::class.asClassName()
|
||||||
@@ -226,13 +226,8 @@ internal class AdapterGenerator(
|
|||||||
result.addStatement("%N.endObject()", readerParam)
|
result.addStatement("%N.endObject()", readerParam)
|
||||||
|
|
||||||
var separator = "\n"
|
var separator = "\n"
|
||||||
var useDefaultsConstructor = false
|
val parameterProperties = propertyList.filter { it.hasConstructorParameter }
|
||||||
val parameterProperties = propertyList.asSequence()
|
val useDefaultsConstructor = parameterProperties.any { it.hasDefault }
|
||||||
.filter { it.hasConstructorParameter }
|
|
||||||
.onEach {
|
|
||||||
useDefaultsConstructor = useDefaultsConstructor || it.hasDefault
|
|
||||||
}
|
|
||||||
.toList()
|
|
||||||
|
|
||||||
val resultName = nameAllocator.newName("result")
|
val resultName = nameAllocator.newName("result")
|
||||||
val hasNonConstructorProperties = nonTransientProperties.any { !it.hasConstructorParameter }
|
val hasNonConstructorProperties = nonTransientProperties.any { !it.hasConstructorParameter }
|
||||||
|
@@ -22,8 +22,8 @@
|
|||||||
# We can't _just_ keep the defaults constructor because Proguard/R8's spec doesn't allow wildcard
|
# We can't _just_ keep the defaults constructor because Proguard/R8's spec doesn't allow wildcard
|
||||||
# matching preceding parameters.
|
# matching preceding parameters.
|
||||||
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
|
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
|
||||||
-keepclassmembers @com.squareup.moshi.JsonClass class * {
|
-keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * {
|
||||||
<init>(...);
|
synthetic <init>(...);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retain generated JsonAdapters if annotated type is retained.
|
# Retain generated JsonAdapters if annotated type is retained.
|
||||||
|
Reference in New Issue
Block a user