From e6110de8c358b76296500cb86fa17b9b4c7897f9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:03:50 +0000 Subject: [PATCH] Update plugin spotless to v6.14.0 (#1620) * Update plugin spotless to v6.14.0 * Update Spotless version and apply --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jake Wharton --- build.gradle.kts | 6 +- examples/build.gradle.kts | 2 +- .../com/squareup/moshi/recipes/JsonString.kt | 2 +- gradle/libs.versions.toml | 4 +- .../squareup/moshi/Rfc3339DateJsonAdapter.kt | 2 +- .../moshi/adapters/EnumJsonAdapter.kt | 6 +- .../squareup/moshi/adapters/Iso8601Utils.kt | 5 +- .../adapters/PolymorphicJsonAdapterFactory.kt | 16 +- moshi-kotlin-codegen/build.gradle.kts | 4 +- .../kotlin/codegen/api/AdapterGenerator.kt | 77 ++++----- .../moshi/kotlin/codegen/api/DelegateKey.kt | 8 +- .../codegen/api/InternalMoshiCodegenApi.kt | 2 +- .../moshi/kotlin/codegen/api/Options.kt | 2 +- .../kotlin/codegen/api/PropertyGenerator.kt | 2 +- .../kotlin/codegen/api/TargetConstructor.kt | 2 +- .../kotlin/codegen/api/TargetParameter.kt | 2 +- .../kotlin/codegen/api/TargetProperty.kt | 2 +- .../moshi/kotlin/codegen/api/TypeRenderer.kt | 4 +- .../moshi/kotlin/codegen/api/kotlintypes.kt | 8 +- .../moshi/kotlin/codegen/apt/AppliedType.kt | 4 +- .../codegen/apt/JsonClassCodegenProcessor.kt | 12 +- .../moshi/kotlin/codegen/apt/metadata.kt | 54 +++---- .../moshi/kotlin/codegen/ksp/AppliedType.kt | 2 +- .../ksp/JsonClassSymbolProcessorProvider.kt | 6 +- .../moshi/kotlin/codegen/ksp/KspUtil.kt | 5 +- .../moshi/kotlin/codegen/ksp/MoshiApiUtil.kt | 8 +- .../moshi/kotlin/codegen/ksp/TargetTypes.kt | 22 +-- .../moshi/kotlin/codegen/ksp/shadedUtil.kt | 11 +- .../apt/JsonClassCodegenProcessorTest.kt | 152 +++++++++--------- .../ksp/JsonClassSymbolProcessorTest.kt | 149 ++++++++--------- moshi-kotlin-tests/build.gradle.kts | 2 +- .../codegen-only/build.gradle.kts | 2 +- .../moshi/kotlin/codegen/CompileOnlyTests.kt | 21 +-- .../codegen/ComplexGenericsInheritanceTest.kt | 8 +- .../kotlin/codegen/DefaultConstructorTest.kt | 2 +- .../kotlin/codegen/GeneratedAdaptersTest.kt | 123 +++++++------- .../ClassInPackageThatLooksLikeAClass.kt | 2 + .../kotlin/codegen/MixingReflectAndCodeGen.kt | 2 +- .../moshi/kotlin/codegen/MultipleMasksTest.kt | 3 +- .../UppercaseInAnnotationPackage.kt | 1 + .../test/extra/AbstractClassInModuleA.kt | 9 +- .../squareup/moshi/kotlin/DualKotlinTest.kt | 50 +++--- .../kotlin/reflect/KotlinJsonAdapterTest.kt | 60 +++---- .../moshi/KotlinJsonAdapterFactory.kt | 2 +- .../reflect/KotlinJsonAdapterFactory.kt | 18 +-- .../kotlin/reflect/KotlinJsonAdapterTest.kt | 2 +- moshi/build.gradle.kts | 2 +- .../squareup/moshi/AdapterMethodsFactory.kt | 22 +-- .../com/squareup/moshi/ArrayJsonAdapter.kt | 2 +- .../java/com/squareup/moshi/ClassFactory.kt | 2 +- .../com/squareup/moshi/ClassJsonAdapter.kt | 10 +- .../squareup/moshi/CollectionJsonAdapter.kt | 2 +- .../src/main/java/com/squareup/moshi/Json.kt | 2 +- .../main/java/com/squareup/moshi/JsonClass.kt | 2 +- .../java/com/squareup/moshi/JsonReader.kt | 5 +- .../java/com/squareup/moshi/JsonUtf8Reader.kt | 8 +- .../java/com/squareup/moshi/JsonUtf8Writer.kt | 2 +- .../com/squareup/moshi/JsonValueReader.kt | 2 +- .../com/squareup/moshi/JsonValueSource.kt | 2 +- .../java/com/squareup/moshi/JsonWriter.kt | 1 + .../com/squareup/moshi/LinkedHashTreeMap.kt | 3 +- .../java/com/squareup/moshi/MapJsonAdapter.kt | 2 +- .../src/main/java/com/squareup/moshi/Moshi.kt | 12 +- .../squareup/moshi/StandardJsonAdapters.kt | 10 +- .../src/main/java/com/squareup/moshi/Types.kt | 17 +- .../java/com/squareup/moshi/internal/Util.kt | 35 ++-- .../com/squareup/moshi/RecordJsonAdapter.kt | 10 +- 67 files changed, 546 insertions(+), 495 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 01f31e2..f16ed40 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,14 +51,16 @@ spotless { targetExclude("**/build/**") } kotlin { - ktlint(libs.versions.ktlint.get()).editorConfigOverride(mapOf("indent_size" to "2")) + ktlint(libs.versions.ktlint.get()).editorConfigOverride( + mapOf("ktlint_standard_filename" to "disabled"), + ) target("**/*.kt") trimTrailingWhitespace() endWithNewline() targetExclude("**/Dependencies.kt", "**/build/**") } kotlinGradle { - ktlint(libs.versions.ktlint.get()).editorConfigOverride(mapOf("indent_size" to "2")) + ktlint(libs.versions.ktlint.get()) target("**/*.gradle.kts") trimTrailingWhitespace() endWithNewline() diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 0e249b2..f7217b8 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -15,7 +15,7 @@ dependencies { tasks.withType().configureEach { kotlinOptions { freeCompilerArgs += listOf( - "-opt-in=kotlin.ExperimentalStdlibApi" + "-opt-in=kotlin.ExperimentalStdlibApi", ) } } diff --git a/examples/src/main/java/com/squareup/moshi/recipes/JsonString.kt b/examples/src/main/java/com/squareup/moshi/recipes/JsonString.kt index 975a9cc..94b4fee 100644 --- a/examples/src/main/java/com/squareup/moshi/recipes/JsonString.kt +++ b/examples/src/main/java/com/squareup/moshi/recipes/JsonString.kt @@ -30,7 +30,7 @@ import kotlin.annotation.AnnotationRetention.RUNTIME @JsonClass(generateAdapter = true) data class ExampleClass( val type: Int, - @JsonString val rawJson: String + @JsonString val rawJson: String, ) @Retention(RUNTIME) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 532cc38..0cbedcb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ kotlin = "1.7.0" kotlinCompileTesting = "1.4.9" kotlinpoet = "1.12.0" ksp = "1.7.0-1.0.6" -ktlint = "0.45.2" +ktlint = "0.48.2" [plugins] dokka = { id = "org.jetbrains.dokka", version = "1.7.20" } @@ -14,7 +14,7 @@ japicmp = { id = "me.champeau.gradle.japicmp", version = "0.2.9" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.24.0" } mavenShadow = { id = "com.github.johnrengelman.shadow", version = "7.1.2" } -spotless = { id = "com.diffplug.spotless", version = "6.7.1" } +spotless = { id = "com.diffplug.spotless", version = "6.14.0" } [libraries] asm = "org.ow2.asm:asm:9.4" diff --git a/moshi-adapters/src/main/java/com/squareup/moshi/Rfc3339DateJsonAdapter.kt b/moshi-adapters/src/main/java/com/squareup/moshi/Rfc3339DateJsonAdapter.kt index 55c4c43..213b26d 100644 --- a/moshi-adapters/src/main/java/com/squareup/moshi/Rfc3339DateJsonAdapter.kt +++ b/moshi-adapters/src/main/java/com/squareup/moshi/Rfc3339DateJsonAdapter.kt @@ -23,7 +23,7 @@ import java.util.Date """This class moved to avoid a package name conflict in the Java Platform Module System. The new class is com.squareup.moshi.adapters.Rfc3339DateJsonAdapter.""", replaceWith = ReplaceWith("com.squareup.moshi.adapters.Rfc3339DateJsonAdapter"), - level = DeprecationLevel.ERROR + level = DeprecationLevel.ERROR, ) public class Rfc3339DateJsonAdapter : JsonAdapter() { diff --git a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/EnumJsonAdapter.kt b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/EnumJsonAdapter.kt index 8d62cc2..55b5119 100644 --- a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/EnumJsonAdapter.kt +++ b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/EnumJsonAdapter.kt @@ -78,12 +78,12 @@ public class EnumJsonAdapter> internal constructor( if (!useFallbackValue) { val name = reader.nextString() throw JsonDataException( - "Expected one of ${nameStrings.toList()} but was $name at path $path" + "Expected one of ${nameStrings.toList()} but was $name at path $path", ) } if (reader.peek() != STRING) { throw JsonDataException( - "Expected a string but was ${reader.peek()} at path $path" + "Expected a string but was ${reader.peek()} at path $path", ) } reader.skipValue() @@ -94,7 +94,7 @@ public class EnumJsonAdapter> internal constructor( override fun toJson(writer: JsonWriter, value: T?) { if (value == null) { throw NullPointerException( - "value was null! Wrap in .nullSafe() to write nullable values." + "value was null! Wrap in .nullSafe() to write nullable values.", ) } writer.value(nameStrings[value.ordinal]) diff --git a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/Iso8601Utils.kt b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/Iso8601Utils.kt index 26c0569..12d2e2a 100644 --- a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/Iso8601Utils.kt +++ b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/Iso8601Utils.kt @@ -107,7 +107,6 @@ internal fun String.parseIsoDate(): Date { return GregorianCalendar(year, month - 1, day).time } if (hasT) { - // extract hours, minutes, seconds and milliseconds hour = parseInt(this, 1.let { offset += it; offset }, 2.let { offset += it; offset }) if (checkOffset(this, offset, ':')) { @@ -164,14 +163,14 @@ internal fun String.parseIsoDate(): Date { val cleaned = act.replace(":", "") if (cleaned != timezoneId) { throw IndexOutOfBoundsException( - "Mismatching time zone indicator: $timezoneId given, resolves to ${timezone.id}" + "Mismatching time zone indicator: $timezoneId given, resolves to ${timezone.id}", ) } } } } else { throw IndexOutOfBoundsException( - "Invalid time zone indicator '$timezoneIndicator'" + "Invalid time zone indicator '$timezoneIndicator'", ) } val calendar: Calendar = GregorianCalendar(timezone) diff --git a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt index 96ed710..74e5b83 100644 --- a/moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt +++ b/moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt @@ -103,7 +103,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( private val labelKey: String, private val labels: List, private val subtypes: List, - private val fallbackJsonAdapter: JsonAdapter? + private val fallbackJsonAdapter: JsonAdapter?, ) : Factory { /** Returns a new factory that decodes instances of `subtype`. */ public fun withSubtype(subtype: Class, label: String): PolymorphicJsonAdapterFactory { @@ -121,7 +121,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( labelKey = labelKey, labels = newLabels, subtypes = newSubtypes, - fallbackJsonAdapter = fallbackJsonAdapter + fallbackJsonAdapter = fallbackJsonAdapter, ) } @@ -133,14 +133,14 @@ public class PolymorphicJsonAdapterFactory internal constructor( * it within your implementation of [JsonAdapter.fromJson] */ public fun withFallbackJsonAdapter( - fallbackJsonAdapter: JsonAdapter? + fallbackJsonAdapter: JsonAdapter?, ): PolymorphicJsonAdapterFactory { return PolymorphicJsonAdapterFactory( baseType = baseType, labelKey = labelKey, labels = labels, subtypes = subtypes, - fallbackJsonAdapter = fallbackJsonAdapter + fallbackJsonAdapter = fallbackJsonAdapter, ) } @@ -161,7 +161,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( override fun toJson(writer: JsonWriter, value: Any?) { throw IllegalArgumentException( - "Expected one of $subtypes but found $value, a ${value?.javaClass}. Register this subtype." + "Expected one of $subtypes but found $value, a ${value?.javaClass}. Register this subtype.", ) } } @@ -181,7 +181,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( private val labels: List, private val subtypes: List, private val jsonAdapters: List>, - private val fallbackJsonAdapter: JsonAdapter? + private val fallbackJsonAdapter: JsonAdapter?, ) : JsonAdapter() { /** Single-element options containing the label's key only. */ private val labelKeyOptions: Options = Options.of(labelKey) @@ -211,7 +211,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( val labelIndex = reader.selectString(labelOptions) if (labelIndex == -1 && fallbackJsonAdapter == null) { throw JsonDataException( - "Expected one of $labels for key '$labelKey' but found '${reader.nextString()}'. Register a subtype for this label." + "Expected one of $labels for key '$labelKey' but found '${reader.nextString()}'. Register a subtype for this label.", ) } return labelIndex @@ -259,7 +259,7 @@ public class PolymorphicJsonAdapterFactory internal constructor( labelKey = labelKey, labels = emptyList(), subtypes = emptyList(), - fallbackJsonAdapter = null + fallbackJsonAdapter = null, ) } } diff --git a/moshi-kotlin-codegen/build.gradle.kts b/moshi-kotlin-codegen/build.gradle.kts index 810e89c..47a6cb7 100644 --- a/moshi-kotlin-codegen/build.gradle.kts +++ b/moshi-kotlin-codegen/build.gradle.kts @@ -34,7 +34,7 @@ tasks.withType().configureEach { "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", - "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" + "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", ) } @@ -91,7 +91,7 @@ val shadowJar = tasks.shadowJar.apply { relocate("com.squareup.kotlinpoet.metadata", "com.squareup.moshi.kotlinpoet.metadata") relocate( "com.squareup.kotlinpoet.classinspector", - "com.squareup.moshi.kotlinpoet.classinspector" + "com.squareup.moshi.kotlinpoet.classinspector", ) relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata") transformers.add(ServiceFileTransformer()) diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt index 5ed37d3..116c3cb 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt @@ -54,14 +54,14 @@ private const val TO_STRING_SIZE_BASE = TO_STRING_PREFIX.length + 1 // 1 is the @InternalMoshiCodegenApi public class AdapterGenerator( private val target: TargetType, - private val propertyList: List + private val propertyList: List, ) { private companion object { private val INT_TYPE_BLOCK = CodeBlock.of("%T::class.javaPrimitiveType", INT) private val DEFAULT_CONSTRUCTOR_MARKER_TYPE_BLOCK = CodeBlock.of( "%M", - MemberName(MOSHI_UTIL_PACKAGE, "DEFAULT_CONSTRUCTOR_MARKER") + MemberName(MOSHI_UTIL_PACKAGE, "DEFAULT_CONSTRUCTOR_MARKER"), ) private val CN_MOSHI = Moshi::class.asClassName() private val CN_TYPE = Type::class.asClassName() @@ -89,13 +89,13 @@ public class AdapterGenerator( "PLATFORM_CLASS_MAPPED_TO_KOTLIN", // Cover for calling fromJson() on a Nothing property type. Theoretically nonsensical but we // support it - "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION" + "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION", ).let { suppressions -> AnnotationSpec.builder(Suppress::class) .useSiteTarget(FILE) .addMember( suppressions.indices.joinToString { "%S" }, - *suppressions + *suppressions, ) .build() } @@ -116,54 +116,55 @@ public class AdapterGenerator( private val moshiParam = ParameterSpec.builder( nameAllocator.newName("moshi"), - CN_MOSHI + CN_MOSHI, ).build() private val typesParam = ParameterSpec.builder( nameAllocator.newName("types"), - ARRAY.parameterizedBy(CN_TYPE) + ARRAY.parameterizedBy(CN_TYPE), ) .build() private val readerParam = ParameterSpec.builder( nameAllocator.newName("reader"), - JsonReader::class + JsonReader::class, ) .build() private val writerParam = ParameterSpec.builder( nameAllocator.newName("writer"), - JsonWriter::class + JsonWriter::class, ) .build() + // Don't use NameAllocator here because it will add `_` to the name since it's a keyword, and that // results in it warning about not matching the overridden function's params. // https://github.com/square/moshi/issues/1502 private val valueParam = ParameterSpec.builder( "value", - originalTypeName.copy(nullable = true) + originalTypeName.copy(nullable = true), ) .build() private val jsonAdapterTypeName = JsonAdapter::class.asClassName().parameterizedBy( - originalTypeName + originalTypeName, ) // selectName() API setup private val optionsProperty = PropertySpec.builder( nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(), - KModifier.PRIVATE + KModifier.PRIVATE, ) .initializer( "%T.of(%L)", JsonReader.Options::class.asTypeName(), nonTransientProperties .map { CodeBlock.of("%S", it.jsonName) } - .joinToCode(", ") + .joinToCode(", "), ) .build() private val constructorProperty = PropertySpec.builder( nameAllocator.newName("constructorRef"), Constructor::class.asClassName().parameterizedBy(originalTypeName).copy(nullable = true), - KModifier.PRIVATE + KModifier.PRIVATE, ) .addAnnotation(Volatile::class) .mutable(true) @@ -245,10 +246,10 @@ public class AdapterGenerator( " ${if (typeVariables.size == 1) "type" else "types"} for generic type variables [", typeVariables.joinToString(", ") { it.name }, "], but received ", - "${typesParam.name}.size" + "${typesParam.name}.size", ) .endControlFlow() - .build() + .build(), ) } @@ -274,8 +275,8 @@ public class AdapterGenerator( nameAllocator, typeRenderer, moshiParam, - uniqueAdapter.name - ) + uniqueAdapter.name, + ), ) } @@ -309,7 +310,7 @@ public class AdapterGenerator( size, TO_STRING_PREFIX, name, - ")" + ")", ) .build() } @@ -425,7 +426,7 @@ public class AdapterGenerator( "%N = %N.fromJson(%N)", property.localName, nameAllocator[property.delegateKey], - readerParam + readerParam, ) } else { val exception = unexpectedNull(property, readerParam) @@ -434,7 +435,7 @@ public class AdapterGenerator( property.localName, nameAllocator[property.delegateKey], readerParam, - exception + exception, ) } if (property.hasConstructorDefault) { @@ -446,7 +447,7 @@ public class AdapterGenerator( result.addStatement( "%1L = %1L and 0x%2L.toInt()", maskNames[maskNameIndex], - Integer.toHexString(inverted) + Integer.toHexString(inverted), ) } else { // Presence tracker for a mutable property @@ -460,7 +461,7 @@ public class AdapterGenerator( propertyIndex, property.localName, nameAllocator[property.delegateKey], - readerParam + readerParam, ) } else { val exception = unexpectedNull(property, readerParam) @@ -470,7 +471,7 @@ public class AdapterGenerator( property.localName, nameAllocator[property.delegateKey], readerParam, - exception + exception, ) } } @@ -550,7 +551,7 @@ public class AdapterGenerator( val coreLookupBlock = CodeBlock.of( "%T::class.java.getDeclaredConstructor(%L)", originalRawTypeName, - args + args, ) val lookupBlock = if (originalTypeName is ParameterizedTypeName) { CodeBlock.of("(%L·as·%T)", coreLookupBlock, nonNullConstructorType) @@ -560,16 +561,16 @@ public class AdapterGenerator( val initializerBlock = CodeBlock.of( "this.%1N·?: %2L.also·{ this.%1N·= it }", constructorProperty, - lookupBlock + lookupBlock, ) val localConstructorProperty = PropertySpec.builder( nameAllocator.newName("localConstructor"), - nonNullConstructorType + nonNullConstructorType, ) .addAnnotation( AnnotationSpec.builder(Suppress::class) .addMember("%S", "UNCHECKED_CAST") - .build() + .build(), ) .initializer(initializerBlock) .build() @@ -577,7 +578,7 @@ public class AdapterGenerator( result.addCode( "«%L%N.newInstance(", returnOrResultAssignment, - localConstructorProperty + localConstructorProperty, ) } else { // Standard constructor call. Don't omit generics for parameterized types even if they can be @@ -597,7 +598,7 @@ public class AdapterGenerator( result.addCode( "/*·%L·*/·%L", input.parameter.name, - input.type.rawType().defaultPrimitiveValue() + input.type.rawType().defaultPrimitiveValue(), ) } else { result.addCode("%N", (input as ParameterProperty).property.localName) @@ -638,7 +639,7 @@ public class AdapterGenerator( "%N.%N = %N", resultName, property.name, - property.localName + property.localName, ) result.endControlFlow() } else { @@ -646,7 +647,7 @@ public class AdapterGenerator( "%1N.%2N = %3N ?: %1N.%2N", resultName, property.name, - property.localName + property.localName, ) } } @@ -663,7 +664,7 @@ public class AdapterGenerator( MemberName(MOSHI_UTIL_PACKAGE, "unexpectedNull"), property.localName, property.jsonName, - reader + reader, ) } @@ -677,7 +678,7 @@ public class AdapterGenerator( result.addStatement( "throw·%T(%S)", NullPointerException::class, - "${valueParam.name} was null! Wrap in .nullSafe() to write nullable values." + "${valueParam.name} was null! Wrap in .nullSafe() to write nullable values.", ) result.endControlFlow() @@ -690,7 +691,7 @@ public class AdapterGenerator( nameAllocator[property.delegateKey], writerParam, valueParam, - property.name + property.name, ) } result.addStatement("%N.endObject()", writerParam) @@ -706,7 +707,7 @@ private fun FunSpec.Builder.addMissingPropertyCheck(property: PropertyGenerator, MemberName(MOSHI_UTIL_PACKAGE, "missingProperty"), property.localName, property.jsonName, - readerParam + readerParam, ) addCode(" ?: throw·%L", missingPropertyBlock) } @@ -753,20 +754,20 @@ private sealed class FromJsonComponent { abstract val type: TypeName data class ParameterOnly( - override val parameter: TargetParameter + override val parameter: TargetParameter, ) : FromJsonComponent(), ParameterComponent { override val type: TypeName = parameter.type } data class PropertyOnly( - override val property: PropertyGenerator + override val property: PropertyGenerator, ) : FromJsonComponent(), PropertyComponent { override val type: TypeName = property.target.type } data class ParameterProperty( override val parameter: TargetParameter, - override val property: PropertyGenerator + override val property: PropertyGenerator, ) : FromJsonComponent(), ParameterComponent, PropertyComponent { override val type: TypeName = parameter.type } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/DelegateKey.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/DelegateKey.kt index 13b91ec..c7ad46b 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/DelegateKey.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/DelegateKey.kt @@ -46,20 +46,20 @@ public data class DelegateKey( nameAllocator: NameAllocator, typeRenderer: TypeRenderer, moshiParameter: ParameterSpec, - propertyName: String + propertyName: String, ): PropertySpec { val qualifierNames = jsonQualifiers.joinToString("") { "At${it.typeName.rawType().simpleName}" } val adapterName = nameAllocator.newName( "${type.toVariableName().replaceFirstChar { it.lowercase(Locale.US) }}${qualifierNames}Adapter", - this + this, ) val adapterTypeName = JsonAdapter::class.asClassName().parameterizedBy(type) val standardArgs = arrayOf( moshiParameter, - typeRenderer.render(type) + typeRenderer.render(type), ) val (initializerString, args) = when { @@ -81,7 +81,7 @@ private fun AnnotationSpec.asInstantiationExpression(): CodeBlock { return CodeBlock.of( "%T(%L)", typeName, - members.joinToCode() + members.joinToCode(), ) } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/InternalMoshiCodegenApi.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/InternalMoshiCodegenApi.kt index 2cb62a4..cd9d417 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/InternalMoshiCodegenApi.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/InternalMoshiCodegenApi.kt @@ -20,6 +20,6 @@ package com.squareup.moshi.kotlin.codegen.api @Retention(value = AnnotationRetention.BINARY) @RequiresOptIn( level = RequiresOptIn.Level.WARNING, - message = "This is an internal API and may change at any time." + message = "This is an internal API and may change at any time.", ) public annotation class InternalMoshiCodegenApi diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/Options.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/Options.kt index 70652ae..d725595 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/Options.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/Options.kt @@ -47,6 +47,6 @@ public object Options { public val POSSIBLE_GENERATED_NAMES: Map = arrayOf( ClassName("javax.annotation.processing", "Generated"), - ClassName("javax.annotation", "Generated") + ClassName("javax.annotation", "Generated"), ).associateBy { it.canonicalName } } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/PropertyGenerator.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/PropertyGenerator.kt index 3c20255..62b58e1 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/PropertyGenerator.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/PropertyGenerator.kt @@ -24,7 +24,7 @@ import com.squareup.kotlinpoet.PropertySpec public class PropertyGenerator( public val target: TargetProperty, public val delegateKey: DelegateKey, - public val isTransient: Boolean = false + public val isTransient: Boolean = false, ) { public val name: String = target.name public val jsonName: String = target.jsonName ?: target.name diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetConstructor.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetConstructor.kt index b97c357..926d0c8 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetConstructor.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetConstructor.kt @@ -22,7 +22,7 @@ import com.squareup.kotlinpoet.KModifier public data class TargetConstructor( val parameters: LinkedHashMap, val visibility: KModifier, - val signature: String? + val signature: String?, ) { init { visibility.checkIsVisibility() diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetParameter.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetParameter.kt index cdb1f18..9f2bd00 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetParameter.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetParameter.kt @@ -27,5 +27,5 @@ public data class TargetParameter( val hasDefault: Boolean, val jsonName: String? = null, val jsonIgnore: Boolean = false, - val qualifiers: Set? = null + val qualifiers: Set? = null, ) diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetProperty.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetProperty.kt index 3f86eb4..1ea61bd 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetProperty.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TargetProperty.kt @@ -26,7 +26,7 @@ public data class TargetProperty( val parameter: TargetParameter?, val visibility: KModifier, val jsonName: String?, - val jsonIgnore: Boolean + val jsonIgnore: Boolean, ) { val name: String get() = propertySpec.name val type: TypeName get() = propertySpec.type diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TypeRenderer.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TypeRenderer.kt index d9ca043..a0b040b 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TypeRenderer.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/TypeRenderer.kt @@ -63,7 +63,7 @@ internal abstract class TypeRenderer { CodeBlock.of( "%T.arrayOf(%L)", Types::class, - renderObjectType(typeName.typeArguments[0]) + renderObjectType(typeName.typeArguments[0]), ) } else { val builder = CodeBlock.builder().apply { @@ -97,7 +97,7 @@ internal abstract class TypeRenderer { method = "subtypeOf" } else -> throw IllegalArgumentException( - "Unrepresentable wildcard type. Cannot have more than one bound: $typeName" + "Unrepresentable wildcard type. Cannot have more than one bound: $typeName", ) } CodeBlock.of("%T.%L(%L)", Types::class, method, render(target, forceBox = true)) diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/kotlintypes.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/kotlintypes.kt index 680c760..6d22ebf 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/kotlintypes.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/kotlintypes.kt @@ -95,7 +95,7 @@ internal fun TypeName.asTypeBlock(): CodeBlock { CodeBlock.of( "%T.newInstance(%L, 0).javaClass", Array::class.java.asClassName(), - componentType.rawType.asTypeBlock() + componentType.rawType.asTypeBlock(), ) } else { CodeBlock.of("%T::class.java", copy(nullable = false)) @@ -148,7 +148,7 @@ internal fun TypeName.stripTypeVarVariance(resolver: TypeVariableResolver): Type } internal fun ParameterizedTypeName.deepCopy( - transform: (TypeName) -> TypeName + transform: (TypeName) -> TypeName, ): ParameterizedTypeName { return rawType.parameterizedBy(typeArguments.map { transform(it) }) .copy(nullable = isNullable, annotations = annotations, tags = tags) @@ -156,7 +156,7 @@ internal fun ParameterizedTypeName.deepCopy( internal fun TypeVariableName.deepCopy( variance: KModifier? = this.variance, - transform: (TypeName) -> TypeName + transform: (TypeName) -> TypeName, ): TypeVariableName { return TypeVariableName(name = name, bounds = bounds.map { transform(it) }, variance = variance) .copy(nullable = isNullable, annotations = annotations, tags = tags) @@ -184,7 +184,7 @@ internal fun LambdaTypeName.deepCopy(transform: (TypeName) -> TypeName): TypeNam return LambdaTypeName.get( receiver?.let(transform), parameters.map { it.toBuilder(type = transform(it.type)).build() }, - transform(returnType) + transform(returnType), ).copy(nullable = isNullable, annotations = annotations, suspending = isSuspending) } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/AppliedType.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/AppliedType.kt index e619229..26bd539 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/AppliedType.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/AppliedType.kt @@ -31,13 +31,13 @@ private val OBJECT_CLASS = ClassName("java.lang", "Object") */ internal class AppliedType private constructor( val element: TypeElement, - private val mirror: DeclaredType + private val mirror: DeclaredType, ) { /** Returns all supertypes of this, recursively. Only [CLASS] is used as we can't really use other types. */ @OptIn(DelicateKotlinPoetApi::class) fun superclasses( types: Types, - result: LinkedHashSet = LinkedHashSet() + result: LinkedHashSet = LinkedHashSet(), ): LinkedHashSet { result.add(this) for (supertype in types.directSupertypes(mirror)) { diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessor.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessor.kt index 68375d7..0050b9f 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessor.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessor.kt @@ -73,7 +73,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() { generatedType = processingEnv.options[OPTION_GENERATED]?.let { POSSIBLE_GENERATED_NAMES[it] ?: error( "Invalid option value for $OPTION_GENERATED. Found $it, " + - "allowable values are $POSSIBLE_GENERATED_NAMES." + "allowable values are $POSSIBLE_GENERATED_NAMES.", ) } @@ -98,7 +98,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() { messager.printMessage( Diagnostic.Kind.ERROR, "@JsonClass can't be applied to $type: must be a Kotlin class", - type + type, ) continue } @@ -115,10 +115,10 @@ public class JsonClassCodegenProcessor : AbstractProcessor() { AnnotationSpec.builder(generatedClassName) .addMember( "value = [%S]", - JsonClassCodegenProcessor::class.java.canonicalName + JsonClassCodegenProcessor::class.java.canonicalName, ) .addMember("comments = %S", "https://github.com/square/moshi") - .build() + .build(), ) } } @@ -136,7 +136,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() { private fun adapterGenerator( element: TypeElement, - cachedClassInspector: MoshiCachedClassInspector + cachedClassInspector: MoshiCachedClassInspector, ): AdapterGenerator? { val type = targetType( messager, @@ -159,7 +159,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() { messager.printMessage( Diagnostic.Kind.ERROR, "No property for required constructor parameter $name", - element + element, ) return null } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/metadata.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/metadata.kt index dc58972..cccc7bb 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/metadata.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/metadata.kt @@ -66,7 +66,7 @@ private val VISIBILITY_MODIFIERS = setOf( KModifier.INTERNAL, KModifier.PRIVATE, KModifier.PROTECTED, - KModifier.PUBLIC + KModifier.PUBLIC, ) private fun Collection.visibility(): KModifier { @@ -78,7 +78,7 @@ internal fun primaryConstructor( targetElement: TypeElement, kotlinApi: TypeSpec, elements: Elements, - messager: Messager + messager: Messager, ): TargetConstructor? { val primaryConstructor = kotlinApi.primaryConstructor ?: return null @@ -101,14 +101,14 @@ internal fun primaryConstructor( messager.printMessage( ERROR, "No KmConstructor found for primary constructor.", - targetElement + targetElement, ) null } return TargetConstructor( parameters, primaryConstructor.modifiers.visibility(), - kmConstructorSignature + kmConstructorSignature, ) } @@ -127,7 +127,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must be a Kotlin class", - element + element, ) return null } @@ -138,7 +138,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must be a Class type", - element + element, ) return null } @@ -148,7 +148,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass with 'generateAdapter = \"true\"' can't be applied to $element: code gen for enums is not supported or necessary", - element + element, ) return null } @@ -156,7 +156,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must be a Kotlin class", - element + element, ) return null } @@ -164,7 +164,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must not be an inner class", - element + element, ) return null } @@ -172,7 +172,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must not be sealed", - element + element, ) return null } @@ -180,7 +180,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must not be abstract", - element + element, ) return null } @@ -188,7 +188,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must not be local", - element + element, ) return null } @@ -196,7 +196,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: must be internal or public", - element + element, ) return null } @@ -211,7 +211,7 @@ internal fun targetType( messager.printMessage( ERROR, "No primary constructor found on $element", - element + element, ) return null } @@ -220,7 +220,7 @@ internal fun targetType( ERROR, "@JsonClass can't be applied to $element: " + "primary constructor is not internal or public", - element + element, ) return null } @@ -234,7 +234,7 @@ internal fun targetType( messager.printMessage( ERROR, "@JsonClass can't be applied to $element: supertype $superclass is not a Kotlin type", - element + element, ) return null } @@ -272,7 +272,7 @@ internal fun targetType( .cast() .map(TypeVariableName::name) .zip(apiSuperClass.typeArguments.asSequence()) - .associate { it } + .associate { it }, ) } @@ -286,7 +286,7 @@ internal fun targetType( kotlinApi = supertypeApi, allowedTypeVars = typeVariables.toSet(), currentClass = appliedClassName, - resolvedTypes = resolvedTypes + resolvedTypes = resolvedTypes, ) for ((name, property) in supertypeProperties) { properties.putIfAbsent(name, property) @@ -328,7 +328,7 @@ private fun resolveTypeArgs( propertyType: TypeName, resolvedTypes: List, allowedTypeVars: Set, - entryStartIndex: Int = resolvedTypes.indexOfLast { it.target == targetClass } + entryStartIndex: Int = resolvedTypes.indexOfLast { it.target == targetClass }, ): TypeName { val unwrappedType = propertyType.unwrapTypeAlias() @@ -370,7 +370,7 @@ private fun declaredProperties( kotlinApi: TypeSpec, allowedTypeVars: Set, currentClass: ClassName, - resolvedTypes: List + resolvedTypes: List, ): Map { val result = mutableMapOf() for (initialProperty in kotlinApi.propertySpecs) { @@ -378,7 +378,7 @@ private fun declaredProperties( targetClass = currentClass, propertyType = initialProperty.type, resolvedTypes = resolvedTypes, - allowedTypeVars = allowedTypeVars + allowedTypeVars = allowedTypeVars, ) val property = initialProperty.toBuilder(type = resolvedType).build() val name = property.name @@ -391,7 +391,7 @@ private fun declaredProperties( parameter = parameter, visibility = property.modifiers.visibility(), jsonName = parameter?.jsonName ?: property.annotations.jsonName() ?: name, - jsonIgnore = isIgnored + jsonIgnore = isIgnored, ) } @@ -420,7 +420,7 @@ internal fun TargetProperty.generator( messager.printMessage( ERROR, "No default value for transient/ignored property $name", - sourceElement + sourceElement, ) return null } @@ -431,7 +431,7 @@ internal fun TargetProperty.generator( messager.printMessage( ERROR, "property $name is not visible", - sourceElement + sourceElement, ) return null } @@ -452,7 +452,7 @@ internal fun TargetProperty.generator( if (it.value != RetentionPolicy.RUNTIME) { messager.printMessage( ERROR, - "JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention" + "JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention", ) } } @@ -466,13 +466,13 @@ internal fun TargetProperty.generator( return PropertyGenerator( this, - DelegateKey(type, jsonQualifierSpecs) + DelegateKey(type, jsonQualifierSpecs), ) } private fun List?.qualifiers( messager: Messager, - elements: Elements + elements: Elements, ): Set { if (this == null) return setOf() return filterTo(mutableSetOf()) { diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/AppliedType.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/AppliedType.kt index f820bb4..41c0fad 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/AppliedType.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/AppliedType.kt @@ -32,7 +32,7 @@ private val OBJECT_CLASS = java.lang.Object::class.asClassName() */ internal class AppliedType private constructor( val type: KSClassDeclaration, - val typeName: TypeName = type.toClassName() + val typeName: TypeName = type.toClassName(), ) { /** Returns all super classes of this, recursively. Only [CLASS] is used as we can't really use other types. */ diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt index f324f6f..c1f23ed 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt @@ -48,7 +48,7 @@ public class JsonClassSymbolProcessorProvider : SymbolProcessorProvider { } private class JsonClassSymbolProcessor( - environment: SymbolProcessorEnvironment + environment: SymbolProcessorEnvironment, ) : SymbolProcessor { private companion object { @@ -103,7 +103,7 @@ private class JsonClassSymbolProcessor( preparedAdapter.proguardConfig?.writeTo(codeGenerator, originatingFile) } catch (e: Exception) { logger.error( - "Error preparing ${type.simpleName.asString()}: ${e.stackTrace.joinToString("\n")}" + "Error preparing ${type.simpleName.asString()}: ${e.stackTrace.joinToString("\n")}", ) } } @@ -152,7 +152,7 @@ private fun ProguardConfig.writeTo(codeGenerator: CodeGenerator, originatingKSFi dependencies = Dependencies(aggregating = false, originatingKSFile), packageName = "", fileName = outputFilePathWithoutExtension(targetClass.canonicalName), - extensionName = "pro" + extensionName = "pro", ) // Don't use writeTo(file) because that tries to handle directories under the hood OutputStreamWriter(file, StandardCharsets.UTF_8) diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/KspUtil.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/KspUtil.kt index 003b9fa..b2302e5 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/KspUtil.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/KspUtil.kt @@ -89,8 +89,9 @@ private fun addValueToBlock(value: Any, resolver: Resolver, member: CodeBlock.Bu } is KSName -> member.add( - "%T.%L", ClassName.bestGuess(value.getQualifier()), - value.getShortName() + "%T.%L", + ClassName.bestGuess(value.getQualifier()), + value.getShortName(), ) is KSAnnotation -> member.add("%L", value.toAnnotationSpec(resolver)) else -> member.add(memberForValue(value)) diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/MoshiApiUtil.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/MoshiApiUtil.kt index dac1d55..70c7c88 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/MoshiApiUtil.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/MoshiApiUtil.kt @@ -48,7 +48,7 @@ internal fun TargetProperty.generator( if (!hasDefault) { logger.error( "No default value for transient/ignored property $name", - originalType + originalType, ) return null } @@ -58,7 +58,7 @@ internal fun TargetProperty.generator( if (!isVisible) { logger.error( "property $name is not visible", - originalType + originalType, ) return null } @@ -76,7 +76,7 @@ internal fun TargetProperty.generator( annotationElement.findAnnotationWithType()?.let { if (it.value != AnnotationRetention.RUNTIME) { logger.error( - "JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention" + "JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention", ) } } @@ -91,7 +91,7 @@ internal fun TargetProperty.generator( return PropertyGenerator( this, - DelegateKey(type, jsonQualifierSpecs) + DelegateKey(type, jsonQualifierSpecs), ) } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/TargetTypes.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/TargetTypes.kt index c4be956..7f5aa86 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/TargetTypes.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/TargetTypes.kt @@ -86,7 +86,7 @@ internal fun targetType( } val classTypeParamsResolver = type.typeParameters.toTypeParameterResolver( - sourceTypeHint = type.qualifiedName!!.asString() + sourceTypeHint = type.qualifiedName!!.asString(), ) val typeVariables = type.typeParameters.map { it.toTypeVariableName(classTypeParamsResolver) } val appliedType = AppliedType(type) @@ -100,7 +100,7 @@ internal fun targetType( logger.error( "@JsonClass can't be applied to $type: " + "primary constructor is not internal or public", - type + type, ) return null } @@ -117,7 +117,7 @@ internal fun targetType( Origin=${classDecl.origin} Annotations=${classDecl.annotations.joinToString(prefix = "[", postfix = "]") { it.shortName.getShortName() }} """.trimIndent(), - type + type, ) return null } @@ -127,7 +127,7 @@ internal fun targetType( classDecl = classDecl, resolver = resolver, typeParameterResolver = classDecl.typeParameters - .toTypeParameterResolver(classTypeParamsResolver) + .toTypeParameterResolver(classTypeParamsResolver), ) for ((name, property) in supertypeProperties) { properties.putIfAbsent(name, property) @@ -169,7 +169,7 @@ internal fun primaryConstructor( resolver: Resolver, targetType: KSClassDeclaration, typeParameterResolver: TypeParameterResolver, - logger: KSPLogger + logger: KSPLogger, ): TargetConstructor? { val primaryConstructor = targetType.primaryConstructor ?: return null @@ -182,7 +182,7 @@ internal fun primaryConstructor( type = parameter.type.toTypeName(typeParameterResolver), hasDefault = parameter.hasDefault, qualifiers = parameter.qualifiers(resolver), - jsonName = parameter.jsonName() + jsonName = parameter.jsonName(), ) } @@ -194,7 +194,7 @@ internal fun primaryConstructor( return TargetConstructor( parameters, primaryConstructor.getVisibility().toKModifier() ?: KModifier.PUBLIC, - kmConstructorSignature + kmConstructorSignature, ) } @@ -244,7 +244,7 @@ private fun declaredProperties( parameter = parameter, visibility = property.getVisibility().toKModifier() ?: KModifier.PUBLIC, jsonName = parameter?.jsonName ?: property.jsonName() ?: name, - jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore() + jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore(), ) } @@ -254,11 +254,11 @@ private fun declaredProperties( private fun KSPropertyDeclaration.toPropertySpec( resolver: Resolver, resolvedType: KSType, - typeParameterResolver: TypeParameterResolver + typeParameterResolver: TypeParameterResolver, ): PropertySpec { return PropertySpec.builder( name = simpleName.getShortName(), - type = resolvedType.toTypeName(typeParameterResolver).unwrapTypeAlias() + type = resolvedType.toTypeName(typeParameterResolver).unwrapTypeAlias(), ) .mutable(isMutable) .addModifiers(modifiers.map { KModifier.valueOf(it.name) }) @@ -273,7 +273,7 @@ private fun KSPropertyDeclaration.toPropertySpec( null } } - .asIterable() + .asIterable(), ) } .build() diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt index 9b5e1ce..553a541 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt @@ -56,7 +56,7 @@ private fun KSAnnotation.toAnnotation(annotationClass: Class return Proxy.newProxyInstance( annotationClass.classLoader, arrayOf(annotationClass), - createInvocationHandler(annotationClass) + createInvocationHandler(annotationClass), ) as T } @@ -119,8 +119,9 @@ private fun KSAnnotation.asAnnotation( annotationInterface: Class<*>, ): Any { return Proxy.newProxyInstance( - this.javaClass.classLoader, arrayOf(annotationInterface), - this.createInvocationHandler(annotationInterface) + this.javaClass.classLoader, + arrayOf(annotationInterface), + this.createInvocationHandler(annotationInterface), ) as Proxy } @@ -158,7 +159,7 @@ private fun List<*>.asArray(method: Method) = private fun List<*>.toArray(method: Method, valueProvider: (Any) -> Any): Array { val array: Array = java.lang.reflect.Array.newInstance( method.returnType.componentType, - this.size + this.size, ) as Array for (r in 0 until this.size) { array[r] = this[r]?.let { valueProvider.invoke(it) } @@ -176,7 +177,7 @@ private fun Any.asEnum(returnType: Class): T = this.declaration.simpleName.getShortName() } else { this.toString() - } + }, ) as T private fun Any.asByte(): Byte = if (this is Int) this.toByte() else this as Byte diff --git a/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessorTest.kt b/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessorTest.kt index afc875d..28f86b6 100644 --- a/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessorTest.kt +++ b/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessorTest.kt @@ -39,7 +39,8 @@ import kotlin.reflect.full.declaredMemberProperties /** Execute kotlinc to confirm that either files are generated or errors are printed. */ class JsonClassCodegenProcessorTest { - @Rule @JvmField val temporaryFolder: TemporaryFolder = TemporaryFolder() + @Rule @JvmField + val temporaryFolder: TemporaryFolder = TemporaryFolder() @Test fun privateConstructor() { @@ -57,8 +58,8 @@ class JsonClassCodegenProcessorTest { fun newInstance(a: Int, b: Int) = PrivateConstructor(a, b) } } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("constructor is not internal or public") @@ -74,8 +75,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class PrivateConstructorParameter(private var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -94,8 +95,8 @@ class JsonClassCodegenProcessorTest { private var a: Int = -1 private var b: Int = -1 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -111,12 +112,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) interface Interface - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to Interface: must be a Kotlin class" + "error: @JsonClass can't be applied to Interface: must be a Kotlin class", ) } @@ -130,8 +131,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true, generator="customGenerator") interface Interface - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) } @@ -146,12 +147,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) abstract class AbstractClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to AbstractClass: must not be abstract" + "error: @JsonClass can't be applied to AbstractClass: must not be abstract", ) } @@ -165,12 +166,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) sealed class SealedClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to SealedClass: must not be sealed" + "error: @JsonClass can't be applied to SealedClass: must not be sealed", ) } @@ -186,12 +187,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) inner class InnerClass(val a: Int) } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to Outer.InnerClass: must not be an inner class" + "error: @JsonClass can't be applied to Outer.InnerClass: must not be an inner class", ) } @@ -207,12 +208,12 @@ class JsonClassCodegenProcessorTest { enum class KotlinEnum { A, B } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass with 'generateAdapter = \"true\"' can't be applied to KotlinEnum: code gen for enums is not supported or necessary" + "error: @JsonClass with 'generateAdapter = \"true\"' can't be applied to KotlinEnum: code gen for enums is not supported or necessary", ) } @@ -230,12 +231,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class LocalClass(val a: Int) } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to LocalClass: must not be local" + "error: @JsonClass can't be applied to LocalClass: must not be local", ) } @@ -249,12 +250,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) private class PrivateClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to PrivateClass: must be internal or public" + "error: @JsonClass can't be applied to PrivateClass: must be internal or public", ) } @@ -270,12 +271,12 @@ class JsonClassCodegenProcessorTest { object ObjectDeclaration { var a = 5 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to ObjectDeclaration: must be a Kotlin class" + "error: @JsonClass can't be applied to ObjectDeclaration: must be a Kotlin class", ) } @@ -291,12 +292,12 @@ class JsonClassCodegenProcessorTest { val expression = object : Any() { var a = 5 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: @JsonClass can't be applied to getExpression\$annotations(): must be a Kotlin class" + "error: @JsonClass can't be applied to getExpression\$annotations(): must be a Kotlin class", ) } @@ -310,12 +311,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class RequiredTransientConstructorParameter(@Transient var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: No default value for transient/ignored property a" + "error: No default value for transient/ignored property a", ) } @@ -330,12 +331,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class RequiredIgnoredConstructorParameter(@Json(ignore = true) var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: No default value for transient/ignored property a" + "error: No default value for transient/ignored property a", ) } @@ -349,12 +350,12 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class NonPropertyConstructorParameter(a: Int, val b: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "error: No property for required constructor parameter a" + "error: No property for required constructor parameter a", ) } @@ -368,15 +369,16 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) data class Foo(val a: Int) - """ - ) + """, + ), ).apply { kaptArgs[OPTION_GENERATED] = "javax.annotation.GeneratedBlerg" }.compile() assertThat(result.messages).contains( - "Invalid option value for $OPTION_GENERATED" + "Invalid option value for $OPTION_GENERATED", ) } + @Test fun disableProguardRulesGenerating() { val result = prepareCompilation( @@ -387,8 +389,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) data class Foo(val a: Int) - """ - ) + """, + ), ).apply { kaptArgs[OPTION_GENERATE_PROGUARD_RULES] = "false" }.compile() @@ -408,8 +410,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class Class2(private var c: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -427,8 +429,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class ExtendsPlatformClass(var a: Int) : Date() - """ - ) + """, + ), ) assertThat(result.messages).contains("supertype java.util.Date is not a Kotlin type") } @@ -444,8 +446,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class ExtendsJavaType(var b: Int) : JavaSuperclass() - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages) @@ -472,8 +474,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ - ) + """, + ), ) // We instantiate directly so doesn't need to be FIELD assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -500,8 +502,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention") @@ -520,8 +522,8 @@ class JsonClassCodegenProcessorTest { @JsonClass(generateAdapter = true) data class Person(val firstName: FirstName, val lastName: LastName, val hairColor: String) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -530,7 +532,7 @@ class JsonClassCodegenProcessorTest { val adapterClass = result.classLoader.loadClass("PersonJsonAdapter").kotlin assertThat(adapterClass.declaredMemberProperties.map { it.returnType }).containsExactly( JsonReader.Options::class.createType(), - JsonAdapter::class.parameterizedBy(String::class) + JsonAdapter::class.parameterizedBy(String::class), ) } @@ -648,8 +650,8 @@ class JsonClassCodegenProcessorTest { val arg64: Long = 64, val arg65: Long = 65 ) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -663,7 +665,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.AliasesJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Simple" -> assertThat(generatedFile.readText()).contains( """ @@ -673,7 +675,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.SimpleJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Generic" -> assertThat(generatedFile.readText()).contains( """ @@ -683,7 +685,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.GenericJsonAdapter { public (com.squareup.moshi.Moshi,java.lang.reflect.Type[]); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.UsingQualifiers" -> { assertThat(generatedFile.readText()).contains( @@ -694,7 +696,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.UsingQualifiersJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) } "moshi-testPackage.MixedTypes" -> assertThat(generatedFile.readText()).contains( @@ -705,7 +707,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.MixedTypesJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.DefaultParams" -> assertThat(generatedFile.readText()).contains( """ @@ -721,7 +723,7 @@ class JsonClassCodegenProcessorTest { -keepclassmembers class testPackage.DefaultParams { public synthetic (java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Complex" -> { assertThat(generatedFile.readText()).contains( @@ -738,7 +740,7 @@ class JsonClassCodegenProcessorTest { -keepclassmembers class testPackage.Complex { public synthetic (java.lang.String,java.util.List,java.lang.Object,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) } "moshi-testPackage.MultipleMasks" -> assertThat(generatedFile.readText()).contains( @@ -755,7 +757,7 @@ class JsonClassCodegenProcessorTest { -keepclassmembers class testPackage.MultipleMasks { public synthetic (long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,int,int,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.NestedType.NestedSimple" -> { assertThat(generatedFile.readText()).contains( @@ -766,7 +768,7 @@ class JsonClassCodegenProcessorTest { -keep class testPackage.NestedType_NestedSimpleJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) } else -> error("Unexpected proguard file! ${generatedFile.name}") @@ -795,7 +797,7 @@ class JsonClassCodegenProcessorTest { private fun KClassifier.parameterizedBy(vararg types: KType): KType { return createType( - types.map { it.asProjection() } + types.map { it.asProjection() }, ) } diff --git a/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorTest.kt b/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorTest.kt index 01930f1..6074f70 100644 --- a/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorTest.kt +++ b/moshi-kotlin-codegen/src/test/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorTest.kt @@ -34,7 +34,8 @@ import org.junit.rules.TemporaryFolder /** Execute kotlinc to confirm that either files are generated or errors are printed. */ class JsonClassSymbolProcessorTest { - @Rule @JvmField val temporaryFolder: TemporaryFolder = TemporaryFolder() + @Rule @JvmField + val temporaryFolder: TemporaryFolder = TemporaryFolder() @Test fun privateConstructor() { @@ -53,8 +54,8 @@ class JsonClassSymbolProcessorTest { fun newInstance(a: Int, b: Int) = PrivateConstructor(a, b) } } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("constructor is not internal or public") @@ -71,8 +72,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class PrivateConstructorParameter(private var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -92,8 +93,8 @@ class JsonClassSymbolProcessorTest { private var a: Int = -1 private var b: Int = -1 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -110,12 +111,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) interface Interface - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.Interface: must be a Kotlin class" + "@JsonClass can't be applied to test.Interface: must be a Kotlin class", ) } @@ -130,8 +131,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true, generator="customGenerator") interface Interface - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) } @@ -147,12 +148,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) abstract class AbstractClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.AbstractClass: must not be abstract" + "@JsonClass can't be applied to test.AbstractClass: must not be abstract", ) } @@ -167,12 +168,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) sealed class SealedClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.SealedClass: must not be sealed" + "@JsonClass can't be applied to test.SealedClass: must not be sealed", ) } @@ -189,12 +190,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) inner class InnerClass(val a: Int) } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.Outer.InnerClass: must not be an inner class" + "@JsonClass can't be applied to test.Outer.InnerClass: must not be an inner class", ) } @@ -211,12 +212,12 @@ class JsonClassSymbolProcessorTest { enum class KotlinEnum { A, B } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass with 'generateAdapter = \"true\"' can't be applied to test.KotlinEnum: code gen for enums is not supported or necessary" + "@JsonClass with 'generateAdapter = \"true\"' can't be applied to test.KotlinEnum: code gen for enums is not supported or necessary", ) } @@ -235,12 +236,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class LocalClass(val a: Int) } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to LocalClass: must not be local" + "@JsonClass can't be applied to LocalClass: must not be local", ) } @@ -255,12 +256,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) private class PrivateClass(val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.PrivateClass: must be internal or public" + "@JsonClass can't be applied to test.PrivateClass: must be internal or public", ) } @@ -277,12 +278,12 @@ class JsonClassSymbolProcessorTest { object ObjectDeclaration { var a = 5 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.ObjectDeclaration: must be a Kotlin class" + "@JsonClass can't be applied to test.ObjectDeclaration: must be a Kotlin class", ) } @@ -299,12 +300,12 @@ class JsonClassSymbolProcessorTest { val expression = object : Any() { var a = 5 } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "@JsonClass can't be applied to test.expression: must be a Kotlin class" + "@JsonClass can't be applied to test.expression: must be a Kotlin class", ) } @@ -319,12 +320,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class RequiredTransientConstructorParameter(@Transient var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "No default value for transient/ignored property a" + "No default value for transient/ignored property a", ) } @@ -340,12 +341,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class RequiredTransientConstructorParameter(@Json(ignore = true) var a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "No default value for transient/ignored property a" + "No default value for transient/ignored property a", ) } @@ -360,12 +361,12 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class NonPropertyConstructorParameter(a: Int, val b: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains( - "No property for required constructor parameter a" + "No property for required constructor parameter a", ) } @@ -380,13 +381,13 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) data class Foo(val a: Int) - """ - ) + """, + ), ).apply { kspArgs[OPTION_GENERATED] = "javax.annotation.GeneratedBlerg" }.compile() assertThat(result.messages).contains( - "Invalid option value for $OPTION_GENERATED" + "Invalid option value for $OPTION_GENERATED", ) } @@ -401,8 +402,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) data class Foo(val a: Int) - """ - ) + """, + ), ).apply { kspArgs[OPTION_GENERATE_PROGUARD_RULES] = "false" } @@ -425,8 +426,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class Class2(private var c: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("property a is not visible") @@ -445,8 +446,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class ExtendsPlatformClass(var a: Int) : Date() - """ - ) + """, + ), ) assertThat(result.messages).contains("supertype java.util.Date is not a Kotlin type") } @@ -463,7 +464,7 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class ExtendsJavaType(var b: Int) : JavaSuperclass() - """ + """, ), java( "JavaSuperclass.java", @@ -472,8 +473,8 @@ class JsonClassSymbolProcessorTest { public class JavaSuperclass { public int a = 1; } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages) @@ -501,8 +502,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ - ) + """, + ), ) // We instantiate directly, no FIELD site target necessary assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -530,8 +531,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR) assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention") @@ -551,8 +552,8 @@ class JsonClassSymbolProcessorTest { @JsonClass(generateAdapter = true) data class Person(val firstName: FirstName, val lastName: LastName, val hairColor: String) - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -680,8 +681,8 @@ class JsonClassSymbolProcessorTest { val arg64: Long = 64, val arg65: Long = 65 ) - """ - ) + """, + ), ) val result = compilation.compile() assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) @@ -696,7 +697,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.AliasesJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Simple" -> assertThat(generatedFile.readText()).contains( """ @@ -706,7 +707,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.SimpleJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Generic" -> assertThat(generatedFile.readText()).contains( """ @@ -716,7 +717,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.GenericJsonAdapter { public (com.squareup.moshi.Moshi,java.lang.reflect.Type[]); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.UsingQualifiers" -> { assertThat(generatedFile.readText()).contains( @@ -727,7 +728,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.UsingQualifiersJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) } "moshi-testPackage.MixedTypes" -> assertThat(generatedFile.readText()).contains( @@ -738,7 +739,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.MixedTypesJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.DefaultParams" -> assertThat(generatedFile.readText()).contains( """ @@ -754,7 +755,7 @@ class JsonClassSymbolProcessorTest { -keepclassmembers class testPackage.DefaultParams { public synthetic (java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.Complex" -> { assertThat(generatedFile.readText()).contains( @@ -771,7 +772,7 @@ class JsonClassSymbolProcessorTest { -keepclassmembers class testPackage.Complex { public synthetic (java.lang.String,java.util.List,java.lang.Object,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) } "moshi-testPackage.MultipleMasks" -> assertThat(generatedFile.readText()).contains( @@ -788,7 +789,7 @@ class JsonClassSymbolProcessorTest { -keepclassmembers class testPackage.MultipleMasks { public synthetic (long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,int,int,int,kotlin.jvm.internal.DefaultConstructorMarker); } - """.trimIndent() + """.trimIndent(), ) "moshi-testPackage.NestedType.NestedSimple" -> { assertThat(generatedFile.readText()).contains( @@ -799,7 +800,7 @@ class JsonClassSymbolProcessorTest { -keep class testPackage.NestedType_NestedSimpleJsonAdapter { public (com.squareup.moshi.Moshi); } - """.trimIndent() + """.trimIndent(), ) } else -> error("Unexpected proguard file! ${generatedFile.name}") diff --git a/moshi-kotlin-tests/build.gradle.kts b/moshi-kotlin-tests/build.gradle.kts index bd9375c..2dab683 100644 --- a/moshi-kotlin-tests/build.gradle.kts +++ b/moshi-kotlin-tests/build.gradle.kts @@ -42,7 +42,7 @@ tasks.withType().configureEach { allWarningsAsErrors = useWError @Suppress("SuspiciousCollectionReassignment") freeCompilerArgs += listOf( - "-opt-in=kotlin.ExperimentalStdlibApi" + "-opt-in=kotlin.ExperimentalStdlibApi", ) } } diff --git a/moshi-kotlin-tests/codegen-only/build.gradle.kts b/moshi-kotlin-tests/codegen-only/build.gradle.kts index d4aafe3..5c9400a 100644 --- a/moshi-kotlin-tests/codegen-only/build.gradle.kts +++ b/moshi-kotlin-tests/codegen-only/build.gradle.kts @@ -43,7 +43,7 @@ tasks.withType().configureEach { allWarningsAsErrors = useWError @Suppress("SuspiciousCollectionReassignment") freeCompilerArgs += listOf( - "-opt-in=kotlin.ExperimentalStdlibApi" + "-opt-in=kotlin.ExperimentalStdlibApi", ) } } diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt index b687b07..9ab7173 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt @@ -30,7 +30,7 @@ import kotlin.annotation.AnnotationTarget.TYPE @JsonClass(generateAdapter = true) data class GenericTestClassWithDefaults( val input: String = "", - val genericInput: T + val genericInput: T, ) @Target(TYPE) @@ -43,28 +43,29 @@ annotation class TypeAnnotation @JsonClass(generateAdapter = true) data class TypeAnnotationClass( val propertyWithAnnotatedType: @TypeAnnotation String = "", - val generic: List<@TypeAnnotation String> + val generic: List<@TypeAnnotation String>, ) // Regression test for https://github.com/square/moshi/issues/1277 @JsonClass(generateAdapter = true) data class OtherTestModel(val TestModel: TestModel? = null) + @JsonClass(generateAdapter = true) data class TestModel( val someVariable: Int, - val anotherVariable: String + val anotherVariable: String, ) // Regression test for https://github.com/square/moshi/issues/1022 @JsonClass(generateAdapter = true) internal data class MismatchParentAndNestedClassVisibility( val type: Int, - val name: String? = null + val name: String? = null, ) { @JsonClass(generateAdapter = true) data class NestedClass( - val nestedProperty: String + val nestedProperty: String, ) } @@ -76,13 +77,13 @@ data class KeysWithSpaces( @Json(name = "3. Last Refreshed") val lastRefreshed: String, @Json(name = "4. Interval") val interval: String, @Json(name = "5. Output Size") val size: String, - @Json(name = "6. Time Zone") val timeZone: String + @Json(name = "6. Time Zone") val timeZone: String, ) // Regression test for https://github.com/square/moshi/issues/848 @JsonClass(generateAdapter = true) data class Hotwords( - val `class`: List? + val `class`: List?, ) /** @@ -115,7 +116,7 @@ data class SmokeTestType( val aliasedName: TypeAliasName = "Woah", val genericAlias: GenericTypeAlias = listOf("Woah"), // Regression test for https://github.com/square/moshi/issues/1272 - val nestedArray: Array>? = null + val nestedArray: Array>? = null, ) typealias TypeAliasName = String @@ -132,11 +133,11 @@ enum class Foo { BAR } @JsonClass(generateAdapter = true) data class ClassWithQualifier( @UpperCase(foo = [Foo.BAR]) - val a: Int + val a: Int, ) // Regression for https://github.com/ZacSweers/MoshiX/issues/120 @JsonClass(generateAdapter = true) data class DataClassInModuleB( - val id: String + val id: String, ) : AbstractClassInModuleA() diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt index 891ea37..022ff57 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt @@ -90,7 +90,7 @@ class ComplexGenericsInheritanceTest { data = Person("layer4F") data2 = "layer4F" data3 = "layer4F" - } + }, ).apply { layer3C = listOf(1, 2, 3) layer3D = "layer3D" @@ -115,7 +115,7 @@ data class Person(val name: String) : Personable @JsonClass(generateAdapter = true) data class PersonResponse( - val extra: String? = null + val extra: String? = null, ) : ResponseWithSettableProperty() abstract class NestedResponse : ResponseWithSettableProperty() @@ -125,7 +125,7 @@ data class NestedPersonResponse(val extra: String? = null) : NestedResponse( - val extra: String? = null + val extra: String? = null, ) : NestedResponse() interface LayerInterface @@ -146,5 +146,5 @@ abstract class Layer3 : Layer2() { @JsonClass(generateAdapter = true) data class Layer4( val layer4E: E, - val layer4F: F? = null + val layer4F: F? = null, ) : Layer3, String>(), LayerInterface diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt index 79b3bfb..eb87c70 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt @@ -62,7 +62,7 @@ data class TestClass( val optional2: Int = 2, val dynamicSelfReferenceOptional: String = required, val dynamicOptional: Int = createInt(), - val dynamicInlineOptional: Int = createInlineInt() + val dynamicInlineOptional: Int = createInlineInt(), ) private fun createInt(): Int { diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt index 311a259..559d727 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt @@ -62,8 +62,8 @@ class GeneratedAdaptersTest { assertThat( adapter.toJson( - JsonAnnotation("baz") - ) + JsonAnnotation("baz"), + ), ).isEqualTo(expectedJson) } @@ -85,8 +85,8 @@ class GeneratedAdaptersTest { assertThat( adapter.toJson( - JsonAnnotationWithDollarSign("baz") - ) + JsonAnnotationWithDollarSign("baz"), + ), ).isEqualTo(expectedJson) } @@ -110,8 +110,8 @@ class GeneratedAdaptersTest { assertThat( adapter.toJson( - JsonAnnotationWithQuotationMark("baz") - ) + JsonAnnotationWithQuotationMark("baz"), + ), ).isEqualTo(expectedJson) } @@ -136,12 +136,13 @@ class GeneratedAdaptersTest { isEmpty() } - @Language("JSON") val expected = + @Language("JSON") + val expected = """{"foo":"fooString","bar":"","bazList":[]}""" assertThat( adapter.toJson( - DefaultValues("fooString") - ) + DefaultValues("fooString"), + ), ).isEqualTo(expected) // Read/write with real values @@ -164,7 +165,7 @@ class GeneratedAdaptersTest { val foo: String, val bar: String = "", val nullableBar: String? = null, - val bazList: List = emptyList() + val bazList: List = emptyList(), ) @Test @@ -206,6 +207,7 @@ class GeneratedAdaptersTest { @Language("JSON") val json = """{"foo":"foo","nullableString":null}""" + @Language("JSON") val invalidJson = """{"foo":null,"nullableString":null}""" @@ -225,7 +227,7 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) data class NullabeTypes( val foo: String, - val nullableString: String? + val nullableString: String?, ) @Test @@ -238,7 +240,7 @@ class GeneratedAdaptersTest { mutableMapOf(), emptyList(), emptySet(), - emptyMap() + emptyMap(), ) val json = adapter.toJson(specialCollections) @@ -253,7 +255,7 @@ class GeneratedAdaptersTest { val mutableMap: MutableMap, val immutableList: List, val immutableSet: Set, - val immutableMap: Map + val immutableMap: Map, ) @Test @@ -272,7 +274,7 @@ class GeneratedAdaptersTest { mutableListOf("immutableMutableList"), mutableListOf("immutableImmutableList"), mutableListOf("mutableMutableList"), - mutableListOf("mutableImmutableList") + mutableListOf("mutableImmutableList"), ) val json = adapter.toJson(mutableProperties) @@ -293,7 +295,7 @@ class GeneratedAdaptersTest { val nullableImmutableMutableList: MutableList?, val nullableImmutableImmutableList: List?, var nullableMutableMutableList: MutableList?, - var nullableMutableImmutableList: List + var nullableMutableImmutableList: List, ) @Test @@ -306,7 +308,7 @@ class GeneratedAdaptersTest { setOf("foo", null, "bar"), mapOf("foo" to "bar", "baz" to null), null, - 1 + 1, ) val noNullsTypeParams = NullableTypeParams( @@ -314,7 +316,7 @@ class GeneratedAdaptersTest { nullableTypeParams.nullableSet, nullableTypeParams.nullableMap.filterValues { it != null }, null, - 1 + 1, ) val json = adapter.toJson(nullableTypeParams) @@ -332,7 +334,7 @@ class GeneratedAdaptersTest { val nullableSet: Set, val nullableMap: Map, val nullableT: T?, - val nonNullT: T + val nonNullT: T, ) @Test fun doNotGenerateAdapter() { @@ -352,7 +354,7 @@ class GeneratedAdaptersTest { val encoded = ConstructorParameters( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":3,"b":5}""") @@ -389,7 +391,7 @@ class GeneratedAdaptersTest { val jsonAdapter = moshi.adapter() val encoded = ConstructorParametersAndProperties( - 3 + 3, ) encoded.b = 5 assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":3,"b":5}""") @@ -410,7 +412,7 @@ class GeneratedAdaptersTest { val encoded = ImmutableConstructorParameters( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":3,"b":5}""") @@ -446,7 +448,7 @@ class GeneratedAdaptersTest { val encoded = ConstructorDefaultValues( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":3,"b":5}""") @@ -498,7 +500,7 @@ class GeneratedAdaptersTest { val encoded = ConstructorParameterWithQualifier( "Android", - "Banana" + "Banana", ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":"ANDROID","b":"Banana"}""") @@ -544,7 +546,8 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) class PropertyWithQualifier { - @Uppercase(inFrench = true) var a: String = "" + @Uppercase(inFrench = true) + var a: String = "" var b: String = "" } @@ -554,7 +557,7 @@ class GeneratedAdaptersTest { val encoded = ConstructorParameterWithJsonName( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"key a":3,"b":5}""") @@ -582,7 +585,8 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) class PropertyWithJsonName { - @Json(name = "key a") var a: Int = -1 + @Json(name = "key a") + var a: Int = -1 var b: Int = -1 } @@ -592,7 +596,7 @@ class GeneratedAdaptersTest { val encoded = TransientConstructorParameter( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"b":5}""") @@ -639,6 +643,7 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) class TransientProperty { @Transient var a: Int = -1 + @Transient private var b: Int = -1 var c: Int = -1 @@ -670,11 +675,13 @@ class GeneratedAdaptersTest { private fun delegate(initial: T) = Delegates.observable(initial) { _, _, _ -> } @delegate:Transient var a: Int by delegate(-1) + @delegate:Transient private var b: Int by delegate(-1) var c: Int by delegate(-1) @JvmName("getBPublic") fun getB() = b + @JvmName("setBPublic") fun setB(b: Int) { this.b = b @@ -692,7 +699,7 @@ class GeneratedAdaptersTest { 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132 + 131, 132, ) val json = ( """ @@ -748,7 +755,7 @@ class GeneratedAdaptersTest { var v29: Int, var v30: Int, var v31: Int, - var v32: Int + var v32: Int, ) @Test fun manyProperties33() { @@ -762,7 +769,7 @@ class GeneratedAdaptersTest { 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132, 133 + 131, 132, 133, ) val json = ( """ @@ -820,7 +827,7 @@ class GeneratedAdaptersTest { var v30: Int, var v31: Int, var v32: Int, - var v33: Int + var v33: Int, ) @Test fun unsettablePropertyIgnored() { @@ -896,7 +903,7 @@ class GeneratedAdaptersTest { val encoded = SubtypeConstructorParameters( 3, - 5 + 5, ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":3,"b":5}""") @@ -934,7 +941,8 @@ class GeneratedAdaptersTest { } /** Generated adapters don't track enough state to detect duplicated values. */ - @Ignore @Test fun duplicatedValueParameter() { + @Ignore @Test + fun duplicatedValueParameter() { val moshi = Moshi.Builder().build() val jsonAdapter = moshi.adapter() @@ -949,7 +957,8 @@ class GeneratedAdaptersTest { class DuplicateValueParameter(var a: Int = -1, var b: Int = -2) /** Generated adapters don't track enough state to detect duplicated values. */ - @Ignore @Test fun duplicatedValueProperty() { + @Ignore @Test + fun duplicatedValueProperty() { val moshi = Moshi.Builder().build() val jsonAdapter = moshi.adapter() @@ -997,7 +1006,7 @@ class GeneratedAdaptersTest { val encoded = MultiplePropertiesShareAdapter( "Android", - "Banana" + "Banana", ) assertThat(jsonAdapter.toJson(encoded)).isEqualTo("""{"a":"ANDROID","b":"BANANA"}""") @@ -1011,7 +1020,7 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) class MultiplePropertiesShareAdapter( @Uppercase(true) var a: String, - @Uppercase(true) var b: String + @Uppercase(true) var b: String, ) @Test fun toJsonOnly() { @@ -1022,8 +1031,8 @@ class GeneratedAdaptersTest { assertThat( jsonAdapter.toJson( - CustomToJsonOnly(1, 2) - ) + CustomToJsonOnly(1, 2), + ), ).isEqualTo("""[1,2]""") val fromJson = jsonAdapter.fromJson("""{"a":3,"b":4}""")!! @@ -1048,8 +1057,8 @@ class GeneratedAdaptersTest { assertThat( jsonAdapter.toJson( - CustomFromJsonOnly(1, 2) - ) + CustomFromJsonOnly(1, 2), + ), ).isEqualTo("""{"a":1,"b":2}""") val fromJson = jsonAdapter.fromJson("""[3,4]""")!! @@ -1131,9 +1140,9 @@ class GeneratedAdaptersTest { assertThat( jsonAdapter.toJson( HasParameterizedProperty( - Twins("1", "2") - ) - ) + Twins("1", "2"), + ), + ), ) .isEqualTo("""{"twins":{"a":"1","b":"2"}}""") @@ -1157,8 +1166,8 @@ class GeneratedAdaptersTest { assertThat( adapter.toJson( - UppercasePropertyName(3, 4) - ) + UppercasePropertyName(3, 4), + ), ).isEqualTo("""{"AAA":3,"BBB":4}""") } @@ -1193,6 +1202,7 @@ class GeneratedAdaptersTest { fun toJson(@Uppercase(inFrench = true) s: String): String { return s.uppercase(Locale.US) } + @FromJson @Uppercase(inFrench = true) fun fromJson(s: String): String { @@ -1223,7 +1233,7 @@ class GeneratedAdaptersTest { } } null - } + }, ) .build() val adapter = moshi.adapter().serializeNulls() @@ -1231,8 +1241,8 @@ class GeneratedAdaptersTest { .isEqualTo(HasNullableBoolean(null)) assertThat( adapter.toJson( - HasNullableBoolean(null) - ) + HasNullableBoolean(null), + ), ).isEqualTo("""{"boolean":null}""") } @@ -1251,15 +1261,15 @@ class GeneratedAdaptersTest { val adapter = moshi.adapter() val encoded = HasCollectionOfPrimitives( - listOf(1, 2, -3) + listOf(1, 2, -3), ) assertThat(adapter.toJson(encoded)).isEqualTo("""{"listOfInts":[1,2,-3]}""") val decoded = adapter.fromJson("""{"listOfInts":[4,-5,6]}""")!! assertThat(decoded).isEqualTo( HasCollectionOfPrimitives( - listOf(4, -5, 6) - ) + listOf(4, -5, 6), + ), ) } @@ -1271,7 +1281,7 @@ class GeneratedAdaptersTest { val adapter = moshi.adapter() val unwrapped = (adapter as NullSafeJsonAdapter).delegate assertThat(unwrapped).isInstanceOf( - GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter::class.java + GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter::class.java, ) } @@ -1313,9 +1323,10 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) data class ClassWithFieldJson( - @field:Json(name = "_links") val links: String + @field:Json(name = "_links") val links: String, ) { - @field:Json(name = "_ids") var ids: String? = null + @field:Json(name = "_ids") + var ids: String? = null } // Regression test to ensure annotations with field site targets still use the right name @@ -1357,7 +1368,7 @@ class GeneratedAdaptersTest { try { GeneratedAdaptersTest_MultipleGenericsJsonAdapter( moshi, - arrayOf(String::class.java) + arrayOf(String::class.java), ) fail("Should have failed to construct the adapter due to wrong number of generics") } catch (e: IllegalArgumentException) { @@ -1396,5 +1407,5 @@ data class NullableTypeParams( val nullableSet: Set, val nullableMap: Map, val nullableT: T?, - val nonNullT: T + val nonNullT: T, ) diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/LooksLikeAClass/ClassInPackageThatLooksLikeAClass.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/LooksLikeAClass/ClassInPackageThatLooksLikeAClass.kt index 2436102..f79a0c6 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/LooksLikeAClass/ClassInPackageThatLooksLikeAClass.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/LooksLikeAClass/ClassInPackageThatLooksLikeAClass.kt @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:Suppress("PackageName") + package com.squareup.moshi.kotlin.codegen.LooksLikeAClass import com.squareup.moshi.JsonClass diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MixingReflectAndCodeGen.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MixingReflectAndCodeGen.kt index 61248c3..5175d44 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MixingReflectAndCodeGen.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MixingReflectAndCodeGen.kt @@ -35,7 +35,7 @@ class MixingReflectAndCodeGen { assertThat(reflectionAdapter.toString()) .isEqualTo( "KotlinJsonAdapter(com.squareup.moshi.kotlin.codegen.MixingReflectAndCodeGen" + - ".UsesReflectionAdapter).nullSafe()" + ".UsesReflectionAdapter).nullSafe()", ) } diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt index e1a4268..8731fe1 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt @@ -35,7 +35,6 @@ import org.junit.Test */ class MultipleMasksTest { @Test fun testMultipleMasks() { - // Set some arbitrary values to make sure offsets are aligning correctly @Language("JSON") val json = @@ -121,5 +120,5 @@ class MultipleMasks( val arg62: Long = 62, val arg63: Long = 63, val arg64: Long = 64, - val arg65: Long = 65 + val arg65: Long = 65, ) diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/annotation/UppercaseInAnnotationPackage.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/annotation/UppercaseInAnnotationPackage.kt index 17f9934..1212287 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/annotation/UppercaseInAnnotationPackage.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/annotation/UppercaseInAnnotationPackage.kt @@ -28,6 +28,7 @@ class UppercaseInAnnotationPackageJsonAdapter { fun toJson(@UppercaseInAnnotationPackage s: String): String { return s.uppercase(Locale.US) } + @FromJson @UppercaseInAnnotationPackage fun fromJson(s: String): String { diff --git a/moshi-kotlin-tests/extra-moshi-test-module/src/main/kotlin/com/squareup/moshi/kotlin/codegen/test/extra/AbstractClassInModuleA.kt b/moshi-kotlin-tests/extra-moshi-test-module/src/main/kotlin/com/squareup/moshi/kotlin/codegen/test/extra/AbstractClassInModuleA.kt index 89e6657..e2ee1bd 100644 --- a/moshi-kotlin-tests/extra-moshi-test-module/src/main/kotlin/com/squareup/moshi/kotlin/codegen/test/extra/AbstractClassInModuleA.kt +++ b/moshi-kotlin-tests/extra-moshi-test-module/src/main/kotlin/com/squareup/moshi/kotlin/codegen/test/extra/AbstractClassInModuleA.kt @@ -20,9 +20,14 @@ import com.squareup.moshi.Json public abstract class AbstractClassInModuleA { // Ignored/transient to ensure processor sees them across module boundaries. @Transient private lateinit var lateinitTransient: String + @Transient private var regularTransient: String = "regularTransient" + // Note that we target the field because otherwise it is stored on the synthetic holder method for // annotations, which isn't visible from kapt - @field:Json(ignore = true) private lateinit var lateinitIgnored: String - @field:Json(ignore = true) private var regularIgnored: String = "regularIgnored" + @field:Json(ignore = true) + private lateinit var lateinitIgnored: String + + @field:Json(ignore = true) + private var regularIgnored: String = "regularIgnored" } diff --git a/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt b/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt index f3ca5af..38ce548 100644 --- a/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt +++ b/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt @@ -87,7 +87,7 @@ class DualKotlinTest { @Suppress("UNUSED_PARAMETER") @FromJson fun fromJson(string: String): String? = null - } + }, ) .build() .adapter() @@ -125,7 +125,7 @@ class DualKotlinTest { @Suppress("UNUSED_PARAMETER") @FromJson fun fromJson(string: String): String? = null - } + }, ) .build() .adapter() @@ -141,7 +141,8 @@ class DualKotlinTest { @JsonClass(generateAdapter = true) class HasNonNullPropertyDifferentJsonName { - @Json(name = "aPrime") var a: String = "" + @Json(name = "aPrime") + var a: String = "" } @Test fun nonNullConstructorParameterCalledWithNullFailsWithJsonDataException() { @@ -163,7 +164,7 @@ class DualKotlinTest { @Suppress("UNUSED_PARAMETER") @FromJson fun fromJson(string: String): String? = null - } + }, ) .build() .adapter() @@ -199,7 +200,7 @@ class DualKotlinTest { fun toJson(@Nullable value: String?): String { return value ?: "fallback" } - } + }, ) .build() @@ -208,7 +209,7 @@ class DualKotlinTest { assertThat( //language=JSON hasNonNullConstructorParameterAdapter - .fromJson("{\"a\":null}") + .fromJson("{\"a\":null}"), ).isEqualTo(HasNonNullConstructorParameter("fallback")) val hasNullableConstructorParameterAdapter = @@ -216,12 +217,12 @@ class DualKotlinTest { assertThat( //language=JSON hasNullableConstructorParameterAdapter - .fromJson("{\"a\":null}") + .fromJson("{\"a\":null}"), ).isEqualTo(HasNullableConstructorParameter("fallback")) //language=JSON assertThat( hasNullableConstructorParameterAdapter - .toJson(HasNullableConstructorParameter(null)) + .toJson(HasNullableConstructorParameter(null)), ).isEqualTo("{\"a\":\"fallback\"}") } @@ -329,7 +330,7 @@ class DualKotlinTest { .isEqualTo( """ {"text":"root","r":{"number":0,"r":{"text":"grand child 1"},"t":{"number":1}},"t":{"text":"child 1"}} - """.trimIndent() + """.trimIndent(), ) } @@ -418,7 +419,7 @@ class DualKotlinTest { class MultipleNonPropertyParameters( val prop: Int, param1: Int = 1, - param2: Int = 2 + param2: Int = 2, ) { init { // Ensure the params always uses their default value @@ -445,7 +446,7 @@ class DualKotlinTest { @JsonClass(generateAdapter = true) class OnlyMultipleNonPropertyParameters( param1: Int = 1, - param2: Int = 2 + param2: Int = 2, ) { init { // Ensure the params always uses their default value @@ -472,7 +473,7 @@ class DualKotlinTest { parameterized = GenericClass(6), wildcardIn = GenericClass(6), wildcardOut = GenericClass(6), - complex = GenericClass(listOf(GenericClass(6))) + complex = GenericClass(listOf(GenericClass(6))), ) assertThat(adapter.toJson(testValue)).isEqualTo(testJson) @@ -486,7 +487,7 @@ class DualKotlinTest { val parameterized: GenericClass, val wildcardIn: GenericClass, val wildcardOut: GenericClass, - val complex: GenericClass? + val complex: GenericClass?, ) // Regression test for https://github.com/square/moshi/issues/991 @@ -506,7 +507,7 @@ class DualKotlinTest { int = 3, long = 3, float = 3.2f, - double = 3.2 + double = 3.2, ) assertThat(adapter.toJson(instance)) .isEqualTo(testJson) @@ -533,7 +534,7 @@ class DualKotlinTest { val float: Float, val nullableFloat: Float? = null, val double: Double, - val nullableDouble: Double? = null + val nullableDouble: Double? = null, ) // Regression test for https://github.com/square/moshi/issues/990 @@ -577,7 +578,7 @@ class DualKotlinTest { val redundantNullableAShouldBeNullable: NullableA?, val manuallyNullableAShouldBeNullable: A?, val convolutedMultiNullableShouldBeNullable: NullableB?, - val deepNestedNullableShouldBeNullable: E + val deepNestedNullableShouldBeNullable: E, ) // Regression test for https://github.com/square/moshi/issues/1009 @@ -617,12 +618,12 @@ class DualKotlinTest { interface IntersectionTypeInterface> enum class IntersectionTypesEnum : IntersectionTypeInterface { - VALUE + VALUE, } @JsonClass(generateAdapter = true) data class IntersectionTypes( - val value: E + val value: E, ) where E : Enum, E : IntersectionTypeInterface @Test fun transientConstructorParameter() { @@ -672,6 +673,7 @@ class DualKotlinTest { class TransientProperty { @Transient var a: Int = -1 + @Transient private var b: Int = -1 var c: Int = -1 @@ -712,7 +714,7 @@ class DualKotlinTest { class MultipleIgnoredConstructorParameters( @Json(ignore = true) var a: Int = -1, var b: Int = -1, - @Json(ignore = true) var c: Int = -1 + @Json(ignore = true) var c: Int = -1, ) @Test fun ignoredProperty() { @@ -732,8 +734,11 @@ class DualKotlinTest { } class IgnoredProperty { - @Json(ignore = true) var a: Int = -1 - @Json(ignore = true) private var b: Int = -1 + @Json(ignore = true) + var a: Int = -1 + + @Json(ignore = true) + private var b: Int = -1 var c: Int = -1 fun getB() = b @@ -756,11 +761,12 @@ class DualKotlinTest { @JsonClass(generateAdapter = true) data class PropertyWithDollarSign( val `$a`: String, - @Json(name = "\$b") val b: String + @Json(name = "\$b") val b: String, ) } typealias TypeAlias = Int + @Suppress("REDUNDANT_PROJECTION") typealias GenericTypeAlias = List?>? diff --git a/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt b/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt index 8f84bcd..69ec80d 100644 --- a/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt +++ b/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt @@ -276,7 +276,8 @@ class KotlinJsonAdapterTest { } class PropertyWithJsonName { - @Json(name = "key a") var a: Int = -1 + @Json(name = "key a") + var a: Int = -1 var b: Int = -1 } @@ -289,7 +290,7 @@ class KotlinJsonAdapterTest { assertThat(expected).hasMessageThat().isEqualTo( "No default value for transient constructor parameter #0 " + "a of fun ``(kotlin.Int): " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.RequiredTransientConstructorParameter" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.RequiredTransientConstructorParameter", ) } } @@ -305,7 +306,7 @@ class KotlinJsonAdapterTest { assertThat(expected).hasMessageThat().isEqualTo( "No default value for ignored constructor parameter #0 " + "a of fun ``(kotlin.Int): " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.RequiredIgnoredConstructorParameter" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.RequiredIgnoredConstructorParameter", ) } } @@ -320,7 +321,7 @@ class KotlinJsonAdapterTest { } catch (expected: IllegalArgumentException) { assertThat(expected).hasMessageThat().isEqualTo( "'a' has a constructor parameter of type " + - "kotlin.Int but a property of type kotlin.String." + "kotlin.Int but a property of type kotlin.String.", ) } } @@ -406,7 +407,7 @@ class KotlinJsonAdapterTest { fail() } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( - "Platform class kotlin.Triple in kotlin.Triple requires explicit JsonAdapter to be registered" + "Platform class kotlin.Triple in kotlin.Triple requires explicit JsonAdapter to be registered", ) } } @@ -551,7 +552,7 @@ class KotlinJsonAdapterTest { } catch (expected: IllegalArgumentException) { assertThat(expected).hasMessageThat().isEqualTo( "No property for required constructor parameter #0 a of fun ``(" + - "kotlin.Int, kotlin.Int): ${NonPropertyConstructorParameter::class.qualifiedName}" + "kotlin.Int, kotlin.Int): ${NonPropertyConstructorParameter::class.qualifiedName}", ) } } @@ -579,7 +580,7 @@ class KotlinJsonAdapterTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( "No JsonAdapter for interface " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$Interface (with no annotations)" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$Interface (with no annotations)", ) } } @@ -594,7 +595,7 @@ class KotlinJsonAdapterTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( "Cannot serialize abstract class " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$AbstractClass" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$AbstractClass", ) } } @@ -609,7 +610,7 @@ class KotlinJsonAdapterTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( "Cannot serialize inner class " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$InnerClass" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$InnerClass", ) } } @@ -625,7 +626,7 @@ class KotlinJsonAdapterTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( "Cannot serialize local class or object expression " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$localClassesNotSupported\$LocalClass" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$localClassesNotSupported\$LocalClass", ) } } @@ -638,7 +639,7 @@ class KotlinJsonAdapterTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessageThat().isEqualTo( "Cannot serialize object declaration " + - "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$ObjectDeclaration" + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$ObjectDeclaration", ) } } @@ -666,7 +667,7 @@ class KotlinJsonAdapterTest { assertThat(e).hasMessageThat().isEqualTo( "Cannot serialize $type " + "com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest\$anonymousClassesNotSupported" + - "\$expression$1" + "\$expression$1", ) } } @@ -682,7 +683,7 @@ class KotlinJsonAdapterTest { 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132 + 131, 132, ) val json = ( """ @@ -737,7 +738,7 @@ class KotlinJsonAdapterTest { var v29: Int, var v30: Int, var v31: Int, - var v32: Int + var v32: Int, ) @Test fun manyProperties33() { @@ -751,7 +752,7 @@ class KotlinJsonAdapterTest { 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132, 133 + 131, 132, 133, ) val json = ( """ @@ -808,7 +809,7 @@ class KotlinJsonAdapterTest { var v30: Int, var v31: Int, var v32: Int, - var v33: Int + var v33: Int, ) data class Box(val data: T) @@ -856,6 +857,7 @@ class KotlinJsonAdapterTest { fun toJson(@Uppercase s: String): String { return s.uppercase(Locale.US) } + @FromJson @Uppercase fun fromJson(s: String): String { @@ -885,7 +887,7 @@ class KotlinJsonAdapterTest { } } null - } + }, ) .add(KotlinJsonAdapterFactory()) .build() @@ -922,7 +924,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToStandardReflection::class.java, """{"map":{"key":"value"}}""", - MapOfStringToStandardReflection(mapOf("key" to "value")) + MapOfStringToStandardReflection(mapOf("key" to "value")), ) } @@ -933,7 +935,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToStandardCodegen::class.java, """{"map":{"key":"value"}}""", - MapOfStringToStandardCodegen(mapOf("key" to "value")) + MapOfStringToStandardCodegen(mapOf("key" to "value")), ) } @@ -945,7 +947,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToEnumReflection::class.java, """{"map":{"key":"A"}}""", - MapOfStringToEnumReflection(mapOf("key" to KotlinEnum.A)) + MapOfStringToEnumReflection(mapOf("key" to KotlinEnum.A)), ) } @@ -956,7 +958,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToEnumCodegen::class.java, """{"map":{"key":"A"}}""", - MapOfStringToEnumCodegen(mapOf("key" to KotlinEnum.A)) + MapOfStringToEnumCodegen(mapOf("key" to KotlinEnum.A)), ) } @@ -968,7 +970,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToCollectionReflection::class.java, """{"map":{"key":[]}}""", - MapOfStringToCollectionReflection(mapOf("key" to listOf())) + MapOfStringToCollectionReflection(mapOf("key" to listOf())), ) } @@ -979,7 +981,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToCollectionCodegen::class.java, """{"map":{"key":[]}}""", - MapOfStringToCollectionCodegen(mapOf("key" to listOf())) + MapOfStringToCollectionCodegen(mapOf("key" to listOf())), ) } @@ -991,7 +993,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToMapReflection::class.java, """{"map":{"key":{}}}""", - MapOfStringToMapReflection(mapOf("key" to mapOf())) + MapOfStringToMapReflection(mapOf("key" to mapOf())), ) } @@ -1002,7 +1004,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToMapCodegen::class.java, """{"map":{"key":{}}}""", - MapOfStringToMapCodegen(mapOf("key" to mapOf())) + MapOfStringToMapCodegen(mapOf("key" to mapOf())), ) } @@ -1014,7 +1016,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToArrayReflection::class.java, """{"map":{"key":[]}}""", - MapOfStringToArrayReflection(mapOf("key" to arrayOf())) + MapOfStringToArrayReflection(mapOf("key" to arrayOf())), ) } @@ -1025,7 +1027,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToArrayCodegen::class.java, """{"map":{"key":[]}}""", - MapOfStringToArrayCodegen(mapOf("key" to arrayOf())) + MapOfStringToArrayCodegen(mapOf("key" to arrayOf())), ) } @@ -1037,7 +1039,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToClassReflection::class.java, """{"map":{"key":{"a":19,"b":42}}}""", - MapOfStringToClassReflection(mapOf("key" to ConstructorParameters(19, 42))) + MapOfStringToClassReflection(mapOf("key" to ConstructorParameters(19, 42))), ) } @@ -1048,7 +1050,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToClassCodegen::class.java, """{"map":{"key":{"a":19,"b":42}}}""", - MapOfStringToClassCodegen(mapOf("key" to ConstructorParameters(19, 42))) + MapOfStringToClassCodegen(mapOf("key" to ConstructorParameters(19, 42))), ) } diff --git a/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt b/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt index 03dbd5a..2b64407 100644 --- a/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt +++ b/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt @@ -19,7 +19,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory @Deprecated( message = "this moved to avoid a package name conflict in the Java Platform Module System.", - replaceWith = ReplaceWith("com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory") + replaceWith = ReplaceWith("com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory"), ) public class KotlinJsonAdapterFactory : JsonAdapter.Factory by KotlinJsonAdapterFactory() diff --git a/moshi-kotlin/src/main/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterFactory.kt b/moshi-kotlin/src/main/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterFactory.kt index d21f2d9..02555d7 100644 --- a/moshi-kotlin/src/main/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterFactory.kt +++ b/moshi-kotlin/src/main/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterFactory.kt @@ -61,7 +61,7 @@ internal class KotlinJsonAdapter( val constructor: KFunction, val allBindings: List?>, val nonIgnoredBindings: List>, - val options: JsonReader.Options + val options: JsonReader.Options, ) : JsonAdapter() { override fun fromJson(reader: JsonReader): T { @@ -82,7 +82,7 @@ internal class KotlinJsonAdapter( val propertyIndex = binding.propertyIndex if (values[propertyIndex] !== ABSENT_VALUE) { throw JsonDataException( - "Multiple values for '${binding.property.name}' at ${reader.path}" + "Multiple values for '${binding.property.name}' at ${reader.path}", ) } @@ -92,7 +92,7 @@ internal class KotlinJsonAdapter( throw unexpectedNull( binding.property.name, binding.jsonName, - reader + reader, ) } } @@ -108,7 +108,7 @@ internal class KotlinJsonAdapter( else -> throw missingProperty( constructor.parameters[i].name, allBindings[i]?.jsonName, - reader + reader, ) } } @@ -151,7 +151,7 @@ internal class KotlinJsonAdapter( val adapter: JsonAdapter

, val property: KProperty1, val parameter: KParameter?, - val propertyIndex: Int + val propertyIndex: Int, ) { fun get(value: K) = property.get(value) @@ -165,7 +165,7 @@ internal class KotlinJsonAdapter( /** A simple [Map] that uses parameter indexes instead of sorting or hashing. */ class IndexedParameterMap( private val parameterKeys: List, - private val parameterValues: Array + private val parameterValues: Array, ) : AbstractMutableMap() { override fun put(key: KParameter, value: Any?): Any? = null @@ -278,7 +278,7 @@ public class KotlinJsonAdapterFactory : JsonAdapter.Factory { } else { Types.newParameterizedType( rawClassifierType, - *property.returnType.arguments.mapNotNull { it.type?.javaType }.toTypedArray() + *property.returnType.arguments.mapNotNull { it.type?.javaType }.toTypedArray(), ) } } else { @@ -295,7 +295,7 @@ public class KotlinJsonAdapterFactory : JsonAdapter.Factory { val adapter = moshi.adapter( resolvedPropertyType, allAnnotations.toTypedArray().jsonAnnotations, - property.name + property.name, ) @Suppress("UNCHECKED_CAST") @@ -304,7 +304,7 @@ public class KotlinJsonAdapterFactory : JsonAdapter.Factory { adapter, property as KProperty1, parameter, - parameter?.index ?: -1 + parameter?.index ?: -1, ) } diff --git a/moshi-kotlin/src/test/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt b/moshi-kotlin/src/test/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt index 372c018..ef63b9e 100644 --- a/moshi-kotlin/src/test/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt +++ b/moshi-kotlin/src/test/java/com/squareup/moshi/kotlin/reflect/KotlinJsonAdapterTest.kt @@ -31,7 +31,7 @@ class KotlinJsonAdapterTest { .build() val adapter = moshi.adapter(Data::class.java) assertThat(adapter.toString()).isEqualTo( - "KotlinJsonAdapter(com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.Data).nullSafe()" + "KotlinJsonAdapter(com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterTest.Data).nullSafe()", ) } } diff --git a/moshi/build.gradle.kts b/moshi/build.gradle.kts index f7d3d5c..c1d222f 100644 --- a/moshi/build.gradle.kts +++ b/moshi/build.gradle.kts @@ -62,7 +62,7 @@ tasks.withType() kotlinOptions { val toAdd = mutableListOf( "-opt-in=kotlin.contracts.ExperimentalContracts", - "-Xjvm-default=all" + "-Xjvm-default=all", ) if (name.contains("test", true)) { toAdd += "-opt-in=kotlin.ExperimentalStdlibApi" diff --git a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.kt b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.kt index 68467ce..3eabb61 100644 --- a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.kt +++ b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.kt @@ -29,12 +29,12 @@ import java.lang.reflect.Type internal class AdapterMethodsFactory( private val toAdapters: List, - private val fromAdapters: List + private val fromAdapters: List, ) : JsonAdapter.Factory { override fun create( type: Type, annotations: Set, - moshi: Moshi + moshi: Moshi, ): JsonAdapter<*>? { val toAdapter = get(toAdapters, type, annotations) val fromAdapter = get(fromAdapters, type, annotations) @@ -47,7 +47,7 @@ internal class AdapterMethodsFactory( val missingAnnotation = if (toAdapter == null) "@ToJson" else "@FromJson" throw IllegalArgumentException( "No $missingAnnotation adapter for ${type.toStringWithAnnotations(annotations)}", - e + e, ) } } else { @@ -154,7 +154,7 @@ internal class AdapterMethodsFactory( annotations = qualifierAnnotations, adapter = adapter, method = method, - nullable = true + nullable = true, ) { override fun toJson(moshi: Moshi, writer: JsonWriter, value: Any?) { invokeMethod(writer, value) @@ -173,7 +173,7 @@ internal class AdapterMethodsFactory( annotations = qualifierAnnotations, adapter = adapter, method = method, - nullable = nullable + nullable = nullable, ) { private lateinit var delegate: JsonAdapter @@ -203,7 +203,7 @@ internal class AdapterMethodsFactory( void toJson(JsonWriter writer, T value, JsonAdapter delegate, ) throws ; R toJson(T value) throws ; - """.trimIndent() + """.trimIndent(), ) } } @@ -244,7 +244,7 @@ internal class AdapterMethodsFactory( annotations = returnTypeAnnotations, adapter = adapter, method = method, - nullable = true + nullable = true, ) { override fun fromJson(moshi: Moshi, reader: JsonReader) = invokeMethod(reader) } @@ -260,7 +260,7 @@ internal class AdapterMethodsFactory( annotations = returnTypeAnnotations, adapter = adapter, method = method, - nullable = nullable + nullable = nullable, ) { lateinit var delegate: JsonAdapter @@ -288,7 +288,7 @@ internal class AdapterMethodsFactory( R fromJson(JsonReader jsonReader, JsonAdapter delegate, ) throws ; R fromJson(T value) throws ; - """.trimIndent() + """.trimIndent(), ) } } @@ -298,7 +298,7 @@ internal class AdapterMethodsFactory( private fun get( adapterMethods: List, type: Type, - annotations: Set + annotations: Set, ): AdapterMethod? { for (adapterMethod in adapterMethods) { if (Types.equals(adapterMethod.type, type) && adapterMethod.annotations == annotations) { @@ -316,7 +316,7 @@ internal class AdapterMethodsFactory( val annotations: Set, val adapter: Any, val method: Method, - val nullable: Boolean + val nullable: Boolean, ) { val type = type.canonicalize() private val jsonAdapters: Array?> = arrayOfNulls(parameterCount - adaptersOffset) diff --git a/moshi/src/main/java/com/squareup/moshi/ArrayJsonAdapter.kt b/moshi/src/main/java/com/squareup/moshi/ArrayJsonAdapter.kt index a564894..77a03db 100644 --- a/moshi/src/main/java/com/squareup/moshi/ArrayJsonAdapter.kt +++ b/moshi/src/main/java/com/squareup/moshi/ArrayJsonAdapter.kt @@ -24,7 +24,7 @@ import java.lang.reflect.Array as JavaArray */ internal class ArrayJsonAdapter( private val elementClass: Class<*>, - private val elementAdapter: JsonAdapter + private val elementAdapter: JsonAdapter, ) : JsonAdapter() { override fun fromJson(reader: JsonReader): Any { val list = buildList { diff --git a/moshi/src/main/java/com/squareup/moshi/ClassFactory.kt b/moshi/src/main/java/com/squareup/moshi/ClassFactory.kt index 04b8d02..97d3472 100644 --- a/moshi/src/main/java/com/squareup/moshi/ClassFactory.kt +++ b/moshi/src/main/java/com/squareup/moshi/ClassFactory.kt @@ -87,7 +87,7 @@ internal abstract class ClassFactory { val newInstance = ObjectStreamClass::class.java.getDeclaredMethod( "newInstance", Class::class.java, - Int::class.javaPrimitiveType + Int::class.javaPrimitiveType, ) newInstance.isAccessible = true return object : ClassFactory() { diff --git a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.kt b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.kt index f625536..3ba9b4f 100644 --- a/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.kt +++ b/moshi/src/main/java/com/squareup/moshi/ClassJsonAdapter.kt @@ -49,7 +49,7 @@ import java.lang.reflect.Type */ internal class ClassJsonAdapter( private val classFactory: ClassFactory, - fieldsMap: Map> + fieldsMap: Map>, ) : JsonAdapter() { private val fieldsArray = fieldsMap.values.toTypedArray() private val options = JsonReader.Options.of(*fieldsMap.keys.toTypedArray()) @@ -115,7 +115,7 @@ internal class ClassJsonAdapter( override fun create( type: Type, annotations: Set, - moshi: Moshi + moshi: Moshi, ): JsonAdapter<*>? { if (type !is Class<*> && type !is ParameterizedType) { return null @@ -136,7 +136,7 @@ internal class ClassJsonAdapter( } } throw IllegalArgumentException( - "$messagePrefix requires explicit JsonAdapter to be registered" + "$messagePrefix requires explicit JsonAdapter to be registered", ) } @@ -185,7 +185,7 @@ internal class ClassJsonAdapter( private fun createFieldBindings( moshi: Moshi, type: Type, - fieldBindings: MutableMap> + fieldBindings: MutableMap>, ) { val rawType = type.rawType val platformType = rawType.isPlatformType @@ -201,7 +201,7 @@ internal class ClassJsonAdapter( val adapter = moshi.adapter( type = fieldType, annotations = annotations, - fieldName = fieldName + fieldName = fieldName, ) // Create the binding between field and JSON. diff --git a/moshi/src/main/java/com/squareup/moshi/CollectionJsonAdapter.kt b/moshi/src/main/java/com/squareup/moshi/CollectionJsonAdapter.kt index 62f956f..da7d1f4 100644 --- a/moshi/src/main/java/com/squareup/moshi/CollectionJsonAdapter.kt +++ b/moshi/src/main/java/com/squareup/moshi/CollectionJsonAdapter.kt @@ -20,7 +20,7 @@ import java.lang.reflect.Type /** Converts collection types to JSON arrays containing their converted contents. */ internal abstract class CollectionJsonAdapter, T> private constructor( - private val elementAdapter: JsonAdapter + private val elementAdapter: JsonAdapter, ) : JsonAdapter() { abstract fun newCollection(): C diff --git a/moshi/src/main/java/com/squareup/moshi/Json.kt b/moshi/src/main/java/com/squareup/moshi/Json.kt index 5f5d97c..2c5f8ac 100644 --- a/moshi/src/main/java/com/squareup/moshi/Json.kt +++ b/moshi/src/main/java/com/squareup/moshi/Json.kt @@ -39,7 +39,7 @@ public annotation class Json( * * **Note:** this has no effect in `enum` or `record` classes. */ - val ignore: Boolean = false + val ignore: Boolean = false, ) { public companion object { /** The default value of [name]. Should only be used to check if it's been set. */ diff --git a/moshi/src/main/java/com/squareup/moshi/JsonClass.kt b/moshi/src/main/java/com/squareup/moshi/JsonClass.kt index 5823064..da4316f 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonClass.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonClass.kt @@ -63,5 +63,5 @@ public annotation class JsonClass( * generator to create the API signature to get started, then make your own generator match that * expected signature. */ - val generator: String = "" + val generator: String = "", ) diff --git a/moshi/src/main/java/com/squareup/moshi/JsonReader.kt b/moshi/src/main/java/com/squareup/moshi/JsonReader.kt index d07dd3b..8b6440b 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonReader.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonReader.kt @@ -230,7 +230,6 @@ public sealed class JsonReader : Closeable { * useful in development and debugging because it means a typo like "locatiom" will be detected * early. It's potentially harmful in production because it complicates revising a JSON schema. */ - /** Returns true if this parser forbids skipping names and values. */ @get:JvmName("failOnUnknown") public var failOnUnknown: Boolean = false @@ -578,7 +577,7 @@ public sealed class JsonReader : Closeable { */ public class Options private constructor( internal val strings: Array, - internal val doubleQuoteSuffix: OkioOptions + internal val doubleQuoteSuffix: OkioOptions, ) { /** Returns a copy of this [Option's][Options] strings. */ public fun strings(): List { @@ -657,7 +656,7 @@ public sealed class JsonReader : Closeable { * The end of the JSON stream. This sentinel value is returned by [JsonReader.peek] to * signal that the JSON-encoded value has no more tokens. */ - END_DOCUMENT + END_DOCUMENT, } public companion object { diff --git a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Reader.kt b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Reader.kt index 5e73f91..75ec851 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Reader.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Reader.kt @@ -530,7 +530,9 @@ internal class JsonUtf8Reader : JsonReader { peeked = PEEKED_NONE pathNames[stackSize - 1] = name i - } else -1 + } else { + -1 + } } override fun nextString(): String { @@ -586,7 +588,9 @@ internal class JsonUtf8Reader : JsonReader { peeked = PEEKED_NONE pathIndices[stackSize - 1]++ i - } else -1 + } else { + -1 + } } override fun nextBoolean(): Boolean { diff --git a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt index 5ffccd4..9955e39 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt @@ -37,7 +37,7 @@ import kotlin.require internal class JsonUtf8Writer( /** The output data, containing at most one top-level array or object. */ - private val sink: BufferedSink + private val sink: BufferedSink, ) : JsonWriter() { /** The name/value separator; either ":" or ": ". */ diff --git a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt index b732b18..8a7e405 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt @@ -381,7 +381,7 @@ internal class JsonValueReader : JsonReader { internal class JsonIterator( val endToken: Token, val array: Array, - var next: Int + var next: Int, ) : Iterator, Cloneable { override fun hasNext() = next < array.size diff --git a/moshi/src/main/java/com/squareup/moshi/JsonValueSource.kt b/moshi/src/main/java/com/squareup/moshi/JsonValueSource.kt index 3dde36e..1ef57f8 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonValueSource.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonValueSource.kt @@ -47,7 +47,7 @@ internal class JsonValueSource @JvmOverloads constructor( * reached, this should be compared against 0. If it is zero, then we've read a complete value and * this source is exhausted. */ - private var stackSize: Int = 0 + private var stackSize: Int = 0, ) : Source { private val buffer: Buffer = source.buffer diff --git a/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt b/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt index a94050e..4d05b82 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt @@ -158,6 +158,7 @@ public sealed class JsonWriter : Closeable, Flushable { * the encoded document will be compact. */ get() = _indent.orEmpty() + /** * Sets the indentation string to be repeated for each level of indentation in the encoded * document. If `indent.isEmpty()` the encoded document will be compact. Otherwise, the diff --git a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt index ac9c984..869dda3 100644 --- a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt +++ b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt @@ -22,7 +22,7 @@ internal class LinkedHashTreeMap * @param comparator the comparator to order elements with, or null to use the natural ordering. */ constructor( - comparator: Comparator? = null + comparator: Comparator? = null, ) : AbstractMutableMap(), Serializable { @Suppress("UNCHECKED_CAST") private val comparator: Comparator = (comparator ?: NATURAL_ORDER) as Comparator @@ -83,6 +83,7 @@ constructor( @JvmField var next: Node? + @JvmField var prev: Node? diff --git a/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.kt b/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.kt index 4c03f93..48ac5c0 100644 --- a/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.kt +++ b/moshi/src/main/java/com/squareup/moshi/MapJsonAdapter.kt @@ -51,7 +51,7 @@ internal class MapJsonAdapter(moshi: Moshi, keyType: Type, valueType: Type val replaced = result.put(name, value) if (replaced != null) { throw JsonDataException( - "Map key '$name' has multiple values at path ${reader.path}: $replaced and $value" + "Map key '$name' has multiple values at path ${reader.path}: $replaced and $value", ) } } diff --git a/moshi/src/main/java/com/squareup/moshi/Moshi.kt b/moshi/src/main/java/com/squareup/moshi/Moshi.kt index 393deed..d36856b 100644 --- a/moshi/src/main/java/com/squareup/moshi/Moshi.kt +++ b/moshi/src/main/java/com/squareup/moshi/Moshi.kt @@ -107,7 +107,7 @@ public class Moshi internal constructor(builder: Builder) { public fun adapter( type: Type, annotations: Set, - fieldName: String? + fieldName: String?, ): JsonAdapter { val cleanedType = type.canonicalize().removeSubtypeWildcard() @@ -150,7 +150,7 @@ public class Moshi internal constructor(builder: Builder) { public fun nextAdapter( skipPast: JsonAdapter.Factory, type: Type, - annotations: Set + annotations: Set, ): JsonAdapter { val cleanedType = type.canonicalize().removeSubtypeWildcard() val skipPastIndex = factories.indexOf(skipPast) @@ -203,7 +203,7 @@ public class Moshi internal constructor(builder: Builder) { public fun add( type: Type, annotation: Class, - jsonAdapter: JsonAdapter + jsonAdapter: JsonAdapter, ): Builder = apply { add(newAdapterFactory(type, annotation, jsonAdapter)) } @@ -225,7 +225,7 @@ public class Moshi internal constructor(builder: Builder) { public fun addLast( type: Type, annotation: Class, - jsonAdapter: JsonAdapter + jsonAdapter: JsonAdapter, ): Builder = apply { addLast(newAdapterFactory(type, annotation, jsonAdapter)) } @@ -373,7 +373,7 @@ public class Moshi internal constructor(builder: Builder) { fun newAdapterFactory( type: Type, - jsonAdapter: JsonAdapter + jsonAdapter: JsonAdapter, ): JsonAdapter.Factory { return JsonAdapter.Factory { targetType, annotations, _ -> if (annotations.isEmpty() && typesMatch(type, targetType)) jsonAdapter else null @@ -383,7 +383,7 @@ public class Moshi internal constructor(builder: Builder) { fun newAdapterFactory( type: Type, annotation: Class, - jsonAdapter: JsonAdapter + jsonAdapter: JsonAdapter, ): JsonAdapter.Factory { require(annotation.isAnnotationPresent(JsonQualifier::class.java)) { "$annotation does not have @JsonQualifier" } require(annotation.declaredMethods.isEmpty()) { "Use JsonAdapter.Factory for annotations with elements" } diff --git a/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.kt b/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.kt index 8407932..83fff1e 100644 --- a/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.kt +++ b/moshi/src/main/java/com/squareup/moshi/StandardJsonAdapters.kt @@ -53,7 +53,9 @@ internal object StandardJsonAdapters : JsonAdapter.Factory { return if (rawType.isEnum) { @Suppress("UNCHECKED_CAST") EnumJsonAdapter(rawType as Class>).nullSafe() - } else null + } else { + null + } } fun rangeCheckNextInt(reader: JsonReader, typeMessage: String?, min: Int, max: Int): Int { @@ -120,7 +122,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory { // Double check for infinity after float conversion; many doubles > Float.MAX if (!reader.lenient && value.isInfinite()) { throw JsonDataException( - "JSON forbids NaN and infinities: $value at path ${reader.path}" + "JSON forbids NaN and infinities: $value at path ${reader.path}", ) } return value @@ -207,7 +209,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory { val path = reader.path val name = reader.nextString() throw JsonDataException( - "Expected one of ${nameStrings.toList()} but was $name at path $path" + "Expected one of ${nameStrings.toList()} but was $name at path $path", ) } @@ -242,7 +244,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory { JsonReader.Token.BOOLEAN -> booleanAdapter.fromJson(reader) JsonReader.Token.NULL -> reader.nextNull() else -> throw IllegalStateException( - "Expected a value but was ${reader.peek()} at path ${reader.path}" + "Expected a value but was ${reader.peek()} at path ${reader.path}", ) } } diff --git a/moshi/src/main/java/com/squareup/moshi/Types.kt b/moshi/src/main/java/com/squareup/moshi/Types.kt index 81e22fc..af7a10a 100644 --- a/moshi/src/main/java/com/squareup/moshi/Types.kt +++ b/moshi/src/main/java/com/squareup/moshi/Types.kt @@ -14,6 +14,7 @@ * limitations under the License. */ @file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + package com.squareup.moshi import com.squareup.moshi.internal.EMPTY_TYPE_ARRAY @@ -74,7 +75,7 @@ public object Types { @JvmStatic public fun nextAnnotations( annotations: Set, - jsonQualifier: Class + jsonQualifier: Class, ): Set? { require(jsonQualifier.isAnnotationPresent(JsonQualifier::class.java)) { "$jsonQualifier is not a JsonQualifier." @@ -112,7 +113,7 @@ public object Types { public fun newParameterizedTypeWithOwner( ownerType: Type?, rawType: Type, - vararg typeArguments: Type + vararg typeArguments: Type, ): ParameterizedType { require(typeArguments.isNotEmpty()) { "Missing type arguments for $rawType" @@ -198,7 +199,9 @@ public object Types { } return if (collectionType is ParameterizedType) { collectionType.actualTypeArguments[0] - } else Any::class.java + } else { + Any::class.java + } } /** Returns true if `a` and `b` are equal. */ @@ -254,7 +257,7 @@ public object Types { @JvmStatic public fun getFieldJsonQualifierAnnotations( clazz: Class<*>, - fieldName: String + fieldName: String, ): Set { try { val field = clazz.getDeclaredField(fieldName) @@ -271,7 +274,8 @@ public object Types { } } catch (e: NoSuchFieldException) { throw IllegalArgumentException( - "Could not access field $fieldName on class ${clazz.canonicalName}", e + "Could not access field $fieldName on class ${clazz.canonicalName}", + e, ) } } @@ -289,7 +293,8 @@ public object Types { } @Suppress("UNCHECKED_CAST") return Proxy.newProxyInstance( - annotationType.classLoader, arrayOf>(annotationType) + annotationType.classLoader, + arrayOf>(annotationType), ) { proxy, method, args -> when (method.name) { "annotationType" -> annotationType diff --git a/moshi/src/main/java/com/squareup/moshi/internal/Util.kt b/moshi/src/main/java/com/squareup/moshi/internal/Util.kt index c8a6e14..5c29a86 100644 --- a/moshi/src/main/java/com/squareup/moshi/internal/Util.kt +++ b/moshi/src/main/java/com/squareup/moshi/internal/Util.kt @@ -15,6 +15,7 @@ */ @file:JvmName("Util") @file:Suppress("unused", "MemberVisibilityCanBePrivate") + package com.squareup.moshi.internal import com.squareup.moshi.Json @@ -49,6 +50,7 @@ import java.util.LinkedHashSet import kotlin.contracts.contract @JvmField internal val NO_ANNOTATIONS: Set = emptySet() + @JvmField internal val EMPTY_TYPE_ARRAY: Array = arrayOf() @Suppress("UNCHECKED_CAST") @@ -108,7 +110,7 @@ public val Array.jsonAnnotations: Set for (annotation in this) { @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") if ((annotation as java.lang.annotation.Annotation).annotationType() - .isAnnotationPresent(JsonQualifier::class.java) + .isAnnotationPresent(JsonQualifier::class.java) ) { if (result == null) result = LinkedHashSet() result.add(annotation) @@ -118,7 +120,7 @@ public val Array.jsonAnnotations: Set } internal fun Set.isAnnotationPresent( - annotationClass: Class + annotationClass: Class, ): Boolean { if (isEmpty()) return false // Save an iterator in the common case. for (annotation in this) { @@ -207,7 +209,7 @@ public fun Type.resolve(context: Type, contextRawType: Class<*>): Type { private fun Type.resolve( context: Type, contextRawType: Class<*>, - visitedTypeVariables: MutableCollection> + visitedTypeVariables: MutableCollection>, ): Type { // This implementation is made a little more complicated in an attempt to avoid object-creation. var toResolve = this @@ -361,7 +363,7 @@ internal fun Type.toStringWithAnnotations(annotations: Set): String */ public fun Moshi.generatedAdapter( type: Type, - rawType: Class<*> + rawType: Class<*>, ): JsonAdapter<*>? { val jsonClass = rawType.getAnnotation(JsonClass::class.java) if (jsonClass == null || !jsonClass.generateAdapter) { @@ -403,11 +405,12 @@ public fun Moshi.generatedAdapter( if (possiblyFoundAdapter != null && type !is ParameterizedType && possiblyFoundAdapter.typeParameters.isNotEmpty()) { throw RuntimeException( "Failed to find the generated JsonAdapter constructor for '$type'. Suspiciously, the type was not parameterized but the target class '${possiblyFoundAdapter.canonicalName}' is generic. Consider using Types#newParameterizedType() to define these missing type variables.", - e + e, ) } else { throw RuntimeException( - "Failed to find the generated JsonAdapter constructor for $type", e + "Failed to find the generated JsonAdapter constructor for $type", + e, ) } } catch (e: IllegalAccessException) { @@ -452,7 +455,7 @@ private fun Class.findConstructor(): Constructor { public fun missingProperty( propertyName: String?, jsonName: String?, - reader: JsonReader + reader: JsonReader, ): JsonDataException { val path = reader.path val message = if (jsonName == propertyName) { @@ -466,7 +469,7 @@ public fun missingProperty( public fun unexpectedNull( propertyName: String, jsonName: String, - reader: JsonReader + reader: JsonReader, ): JsonDataException { val path = reader.path val message: String = if (jsonName == propertyName) { @@ -512,7 +515,7 @@ internal class ParameterizedTypeImpl private constructor( private val ownerType: Type?, private val rawType: Type, @JvmField - val typeArguments: Array + val typeArguments: Array, ) : ParameterizedType { override fun getActualTypeArguments() = typeArguments.clone() @@ -547,14 +550,16 @@ internal class ParameterizedTypeImpl private constructor( operator fun invoke( ownerType: Type?, rawType: Type, - vararg typeArguments: Type + vararg typeArguments: Type, ): ParameterizedTypeImpl { // Require an owner type if the raw type needs it. if (rawType is Class<*>) { val enclosingClass = rawType.enclosingClass if (ownerType != null) { require(!(enclosingClass == null || ownerType.rawType != enclosingClass)) { "unexpected owner type for $rawType: $ownerType" } - } else require(enclosingClass == null) { "unexpected owner type for $rawType: null" } + } else { + require(enclosingClass == null) { "unexpected owner type for $rawType: null" } + } } @Suppress("UNCHECKED_CAST") val finalTypeArgs = typeArguments.clone() as Array @@ -594,7 +599,7 @@ internal class GenericArrayTypeImpl private constructor(private val componentTyp */ internal class WildcardTypeImpl private constructor( private val upperBound: Type, - private val lowerBound: Type? + private val lowerBound: Type?, ) : WildcardType { override fun getUpperBounds() = arrayOf(upperBound) @@ -622,7 +627,7 @@ internal class WildcardTypeImpl private constructor( @JvmName("create") operator fun invoke( upperBounds: Array, - lowerBounds: Array + lowerBounds: Array, ): WildcardTypeImpl { require(lowerBounds.size <= 1) require(upperBounds.size == 1) @@ -631,13 +636,13 @@ internal class WildcardTypeImpl private constructor( require(!(upperBounds[0] !== Any::class.java)) WildcardTypeImpl( lowerBound = lowerBounds[0].canonicalize(), - upperBound = Any::class.java + upperBound = Any::class.java, ) } else { upperBounds[0].checkNotPrimitive() WildcardTypeImpl( lowerBound = null, - upperBound = upperBounds[0].canonicalize() + upperBound = upperBounds[0].canonicalize(), ) } } diff --git a/moshi/src/main/java16/com/squareup/moshi/RecordJsonAdapter.kt b/moshi/src/main/java16/com/squareup/moshi/RecordJsonAdapter.kt index ad3a683..c673f34 100644 --- a/moshi/src/main/java16/com/squareup/moshi/RecordJsonAdapter.kt +++ b/moshi/src/main/java16/com/squareup/moshi/RecordJsonAdapter.kt @@ -37,14 +37,14 @@ import java.lang.reflect.Type internal class RecordJsonAdapter( private val constructor: MethodHandle, private val targetClass: String, - componentBindings: Map> + componentBindings: Map>, ) : JsonAdapter() { data class ComponentBinding( val componentName: String, val jsonName: String, val adapter: JsonAdapter, - val accessor: MethodHandle + val accessor: MethodHandle, ) private val componentBindingsArray = componentBindings.values.toTypedArray() @@ -77,7 +77,7 @@ internal class RecordJsonAdapter( throw missingProperty( propertyName = componentBindingsArray[i].componentName, jsonName = componentBindingsArray[i].jsonName, - reader = reader + reader = reader, ) } } @@ -133,7 +133,7 @@ internal class RecordJsonAdapter( val replaced = bindings.put(componentBinding.jsonName, componentBinding) if (replaced != null) { throw IllegalArgumentException( - "Conflicting components:\n ${replaced.componentName}\n ${componentBinding.componentName}" + "Conflicting components:\n ${replaced.componentName}\n ${componentBinding.componentName}", ) } component.type @@ -155,7 +155,7 @@ internal class RecordJsonAdapter( rawType: Class<*>, moshi: Moshi, lookup: MethodHandles.Lookup, - component: RecordComponent + component: RecordComponent, ): ComponentBinding { val componentName = component.name val jsonName = component.jsonName(componentName)