mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Merge pull request #726 from square/eric.kp$
Update to KotlinPoet 1.0.0-RC2.
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup</groupId>
|
<groupId>com.squareup</groupId>
|
||||||
<artifactId>kotlinpoet</artifactId>
|
<artifactId>kotlinpoet</artifactId>
|
||||||
<version>1.0.0-RC1</version>
|
<version>1.0.0-RC2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.auto</groupId>
|
<groupId>com.google.auto</groupId>
|
||||||
|
@@ -79,8 +79,9 @@ internal class AdapterGenerator(
|
|||||||
private val optionsProperty = PropertySpec.builder(
|
private val optionsProperty = PropertySpec.builder(
|
||||||
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
|
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
|
||||||
KModifier.PRIVATE)
|
KModifier.PRIVATE)
|
||||||
.initializer("%T.of(${propertyList.joinToString(", ") { "\"${it.jsonName}\"" }})",
|
.initializer("%T.of(${propertyList.joinToString(", ") {
|
||||||
JsonReader.Options::class.asTypeName())
|
CodeBlock.of("%S", it.jsonName).toString()
|
||||||
|
}})", JsonReader.Options::class.asTypeName())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
fun generateFile(generatedOption: TypeElement?): FileSpec {
|
fun generateFile(generatedOption: TypeElement?): FileSpec {
|
||||||
@@ -296,7 +297,7 @@ internal class AdapterGenerator(
|
|||||||
|
|
||||||
result.addStatement("%N.beginObject()", writerParam)
|
result.addStatement("%N.beginObject()", writerParam)
|
||||||
propertyList.forEach { property ->
|
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)",
|
result.addStatement("%N.toJson(%N, %N.%L)",
|
||||||
nameAllocator.get(property.delegateKey), writerParam, valueParam, property.name)
|
nameAllocator.get(property.delegateKey), writerParam, valueParam, property.name)
|
||||||
}
|
}
|
||||||
|
@@ -47,7 +47,7 @@ internal data class DelegateKey(
|
|||||||
propertyName: String
|
propertyName: String
|
||||||
): PropertySpec {
|
): PropertySpec {
|
||||||
val qualifierNames = jsonQualifiers.joinToString("") {
|
val qualifierNames = jsonQualifiers.joinToString("") {
|
||||||
"At${(it.type as ClassName).simpleName}"
|
"At${it.className.simpleName}"
|
||||||
}
|
}
|
||||||
val adapterName = nameAllocator.newName(
|
val adapterName = nameAllocator.newName(
|
||||||
"${type.toVariableName().decapitalize()}${qualifierNames}Adapter", this)
|
"${type.toVariableName().decapitalize()}${qualifierNames}Adapter", this)
|
||||||
|
@@ -157,7 +157,7 @@ internal data class TargetProperty(
|
|||||||
private val Element?.jsonName: String?
|
private val Element?.jsonName: String?
|
||||||
get() {
|
get() {
|
||||||
if (this == null) return null
|
if (this == null) return null
|
||||||
return getAnnotation(Json::class.java)?.name?.replace("$", "\\$")
|
return getAnnotation(Json::class.java)?.name
|
||||||
}
|
}
|
||||||
|
|
||||||
private val AnnotationMirror.simpleName: Name
|
private val AnnotationMirror.simpleName: Name
|
||||||
|
@@ -51,9 +51,9 @@ abstract class TypeRenderer {
|
|||||||
|| typeName == INT.asNullable()
|
|| typeName == INT.asNullable()
|
||||||
|| typeName == LONG.asNullable()
|
|| typeName == LONG.asNullable()
|
||||||
|| typeName == SHORT.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) {
|
return when (typeName) {
|
||||||
|
Reference in New Issue
Block a user