Merge pull request #1211 from ZacSweers/z/appendLnFixes

Switch to new appendLine APIs
This commit is contained in:
Jake Wharton
2020-09-01 09:17:38 -04:00
committed by GitHub

View File

@@ -49,27 +49,27 @@ internal data class ProguardConfig(
val targetName = targetClass.reflectionName() val targetName = targetClass.reflectionName()
val adapterCanonicalName = ClassName(targetClass.packageName, adapterName).canonicalName val adapterCanonicalName = ClassName(targetClass.packageName, adapterName).canonicalName
// Keep the class name for Moshi's reflective lookup based on it // Keep the class name for Moshi's reflective lookup based on it
appendln("-if class $targetName") appendLine("-if class $targetName")
appendln("-keepnames class $targetName") appendLine("-keepnames class $targetName")
appendln("-if class $targetName") appendLine("-if class $targetName")
appendln("-keep class $adapterCanonicalName {") appendLine("-keep class $adapterCanonicalName {")
// Keep the constructor for Moshi's reflective lookup // Keep the constructor for Moshi's reflective lookup
val constructorArgs = adapterConstructorParams.joinToString(",") val constructorArgs = adapterConstructorParams.joinToString(",")
appendln(" public <init>($constructorArgs);") appendLine(" public <init>($constructorArgs);")
// Keep any qualifier properties // Keep any qualifier properties
for (qualifierProperty in qualifierProperties) { for (qualifierProperty in qualifierProperties) {
appendln(" private com.squareup.moshi.JsonAdapter ${qualifierProperty.name};") appendLine(" private com.squareup.moshi.JsonAdapter ${qualifierProperty.name};")
} }
appendln("}") appendLine("}")
qualifierProperties.asSequence() qualifierProperties.asSequence()
.flatMap { it.qualifiers.asSequence() } .flatMap { it.qualifiers.asSequence() }
.map(ClassName::reflectionName) .map(ClassName::reflectionName)
.sorted() .sorted()
.forEach { qualifier -> .forEach { qualifier ->
appendln("-if class $targetName") appendLine("-if class $targetName")
appendln("-keep @interface $qualifier") appendLine("-keep @interface $qualifier")
} }
if (targetConstructorHasDefaults) { if (targetConstructorHasDefaults) {
@@ -80,10 +80,10 @@ internal data class ProguardConfig(
// synthetic <init>(...); // synthetic <init>(...);
// } // }
// //
appendln("-if class $targetName") appendLine("-if class $targetName")
appendln("-keepnames class kotlin.jvm.internal.DefaultConstructorMarker") appendLine("-keepnames class kotlin.jvm.internal.DefaultConstructorMarker")
appendln("-if class $targetName") appendLine("-if class $targetName")
appendln("-keepclassmembers class $targetName {") appendLine("-keepclassmembers class $targetName {")
val allParams = targetConstructorParams.toMutableList() val allParams = targetConstructorParams.toMutableList()
val maskCount = if (targetConstructorParams.isEmpty()) { val maskCount = if (targetConstructorParams.isEmpty()) {
0 0
@@ -95,8 +95,8 @@ internal data class ProguardConfig(
} }
allParams += "kotlin.jvm.internal.DefaultConstructorMarker" allParams += "kotlin.jvm.internal.DefaultConstructorMarker"
val params = allParams.joinToString(",") val params = allParams.joinToString(",")
appendln(" public synthetic <init>($params);") appendLine(" public synthetic <init>($params);")
appendln("}") appendLine("}")
} }
} }
} }