Skip to content

Commit e0e5e99

Browse files
Update dependency com.facebook:ktfmt to v0.62 (#2089)
* Update dependency com.facebook:ktfmt to v0.62 * Reformat --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jake Wharton <jw@jakewharton.com>
1 parent be31de2 commit e0e5e99

6 files changed

Lines changed: 56 additions & 57 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "k
3636
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
3737
truth = "com.google.truth:truth:1.4.5"
3838
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.35.0"
39-
ktfmt = "com.facebook:ktfmt:0.61"
39+
ktfmt = "com.facebook:ktfmt:0.62"

moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/ProguardRules.kt

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,53 @@ public data class ProguardConfig(
4545
return "META-INF/proguard/moshi-$canonicalName"
4646
}
4747

48-
public fun writeTo(out: Appendable): Unit =
49-
out.run {
48+
public fun writeTo(out: Appendable): Unit = out.run {
49+
//
50+
// -keepnames class {the target class}
51+
// -if class {the target class}
52+
// -keep class {the generated adapter} {
53+
// <init>(...);
54+
// private final {adapter fields}
55+
// }
56+
//
57+
val targetName = targetClass.reflectionName()
58+
val adapterCanonicalName = ClassName(targetClass.packageName, adapterName).canonicalName
59+
// Keep the class name for Moshi's reflective lookup based on it
60+
appendLine("-keepnames class $targetName")
61+
62+
appendLine("-if class $targetName")
63+
appendLine("-keep class $adapterCanonicalName {")
64+
// Keep the constructor for Moshi's reflective lookup
65+
val constructorArgs = adapterConstructorParams.joinToString(",")
66+
appendLine(" public <init>($constructorArgs);")
67+
appendLine("}")
68+
69+
if (targetConstructorHasDefaults) {
70+
// If the target class has default parameter values, keep its synthetic constructor
5071
//
51-
// -keepnames class {the target class}
5272
// -if class {the target class}
53-
// -keep class {the generated adapter} {
54-
// <init>(...);
55-
// private final {adapter fields}
73+
// -keepnames class kotlin.jvm.internal.DefaultConstructorMarker
74+
// -keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * {
75+
// synthetic <init>(...);
5676
// }
5777
//
58-
val targetName = targetClass.reflectionName()
59-
val adapterCanonicalName = ClassName(targetClass.packageName, adapterName).canonicalName
60-
// Keep the class name for Moshi's reflective lookup based on it
61-
appendLine("-keepnames class $targetName")
62-
6378
appendLine("-if class $targetName")
64-
appendLine("-keep class $adapterCanonicalName {")
65-
// Keep the constructor for Moshi's reflective lookup
66-
val constructorArgs = adapterConstructorParams.joinToString(",")
67-
appendLine(" public <init>($constructorArgs);")
79+
appendLine("-keepnames class kotlin.jvm.internal.DefaultConstructorMarker")
80+
appendLine("-keepclassmembers class $targetName {")
81+
val allParams = targetConstructorParams.toMutableList()
82+
val maskCount =
83+
if (targetConstructorParams.isEmpty()) {
84+
0
85+
} else {
86+
(targetConstructorParams.size + 31) / 32
87+
}
88+
repeat(maskCount) { allParams += "int" }
89+
allParams += "kotlin.jvm.internal.DefaultConstructorMarker"
90+
val params = allParams.joinToString(",")
91+
appendLine(" public synthetic <init>($params);")
6892
appendLine("}")
69-
70-
if (targetConstructorHasDefaults) {
71-
// If the target class has default parameter values, keep its synthetic constructor
72-
//
73-
// -if class {the target class}
74-
// -keepnames class kotlin.jvm.internal.DefaultConstructorMarker
75-
// -keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * {
76-
// synthetic <init>(...);
77-
// }
78-
//
79-
appendLine("-if class $targetName")
80-
appendLine("-keepnames class kotlin.jvm.internal.DefaultConstructorMarker")
81-
appendLine("-keepclassmembers class $targetName {")
82-
val allParams = targetConstructorParams.toMutableList()
83-
val maskCount =
84-
if (targetConstructorParams.isEmpty()) {
85-
0
86-
} else {
87-
(targetConstructorParams.size + 31) / 32
88-
}
89-
repeat(maskCount) { allParams += "int" }
90-
allParams += "kotlin.jvm.internal.DefaultConstructorMarker"
91-
val params = allParams.joinToString(",")
92-
appendLine(" public synthetic <init>($params);")
93-
appendLine("}")
94-
}
9593
}
94+
}
9695
}
9796

9897
/**

moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ private class JsonClassSymbolProcessor(environment: SymbolProcessorEnvironment)
6565
environment.options[OPTION_GENERATE_PROGUARD_RULES]?.toBooleanStrictOrNull() ?: true
6666

6767
override fun process(resolver: Resolver): List<KSAnnotated> {
68-
val generatedAnnotation =
69-
generatedOption?.let {
70-
AnnotationSpec.builder(ClassName.bestGuess(it))
71-
.addMember("value = [%S]", JsonClassSymbolProcessor::class.java.canonicalName)
72-
.addMember("comments = %S", "https://github.com/square/moshi")
73-
.build()
74-
}
68+
val generatedAnnotation = generatedOption?.let {
69+
AnnotationSpec.builder(ClassName.bestGuess(it))
70+
.addMember("value = [%S]", JsonClassSymbolProcessor::class.java.canonicalName)
71+
.addMember("comments = %S", "https://github.com/square/moshi")
72+
.build()
73+
}
7574

7675
for (type in resolver.getSymbolsWithAnnotation(JSON_CLASS_NAME)) {
7776
// For the smart cast

moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/MoshiApiUtil.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ internal fun TargetProperty.generator(
7777
}
7878
}
7979

80-
val jsonQualifierSpecs =
81-
qualifiers.map { it.toBuilder().useSiteTarget(AnnotationSpec.UseSiteTarget.FIELD).build() }
80+
val jsonQualifierSpecs = qualifiers.map {
81+
it.toBuilder().useSiteTarget(AnnotationSpec.UseSiteTarget.FIELD).build()
82+
}
8283

8384
return PropertyGenerator(this, DelegateKey(type, jsonQualifierSpecs))
8485
}

moshi-kotlin/src/main/java/com/squareup/moshi/kotlin/reflect/IndexedParameterMap.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ internal class IndexedParameterMap(
1010

1111
override val entries: MutableSet<MutableMap.MutableEntry<KtParameter, Any?>>
1212
get() {
13-
val allPossibleEntries =
14-
parameterKeys.mapIndexed { index, value ->
15-
SimpleEntry<KtParameter, Any?>(value, parameterValues[index])
16-
}
13+
val allPossibleEntries = parameterKeys.mapIndexed { index, value ->
14+
SimpleEntry<KtParameter, Any?>(value, parameterValues[index])
15+
}
1716
return allPossibleEntries.filterTo(mutableSetOf()) { it.value !== ABSENT_VALUE }
1817
}
1918

moshi/src/main/java/com/squareup/moshi/internal/Util.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ private fun Type.resolve(
244244
toResolve is ParameterizedType -> {
245245
val original = toResolve
246246
val ownerType: Type? = original.ownerType
247-
val newOwnerType =
248-
ownerType?.let { ownerType.resolve(context, contextRawType, visitedTypeVariables) }
247+
val newOwnerType = ownerType?.let {
248+
ownerType.resolve(context, contextRawType, visitedTypeVariables)
249+
}
249250
var changed = newOwnerType !== ownerType
250251
var args = original.actualTypeArguments
251252
for (t in args.indices) {

0 commit comments

Comments
 (0)