mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Update to KotlinPoet 1.0.0-RC2.
Also, use KotlinPoet's escaping for $ characters in formatted strings.
This is partly a revert of 01f600c
(https://github.com/square/moshi/pull/604/).
This commit is contained in:
@@ -79,8 +79,9 @@ internal class AdapterGenerator(
|
||||
private val optionsProperty = PropertySpec.builder(
|
||||
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
|
||||
KModifier.PRIVATE)
|
||||
.initializer("%T.of(${propertyList.joinToString(", ") { "\"${it.jsonName}\"" }})",
|
||||
JsonReader.Options::class.asTypeName())
|
||||
.initializer("%T.of(${propertyList.joinToString(", ") {
|
||||
CodeBlock.of("%S", it.jsonName).toString()
|
||||
}})", JsonReader.Options::class.asTypeName())
|
||||
.build()
|
||||
|
||||
fun generateFile(generatedOption: TypeElement?): FileSpec {
|
||||
@@ -296,7 +297,7 @@ internal class AdapterGenerator(
|
||||
|
||||
result.addStatement("%N.beginObject()", writerParam)
|
||||
propertyList.forEach { property ->
|
||||
result.addStatement("%N.name(\"${property.jsonName}\")", writerParam)
|
||||
result.addStatement("%N.name(%S)", writerParam, property.jsonName)
|
||||
result.addStatement("%N.toJson(%N, %N.%L)",
|
||||
nameAllocator.get(property.delegateKey), writerParam, valueParam, property.name)
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ internal data class DelegateKey(
|
||||
propertyName: String
|
||||
): PropertySpec {
|
||||
val qualifierNames = jsonQualifiers.joinToString("") {
|
||||
"At${(it.type as ClassName).simpleName}"
|
||||
"At${it.className.simpleName}"
|
||||
}
|
||||
val adapterName = nameAllocator.newName(
|
||||
"${type.toVariableName().decapitalize()}${qualifierNames}Adapter", this)
|
||||
|
@@ -157,7 +157,7 @@ internal data class TargetProperty(
|
||||
private val Element?.jsonName: String?
|
||||
get() {
|
||||
if (this == null) return null
|
||||
return getAnnotation(Json::class.java)?.name?.replace("$", "\\$")
|
||||
return getAnnotation(Json::class.java)?.name
|
||||
}
|
||||
|
||||
private val AnnotationMirror.simpleName: Name
|
||||
|
@@ -51,9 +51,9 @@ abstract class TypeRenderer {
|
||||
|| typeName == INT.asNullable()
|
||||
|| typeName == LONG.asNullable()
|
||||
|| typeName == SHORT.asNullable()) {
|
||||
return CodeBlock.of("%T::class.javaObjectType", typeName.asNonNullable())
|
||||
return CodeBlock.of("%T::class.javaObjectType", typeName.asNonNull())
|
||||
}
|
||||
return render(typeName.asNonNullable())
|
||||
return render(typeName.asNonNull())
|
||||
}
|
||||
|
||||
return when (typeName) {
|
||||
|
Reference in New Issue
Block a user