diff --git a/build.gradle.kts b/build.gradle.kts index d55eba09..40d60c86 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,11 +60,7 @@ spotless { target("**/*.kt") trimTrailingWhitespace() endWithNewline() - targetExclude( - "**/Dependencies.kt", - "**/spotless.kt", - "**/build/**", - ) + targetExclude("**/Dependencies.kt", "**/spotless.kt", "**/build/**") } kotlinGradle { ktfmt(ktfmtVersion).googleStyle() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d909ce60..56572bc8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,15 +15,15 @@ [versions] agp = "8.2.1" autoService = "1.1.1" -gjf = "1.13.0" +gjf = "1.17.0" incap = "1.0.0" -jdk = "20" +jdk = "21" jvmTarget = "11" kotlin = "1.9.22" kotlinCompileTesting = "0.4.0" kotlinpoet = "1.15.3" ksp = "1.9.22-1.0.16" -ktfmt = "0.46" +ktfmt = "0.47" moshi = "1.15.0" okhttp = "4.12.0" retrofit = "2.9.0" diff --git a/moshi-adapters/src/main/kotlin/dev/zacsweers/moshix/adapters/TrackUnknownKeys.kt b/moshi-adapters/src/main/kotlin/dev/zacsweers/moshix/adapters/TrackUnknownKeys.kt index c185e853..46a9a67a 100644 --- a/moshi-adapters/src/main/kotlin/dev/zacsweers/moshix/adapters/TrackUnknownKeys.kt +++ b/moshi-adapters/src/main/kotlin/dev/zacsweers/moshix/adapters/TrackUnknownKeys.kt @@ -80,7 +80,7 @@ public annotation class TrackUnknownKeys { private val shouldTrack: (clazz: Class<*>, annotations: Set) -> Boolean = { _, _ -> true }, - private val tracker: UnknownKeysTracker + private val tracker: UnknownKeysTracker, ) : JsonAdapter.Factory { override fun create(type: Type, annotations: Set, moshi: Moshi): JsonAdapter<*>? { if (type !is Class<*>) return null @@ -95,7 +95,7 @@ public annotation class TrackUnknownKeys { private class TrackUnknownKeysJsonAdapter( private val delegate: JsonAdapter, private val clazz: Class<*>, - private val tracker: UnknownKeysTracker + private val tracker: UnknownKeysTracker, ) : JsonAdapter() { override fun fromJson(reader: JsonReader): T? { val token = reader.peek() diff --git a/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/AdaptedByTest.kt b/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/AdaptedByTest.kt index 640ecb58..e811d950 100644 --- a/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/AdaptedByTest.kt +++ b/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/AdaptedByTest.kt @@ -140,14 +140,14 @@ class AdaptedByTest { .isEqualTo( ClassUsingAnnotatedClasses( AnnotatedStringAlias("value"), - AnnotatedFactoryStringAlias("value") + AnnotatedFactoryStringAlias("value"), ) ) } data class ClassUsingAnnotatedClasses( val alias1: AnnotatedStringAlias, - val alias2: AnnotatedFactoryStringAlias + val alias2: AnnotatedFactoryStringAlias, ) @Test diff --git a/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/JsonStringTest.kt b/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/JsonStringTest.kt index a6bfdd9a..81ef184c 100644 --- a/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/JsonStringTest.kt +++ b/moshi-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/JsonStringTest.kt @@ -47,10 +47,7 @@ class JsonStringTest { } @JsonClass(generateAdapter = true) - data class ExampleClass( - val type: Int, - @JsonString val rawJson: String, - ) + data class ExampleClass(val type: Int, @JsonString val rawJson: String) @Test fun nullableCase() { @@ -68,10 +65,7 @@ class JsonStringTest { } @JsonClass(generateAdapter = true) - data class NullableExampleClass( - val type: Int, - @JsonString val rawJson: String?, - ) + data class NullableExampleClass(val type: Int, @JsonString val rawJson: String?) @Test fun retrofitServiceMethodCase() { diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/AppliedType.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/AppliedType.kt index 162e4625..182bb82b 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/AppliedType.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/AppliedType.kt @@ -32,9 +32,7 @@ internal class AppliedType private constructor(val type: IrClass) { * Returns all super classes of this, recursively. Only [IrClass] is used as we can't really use * other types. */ - fun superclasses( - pluginContext: IrPluginContext, - ): LinkedHashSet { + fun superclasses(pluginContext: IrPluginContext): LinkedHashSet { val result: LinkedHashSet = LinkedHashSet() result.add(this) for (supertype in type.getAllSuperclasses()) { diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/BaseSymbols.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/BaseSymbols.kt index 9ebcef3d..e942e5c7 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/BaseSymbols.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/BaseSymbols.kt @@ -36,7 +36,7 @@ import org.jetbrains.kotlin.name.Name internal open class BaseSymbols( protected val irBuiltIns: IrBuiltIns, protected val moduleFragment: IrModuleFragment, - val pluginContext: IrPluginContext + val pluginContext: IrPluginContext, ) { constructor( other: BaseSymbols @@ -138,7 +138,7 @@ internal open class BaseSymbols( protected fun createPackage(packageName: String): IrPackageFragment = IrExternalPackageFragmentImpl.createEmptyExternalPackageFragment( moduleFragment.descriptor, - FqName(packageName) + FqName(packageName), ) protected fun createClass( @@ -147,7 +147,7 @@ internal open class BaseSymbols( classKind: ClassKind, classModality: Modality, isValueClass: Boolean = false, - body: IrClass.() -> Unit = {} + body: IrClass.() -> Unit = {}, ): IrClassSymbol = irFactory .buildClass { @@ -169,7 +169,7 @@ internal open class BaseSymbols( endOffset, context.irBuiltIns.kClassClass.starProjectedType, context.irBuiltIns.kClassClass, - classType + classType, ) private fun IrBuilderWithScope.kClassToJavaClass(kClassReference: IrExpression) = @@ -185,7 +185,7 @@ internal open class BaseSymbols( fun javaClassReference( irBuilder: IrBuilderWithScope, classType: IrType, - forceObjectType: Boolean = false + forceObjectType: Boolean = false, ) = with(irBuilder) { val kClassReference = kClassReference(classType) diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiCommandLineProcessor.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiCommandLineProcessor.kt index bb0af17b..3e1967eb 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiCommandLineProcessor.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiCommandLineProcessor.kt @@ -42,7 +42,7 @@ public class MoshiCommandLineProcessor : CommandLineProcessor { valueDescription = "", description = KEY_ENABLED.toString(), required = true, - allowMultipleOccurrences = false + allowMultipleOccurrences = false, ) val OPTION_DEBUG = CliOption( @@ -50,7 +50,7 @@ public class MoshiCommandLineProcessor : CommandLineProcessor { valueDescription = "", description = KEY_DEBUG.toString(), required = false, - allowMultipleOccurrences = false + allowMultipleOccurrences = false, ) val OPTION_ENABLE_SEALED = CliOption( @@ -58,7 +58,7 @@ public class MoshiCommandLineProcessor : CommandLineProcessor { valueDescription = "", description = KEY_GENERATED_ANNOTATION.toString(), required = false, - allowMultipleOccurrences = false + allowMultipleOccurrences = false, ) val OPTION_GENERATED_ANNOTATION = CliOption( @@ -66,24 +66,19 @@ public class MoshiCommandLineProcessor : CommandLineProcessor { valueDescription = "String", description = KEY_ENABLE_SEALED.toString(), required = false, - allowMultipleOccurrences = false + allowMultipleOccurrences = false, ) } override val pluginId: String = "dev.zacsweers.moshix.compiler" override val pluginOptions: Collection = - listOf( - OPTION_DEBUG, - OPTION_ENABLED, - OPTION_ENABLE_SEALED, - OPTION_GENERATED_ANNOTATION, - ) + listOf(OPTION_DEBUG, OPTION_ENABLED, OPTION_ENABLE_SEALED, OPTION_GENERATED_ANNOTATION) override fun processOption( option: AbstractCliOption, value: String, - configuration: CompilerConfiguration + configuration: CompilerConfiguration, ): Unit = when (option.optionName) { "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean()) diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrGenerationExtension.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrGenerationExtension.kt index a91fcaef..f605ad9a 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrGenerationExtension.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrGenerationExtension.kt @@ -26,7 +26,7 @@ internal class MoshiIrGenerationExtension( private val messageCollector: MessageCollector, private val generatedAnnotationName: ClassId?, private val enableSealed: Boolean, - private val debug: Boolean + private val debug: Boolean, ) : IrGenerationExtension { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { @@ -48,7 +48,7 @@ internal class MoshiIrGenerationExtension( generatedAnnotation, enableSealed, deferred, - debug + debug, ) moduleFragment.transform(moshiTransformer, null) for ((file, adapters) in deferred.groupBy { it.irFile }) { diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrUtil.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrUtil.kt index a4323e5e..198059f8 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrUtil.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrUtil.kt @@ -83,7 +83,7 @@ private val TargetProperty.isVisible: Boolean */ internal fun TargetProperty.generator( originalType: IrClass, - errors: MutableList<(logger: MessageCollector) -> Unit> + errors: MutableList<(logger: MessageCollector) -> Unit>, ): PropertyGenerator? { if (jsonIgnore) { if (!hasDefault) { diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitor.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitor.kt index b76328cd..e2d6f655 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitor.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitor.kt @@ -58,9 +58,7 @@ internal class MoshiIrVisitor( private val moshiSealedSymbols by lazy { MoshiSealedSymbols(moshiSymbols) } - private fun adapterGenerator( - originalType: IrClass, - ): MoshiAdapterGenerator? { + private fun adapterGenerator(originalType: IrClass): MoshiAdapterGenerator? { val type = targetType(originalType, pluginContext, messageCollector) ?: return null val properties = mutableMapOf() @@ -123,7 +121,7 @@ internal class MoshiIrVisitor( moshiSymbols = moshiSymbols, moshiSealedSymbols = moshiSealedSymbols, target = declaration, - labelKey = labelKey + labelKey = labelKey, ) } else { return super.visitClassNew(declaration) @@ -143,7 +141,7 @@ internal class MoshiIrVisitor( val irSrc = adapterClass.adapterClass.dumpSrc() messageCollector.report( CompilerMessageSeverity.STRONG_WARNING, - "MOSHI: Dumping current IR src for ${adapterClass.adapterClass.name}\n$irSrc" + "MOSHI: Dumping current IR src for ${adapterClass.adapterClass.name}\n$irSrc", ) } deferredAddedClasses += GeneratedAdapter(adapterClass.adapterClass, declaration.file) diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiSymbols.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiSymbols.kt index 6a999506..af5c0170 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiSymbols.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiSymbols.kt @@ -45,7 +45,7 @@ import org.jetbrains.kotlin.name.Name internal class MoshiSymbols( irBuiltIns: IrBuiltIns, moduleFragment: IrModuleFragment, - pluginContext: IrPluginContext + pluginContext: IrPluginContext, ) : BaseSymbols(irBuiltIns, moduleFragment, pluginContext) { private val moshiPackage: IrPackageFragment by lazy { createPackage("com.squareup.moshi") } private val moshiInternalPackage: IrPackageFragment by lazy { @@ -71,7 +71,7 @@ internal class MoshiSymbols( addFunction( Name.identifier("beginObject").identifier, irBuiltIns.unitType, - Modality.ABSTRACT + Modality.ABSTRACT, ) addFunction(Name.identifier("endObject").identifier, irBuiltIns.unitType, Modality.ABSTRACT) addFunction(Name.identifier("skipName").identifier, irBuiltIns.unitType, Modality.ABSTRACT) @@ -80,7 +80,7 @@ internal class MoshiSymbols( addFunction( Name.identifier("hasNext").identifier, irBuiltIns.booleanType, - Modality.ABSTRACT + Modality.ABSTRACT, ) val optionsClass = createClass(this, "Options", ClassKind.CLASS, Modality.FINAL) @@ -157,14 +157,14 @@ internal class MoshiSymbols( addFunction( Name.identifier("adapter").identifier, jsonAdapter.typeWith(irBuiltIns.anyNType), - Modality.FINAL + Modality.FINAL, ) .apply { addTypeParameter("T", irBuiltIns.anyNType) addValueParameter("type", type.defaultType) addValueParameter( "annotations", - irBuiltIns.setClass.typeWith(irBuiltIns.annotationType) + irBuiltIns.setClass.typeWith(irBuiltIns.annotationType), ) addValueParameter("fieldName", irBuiltIns.stringType) } @@ -172,7 +172,7 @@ internal class MoshiSymbols( addFunction( Name.identifier("newBuilder").identifier, moshiBuilder.defaultType, - Modality.FINAL + Modality.FINAL, ) } .symbol @@ -205,7 +205,7 @@ internal class MoshiSymbols( addFunction( Name.identifier("fromJson").identifier, t.defaultType.makeNullable(), - Modality.ABSTRACT + Modality.ABSTRACT, ) .apply { addValueParameter("reader", jsonReader.defaultType) } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/TargetTypes.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/TargetTypes.kt index bc8d0210..b19898d6 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/TargetTypes.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/TargetTypes.kt @@ -163,9 +163,7 @@ internal fun targetType( ) } -internal fun primaryConstructor( - targetType: IrClass, -): TargetConstructor? { +internal fun primaryConstructor(targetType: IrClass): TargetConstructor? { val primaryConstructor = targetType.primaryConstructor ?: return null val parameters = LinkedHashMap() @@ -180,15 +178,11 @@ internal fun primaryConstructor( hasDefault = parameter.hasDefaultValue(), qualifiers = parameter.jsonQualifiers(), jsonIgnore = parameter.jsonIgnore(), - jsonName = parameter.jsonName() + jsonName = parameter.jsonName(), ) } - return TargetConstructor( - primaryConstructor, - parameters, - primaryConstructor.visibility, - ) + return TargetConstructor(primaryConstructor, parameters, primaryConstructor.visibility) } private fun declaredProperties( @@ -208,7 +202,7 @@ private fun declaredProperties( visibility = property.visibility, jsonName = property.jsonNameFromAnywhere() ?: parameter?.jsonName ?: name, jsonIgnore = - isTransient || parameter?.jsonIgnore == true || property.jsonIgnoreFromAnywhere() + isTransient || parameter?.jsonIgnore == true || property.jsonIgnoreFromAnywhere(), ) } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/DelegateKey.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/DelegateKey.kt index bab8c53e..3b032102 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/DelegateKey.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/DelegateKey.kt @@ -72,7 +72,7 @@ internal data class DelegateKey( adapterCls: IrClass, moshiParameter: IrValueParameter, typesParameter: IrValueParameter?, - propertyName: String + propertyName: String, ): IrField { val qualifierNames = jsonQualifiers.joinToString("") { @@ -111,7 +111,7 @@ internal data class DelegateKey( typesParameter, genericIndex, propertyName, - jsonQualifiers + jsonQualifiers, ) } return field @@ -126,7 +126,7 @@ private fun IrBuilderWithScope.moshiAdapterCall( typesParameter: IrValueParameter?, genericIndex: Int, propertyName: String, - jsonQualifiers: List + jsonQualifiers: List, ): IrExpressionBody { return irExprBody( irCall(moshiSymbols.moshiThreeArgAdapter).apply { @@ -158,7 +158,7 @@ private fun IrBuilderWithScope.addTypeParam( irCall(moshiSymbols.arrayGet.symbol).apply { dispatchReceiver = irGet(typesParameter!!) putValueArgument(0, irInt(genericIndex)) - } + }, ) } } @@ -167,7 +167,7 @@ private fun IrBuilderWithScope.addAnnotationsParam( irCall: IrCall, pluginContext: IrPluginContext, moshiSymbols: MoshiSymbols, - jsonQualifiers: List + jsonQualifiers: List, ) = irCall.apply { val argumentExpression = @@ -189,7 +189,7 @@ private fun IrBuilderWithScope.addAnnotationsParam( callee = callee, type = pluginContext.irBuiltIns.setClass.typeWith(pluginContext.irBuiltIns.annotationType), - typeArguments = listOf(pluginContext.irBuiltIns.annotationType) + typeArguments = listOf(pluginContext.irBuiltIns.annotationType), ) .apply { putValueArgument(0, argExpression) } } @@ -238,7 +238,7 @@ private fun IrBuilderWithScope.renderType( moshiSymbols: MoshiSymbols, delegateType: IrType, typesParameter: IrValueParameter?, - forceBoxing: Boolean = false + forceBoxing: Boolean = false, ): IrExpression { check(delegateType is IrSimpleType) { "Expected a SimpleType, got $delegateType" } val classifier = delegateType.classifier @@ -265,8 +265,8 @@ private fun IrBuilderWithScope.renderType( renderType( moshiSymbols, builtIns.primitiveTypeToIrType.getValue(primitiveArrayType), - typesParameter - ) + typesParameter, + ), ) } } @@ -278,8 +278,8 @@ private fun IrBuilderWithScope.renderType( moshiSymbols, delegateType.arguments[0].typeOrNull!!, typesParameter, - forceBoxing = true - ) + forceBoxing = true, + ), ) } } @@ -288,7 +288,7 @@ private fun IrBuilderWithScope.renderType( return if (delegateType.arguments.isEmpty()) { irImplicitCast( moshiSymbols.javaClassReference(this, delegateType, forceObjectType = forceBoxing), - moshiSymbols.type.defaultType + moshiSymbols.type.defaultType, ) } else { // Build the generic @@ -334,12 +334,12 @@ private fun IrBuilderWithScope.renderType( irCall(moshiSymbols.moshiTypesSubtypeOf).apply { putValueArgument( 0, - renderType(moshiSymbols, builtIns.anyType, typesParameter, forceBoxing = true) + renderType(moshiSymbols, builtIns.anyType, typesParameter, forceBoxing = true), ) } } - } - ) + }, + ), ) } } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/MoshiAdapterGenerator.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/MoshiAdapterGenerator.kt index ad1b0cb3..82789614 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/MoshiAdapterGenerator.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/MoshiAdapterGenerator.kt @@ -129,7 +129,7 @@ internal class MoshiAdapterGenerator( private fun irType( classId: ClassId, nullable: Boolean = false, - arguments: List = emptyList() + arguments: List = emptyList(), ) = pluginContext.irType(classId, nullable, arguments) override fun prepare(): PreparedAdapter { @@ -176,7 +176,7 @@ internal class MoshiAdapterGenerator( classifier = adapterCls.symbol, hasQuestionMark = false, arguments = emptyList(), - annotations = emptyList() + annotations = emptyList(), ) origin = IrDeclarationOrigin.INSTANCE_RECEIVER } @@ -200,7 +200,7 @@ internal class MoshiAdapterGenerator( adapterCls, ctor.valueParameters[0], ctor.valueParameters.getOrNull(1), - uniqueAdapter.name + uniqueAdapter.name, ) } @@ -237,10 +237,7 @@ internal class MoshiAdapterGenerator( ctor.irConstructorBody(pluginContext) { statements -> statements += generateJsonAdapterSuperConstructorCall() statements += - irInstanceInitializerCall( - context = pluginContext, - classSymbol = adapterCls.symbol, - ) + irInstanceInitializerCall(context = pluginContext, classSymbol = adapterCls.symbol) // Size check for types array. Must be equal to the number of type parameters // require(types.size == 1) { @@ -256,7 +253,7 @@ internal class MoshiAdapterGenerator( irCall(moshiSymbols.arraySizeGetter).apply { dispatchReceiver = irGet(ctor.valueParameters[1]) }, - nameHint = "receivedSize" + nameHint = "receivedSize", ) +irIfThen( condition = irNotEquals(irGet(receivedSize), irInt(expectedSize)), @@ -277,10 +274,10 @@ internal class MoshiAdapterGenerator( ) addArgument(irString("], but received ")) addArgument(irGet(receivedSize)) - } + }, ) } - ) + ), ) } } @@ -314,7 +311,7 @@ internal class MoshiAdapterGenerator( FqName("com.squareup.moshi.JsonAdapter"), Name.identifier("toJson").identifier, pluginContext.irBuiltIns.unitType, - modality = Modality.OPEN + modality = Modality.OPEN, ) { function -> function.valueParameters.size == 2 && function.valueParameters[0].type.classifierOrFail == moshiSymbols.jsonWriter @@ -344,10 +341,10 @@ internal class MoshiAdapterGenerator( .apply { putValueArgument( 0, - irString("value was null! Wrap in .nullSafe() to write nullable values.") + irString("value was null! Wrap in .nullSafe() to write nullable values."), ) } - ) + ), ) // Cast it up to the actual type val castValue = @@ -366,7 +363,7 @@ internal class MoshiAdapterGenerator( dispatchReceiver = irGetField( irGet(dispatchReceiverParameter!!), - adapterProperties.getValue(property.delegateKey) + adapterProperties.getValue(property.delegateKey), ) // writer putValueArgument(0, irGet(writer)) @@ -375,7 +372,7 @@ internal class MoshiAdapterGenerator( 1, irCall(target.irClass.getPropertyGetter(property.name)!!).apply { dispatchReceiver = irGet(castValue) - } + }, ) } } @@ -389,7 +386,7 @@ internal class MoshiAdapterGenerator( private fun IrClass.generateFromJsonFun( adapterProperties: Map, - optionsField: IrField + optionsField: IrField, ): IrFunction { return addOverride( FqName("com.squareup.moshi.JsonAdapter"), @@ -424,7 +421,7 @@ internal class MoshiAdapterGenerator( "errors", irType = pluginContext.irBuiltIns.setClass.typeWith(pluginContext.irBuiltIns.stringType), - isMutable = true + isMutable = true, ) val propertiesByIndex = @@ -482,7 +479,7 @@ internal class MoshiAdapterGenerator( errors = errors, maskAllSetValues = maskAllSetValues, bitMasks = bitMasks, - components = components + components = components, ) +irCall(moshiSymbols.jsonReader.getSimpleFunction("endObject")!!).apply { dispatchReceiver = irGet(readerParam) @@ -498,11 +495,11 @@ internal class MoshiAdapterGenerator( irAnd( pluginContext, irNot(irGet(localVars.getValue(property.localHasErrorName))), - irEqualsNull(irGet(localVars.getValue(property.localName))) + irEqualsNull(irGet(localVars.getValue(property.localName))), ) +irIfThen( condition = compositeCondition, - thenPart = addError(errors, property, readerParam, "missingProperty") + thenPart = addError(errors, property, readerParam, "missingProperty"), ) } } @@ -513,7 +510,7 @@ internal class MoshiAdapterGenerator( irNotEquals( irCall(pluginContext.irBuiltIns.setClass.owner.getPropertyGetter("size")!!) .apply { dispatchReceiver = irGet(errors) }, - irInt(0) + irInt(0), ), thenPart = irThrow( @@ -523,10 +520,10 @@ internal class MoshiAdapterGenerator( irCall(moshiSymbols.iterableJoinToString).apply { extensionReceiver = irGet(errors) putValueArgument(0, irString("\n")) - } + }, ) } - ) + ), ) val standardConstructor = target.constructor.irConstructor.symbol @@ -544,7 +541,7 @@ internal class MoshiAdapterGenerator( } addValueParameter( "marker", - irType(ClassId.fromString("kotlin/jvm/internal/DefaultConstructorMarker")) + irType(ClassId.fromString("kotlin/jvm/internal/DefaultConstructorMarker")), ) } .symbol @@ -563,7 +560,7 @@ internal class MoshiAdapterGenerator( localVars, components, bitMasks, - useDefaultsConstructor = true + useDefaultsConstructor = true, ) } else { // Happy path - all parameters with defaults are set @@ -572,10 +569,7 @@ internal class MoshiAdapterGenerator( .withIndex() .asSequence() .map { (index, maskName) -> - irEquals( - irGet(maskName), - irInt(maskAllSetValues[index]), - ) + irEquals(irGet(maskName), irInt(maskAllSetValues[index])) } .joinToIrAnd(this, pluginContext) @@ -589,7 +583,7 @@ internal class MoshiAdapterGenerator( localVars, components, bitMasks, - useDefaultsConstructor = false + useDefaultsConstructor = false, ), // Not all set, invoke the defaults constructor elsePart = @@ -598,8 +592,8 @@ internal class MoshiAdapterGenerator( localVars, components, bitMasks, - useDefaultsConstructor = true - ) + useDefaultsConstructor = true, + ), ) } } else { @@ -609,7 +603,7 @@ internal class MoshiAdapterGenerator( localVars, components, bitMasks, - useDefaultsConstructor = false + useDefaultsConstructor = false, ) } @@ -617,7 +611,7 @@ internal class MoshiAdapterGenerator( irTemporary( constructorInvocationExpression, nameHint = "result", - irType = target.irType + irType = target.irType, ) // Assign properties not present in the constructor. @@ -636,7 +630,7 @@ internal class MoshiAdapterGenerator( irCall(property.target.property.setter!!).apply { dispatchReceiver = irGet(result) putValueArgument(0, irGet(localVars.getValue(property.localName))) - } + }, ) } @@ -654,7 +648,7 @@ internal class MoshiAdapterGenerator( errors: IrVariable, maskAllSetValues: IntArray, bitMasks: List, - components: List + components: List, ) = irWhile().apply { condition = @@ -668,7 +662,7 @@ internal class MoshiAdapterGenerator( dispatchReceiver = irGet(readerParam) putValueArgument(0, irGetField(irGet(fieldsHolder), optionsField)) }, - nameHint = "nextName" + nameHint = "nextName", ) // We track property index and mask index separately, because mask index is @@ -728,7 +722,7 @@ internal class MoshiAdapterGenerator( dispatchReceiver = irGetField( irGet(fieldsHolder), - adapterProperties.getValue(property.delegateKey) + adapterProperties.getValue(property.delegateKey), ) putValueArgument(0, irGet(readerParam)) } @@ -749,7 +743,7 @@ internal class MoshiAdapterGenerator( +irSet(localVars.getValue(property.localHasErrorName), irBoolean(true)) +addError(errors, property, readerParam, "unexpectedNull") }, - elsePart = setVarExpression + elsePart = setVarExpression, ) } else { +setVarExpression @@ -772,11 +766,11 @@ internal class MoshiAdapterGenerator( pluginContext, OperatorNameConventions.AND, irGet(bitMasks[maskNameIndex]), - irInt(inverted) + irInt(inverted), ) +irSet(bitMasks[maskNameIndex].symbol, and) } - } + }, ) ) propertyIndex++ @@ -794,7 +788,7 @@ internal class MoshiAdapterGenerator( +irCall(moshiSymbols.jsonReader.getSimpleFunction("skipValue")!!).apply { dispatchReceiver = irGet(readerParam) } - } + }, ) ) // TODO merge this and the -1? Throw an error? @@ -811,7 +805,7 @@ internal class MoshiAdapterGenerator( errors: IrVariable, property: PropertyGenerator, readerParam: IrValueParameter, - moshiUtilFunction: String + moshiUtilFunction: String, ) = irSet( errors, @@ -826,9 +820,9 @@ internal class MoshiAdapterGenerator( putValueArgument(1, irString(property.jsonName)) putValueArgument(2, irGet(readerParam)) } - } + }, ) - } + }, ) private fun IrBuilderWithScope.constructorCall( @@ -836,7 +830,7 @@ internal class MoshiAdapterGenerator( localVars: Map, components: List, bitMasks: List, - useDefaultsConstructor: Boolean + useDefaultsConstructor: Boolean, ) = irCall(constructor).apply { var lastIndex = 0 @@ -853,12 +847,12 @@ internal class MoshiAdapterGenerator( // primitive type. putValueArgument( input.parameter.index, - defaultPrimitiveValue(input.type, pluginContext) + defaultPrimitiveValue(input.type, pluginContext), ) } else { putValueArgument( input.parameter.index, - irGet(localVars.getValue((input as ParameterProperty).property.localName)) + irGet(localVars.getValue((input as ParameterProperty).property.localName)), ) } } else if (input !is ParameterOnly) { @@ -884,7 +878,7 @@ internal class MoshiAdapterGenerator( startOffset, endOffset, pluginContext.irBuiltIns.unitType, - moshiSymbols.jsonAdapter.constructors.single() + moshiSymbols.jsonAdapter.constructors.single(), ) } } @@ -919,7 +913,7 @@ private sealed class FromJsonComponent { data class ParameterProperty( override val parameter: TargetParameter, - override val property: PropertyGenerator + override val property: PropertyGenerator, ) : FromJsonComponent(), ParameterComponent, PropertyComponent { override val type: IrType = parameter.type } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/PropertyGenerator.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/PropertyGenerator.kt index 9045d4a9..8c4e17a6 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/PropertyGenerator.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/PropertyGenerator.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.ir.types.makeNullable internal class PropertyGenerator( val target: TargetProperty, val delegateKey: DelegateKey, - val isTransientOrIgnored: Boolean = false + val isTransientOrIgnored: Boolean = false, ) { val name: String = target.name val jsonName: String = target.jsonName ?: target.name @@ -67,7 +67,7 @@ internal class PropertyGenerator( internal fun generateLocalProperty( builder: IrStatementsBuilder<*>, - pluginContext: IrPluginContext + pluginContext: IrPluginContext, ): IrVariable { builder.apply { val expression = @@ -83,35 +83,35 @@ internal class PropertyGenerator( expression, isMutable = true, nameHint = localName, - irType = expression.type + irType = expression.type, ) } } internal fun generateLocalIsPresentProperty( builder: IrStatementsBuilder<*>, - pluginContext: IrPluginContext + pluginContext: IrPluginContext, ): IrVariable { builder.apply { return irTemporary( irBoolean(false), isMutable = true, nameHint = localIsPresentName, - irType = pluginContext.irBuiltIns.booleanType + irType = pluginContext.irBuiltIns.booleanType, ) } } internal fun generateLocalHasErrorProperty( builder: IrStatementsBuilder<*>, - pluginContext: IrPluginContext + pluginContext: IrPluginContext, ): IrVariable { builder.apply { return irTemporary( irBoolean(false), isMutable = true, nameHint = localHasErrorName, - irType = pluginContext.irBuiltIns.booleanType + irType = pluginContext.irBuiltIns.booleanType, ) } } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetParameter.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetParameter.kt index c44573e9..85f12a90 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetParameter.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetParameter.kt @@ -26,5 +26,5 @@ internal 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-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetProperty.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetProperty.kt index f623793b..ee7423e4 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetProperty.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/api/TargetProperty.kt @@ -26,7 +26,7 @@ internal data class TargetProperty( val parameter: TargetParameter?, val visibility: DescriptorVisibility, val jsonName: String?, - val jsonIgnore: Boolean + val jsonIgnore: Boolean, ) { val name: String get() = property.name.identifier diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/MoshiSealedSymbols.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/MoshiSealedSymbols.kt index 28c5e51f..69fb38cd 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/MoshiSealedSymbols.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/MoshiSealedSymbols.kt @@ -34,9 +34,8 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance -internal class MoshiSealedSymbols( - private val moshiSymbols: MoshiSymbols, -) : BaseSymbols(moshiSymbols) { +internal class MoshiSealedSymbols(private val moshiSymbols: MoshiSymbols) : + BaseSymbols(moshiSymbols) { private val moshiAdaptersPackage: IrPackageFragment by lazy { createPackage("com.squareup.moshi.adapters") @@ -51,7 +50,7 @@ internal class MoshiSealedSymbols( moshiAdaptersPackage, "PolymorphicJsonAdapterFactory", ClassKind.CLASS, - Modality.FINAL + Modality.FINAL, ) { val classTypeParameter = addTypeParameter("T", irBuiltIns.anyNType, Variance.INVARIANT) // val pjafWithDefaultValue by lazy { pjaf.getSimpleFunction("withDefaultValue")!! } @@ -97,7 +96,7 @@ internal class MoshiSealedSymbols( .apply { addValueParameter( "fallbackJsonAdapter", - moshiSymbols.jsonAdapter.typeWith(irBuiltIns.anyNType).makeNullable() + moshiSymbols.jsonAdapter.typeWith(irBuiltIns.anyNType).makeNullable(), ) } } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/SealedAdapterGenerator.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/SealedAdapterGenerator.kt index dd8c7c13..adc3d02b 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/SealedAdapterGenerator.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/sealed/SealedAdapterGenerator.kt @@ -169,7 +169,7 @@ private constructor( fallbackStrategy = FallbackStrategy.FallbackAdapter( targetConstructor = constructor.symbol, - hasMoshiParam = hasMoshiParam + hasMoshiParam = hasMoshiParam, ) } else if (useDefaultNull) { fallbackStrategy = FallbackStrategy.Null @@ -217,7 +217,7 @@ private constructor( fallbackStrategy = fallbackStrategy, generatedAnnotation = null, subtypes = sealedSubtypes, - objectSubtypes = objectSubtypes + objectSubtypes = objectSubtypes, ) } } @@ -262,7 +262,7 @@ private constructor( subtype = it.owner, labelKey = labelKey, seenLabels = seenLabels, - objectSubtypes = objectSubtypes + objectSubtypes = objectSubtypes, ) } } @@ -271,7 +271,7 @@ private constructor( addLabelKeyForType( subtype = subtype, seenLabels = seenLabels, - objectSubtypes = objectSubtypes + objectSubtypes = objectSubtypes, ) classType?.let { sequenceOf(it) } ?: emptySequence() } @@ -281,7 +281,7 @@ private constructor( subtype: IrClass, seenLabels: MutableMap, objectSubtypes: MutableList, - skipJsonClassCheck: Boolean = false + skipJsonClassCheck: Boolean = false, ): Subtype? { // Regular subtype, read its label val labelAnnotation = @@ -383,7 +383,7 @@ private constructor( classifier = adapterCls.symbol, hasQuestionMark = false, arguments = emptyList(), - annotations = emptyList() + annotations = emptyList(), ) origin = IrDeclarationOrigin.INSTANCE_RECEIVER } @@ -414,7 +414,7 @@ private constructor( putTypeArgument(0, targetType.defaultType) putValueArgument( 0, - moshiSymbols.javaClassReference(this@run, targetType.defaultType) + moshiSymbols.javaClassReference(this@run, targetType.defaultType), ) putValueArgument(1, irString(labelKey)) } @@ -435,7 +435,7 @@ private constructor( 0, irCall(moshiSealedSymbols.objectJsonAdapterCtor).apply { putValueArgument(0, irGetObject(subtype.symbol)) - } + }, ) } } @@ -453,7 +453,7 @@ private constructor( dispatchReceiver = nestedReceiver putValueArgument( 0, - moshiSymbols.javaClassReference(this@run, subtype.className.defaultType) + moshiSymbols.javaClassReference(this@run, subtype.className.defaultType), ) putValueArgument(1, irString(label)) } @@ -479,7 +479,7 @@ private constructor( moshiSealedSymbols = moshiSealedSymbols, subtypesExpression = subtypesExpression, targetType = targetType.defaultType, - moshiParam = moshiParam + moshiParam = moshiParam, ) } ?: subtypesExpression @@ -490,12 +490,12 @@ private constructor( dispatchReceiver = possiblyWithDefaultExpression putValueArgument( 0, - moshiSymbols.javaClassReference(this@run, targetType.defaultType) + moshiSymbols.javaClassReference(this@run, targetType.defaultType), ) putValueArgument(1, irCall(moshiSymbols.emptySet)) putValueArgument(2, moshiAccess) }, - jsonAdapterType + jsonAdapterType, ) ) } @@ -506,7 +506,7 @@ private constructor( adapterCls.generateToStringFun( pluginContext, simpleNames.joinToString("."), - generatedName = "GeneratedSealedJsonAdapter" + generatedName = "GeneratedSealedJsonAdapter", ) return PreparedAdapter(adapterCls) @@ -517,7 +517,7 @@ private constructor( FqName("com.squareup.moshi.JsonAdapter"), Name.identifier("toJson").identifier, pluginContext.irBuiltIns.unitType, - modality = Modality.OPEN + modality = Modality.OPEN, ) { function -> function.valueParameters.size == 2 && function.valueParameters[0].type.classifierOrFail == moshiSymbols.jsonWriter @@ -588,10 +588,7 @@ private constructor( ctor.irConstructorBody(pluginContext) { statements -> statements += generateJsonAdapterSuperConstructorCall() statements += - irInstanceInitializerCall( - context = pluginContext, - classSymbol = adapterCls.symbol, - ) + irInstanceInitializerCall(context = pluginContext, classSymbol = adapterCls.symbol) } return ctor @@ -603,7 +600,7 @@ private constructor( startOffset, endOffset, pluginContext.irBuiltIns.unitType, - moshiSymbols.jsonAdapter.constructors.single() + moshiSymbols.jsonAdapter.constructors.single(), ) } @@ -632,7 +629,7 @@ private constructor( moshiSymbols = moshiSymbols, moshiSealedSymbols = moshiSealedSymbols, target = target, - labelKey = labelKey + labelKey = labelKey, ) } } diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/IrSourcePrinter.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/IrSourcePrinter.kt index 77d1e80e..fdd42edb 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/IrSourcePrinter.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/IrSourcePrinter.kt @@ -136,10 +136,8 @@ internal fun IrElement.dumpSrc(): String { } @Suppress("DEPRECATION") -internal class IrSourcePrinterVisitor( - out: Appendable, - indentUnit: String = " ", -) : IrElementVisitorVoid { +internal class IrSourcePrinterVisitor(out: Appendable, indentUnit: String = " ") : + IrElementVisitorVoid { private val printer = Printer(out, indentUnit) private fun IrElement.print() { @@ -476,7 +474,7 @@ internal class IrSourcePrinterVisitor( private fun IrFunctionAccessExpression.printArgumentList( forceParameterNames: Boolean = false, - forceSingleLine: Boolean = false + forceSingleLine: Boolean = false, ) { val arguments = mutableListOf() val paramNames = mutableListOf() @@ -625,7 +623,7 @@ internal class IrSourcePrinterVisitor( if (printArgumentList) { expression.printArgumentList( forceParameterNames = isAnnotation, - forceSingleLine = isAnnotation + forceSingleLine = isAnnotation, ) } } @@ -1432,7 +1430,7 @@ private inline fun StringBuilder.appendListWith( prefix: String, postfix: String, separator: String, - renderItem: StringBuilder.(T) -> Unit + renderItem: StringBuilder.(T) -> Unit, ) { append(prefix) var isFirst = true diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/NameAllocator.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/NameAllocator.kt index f9b8d1a2..e9ef3440 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/NameAllocator.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/NameAllocator.kt @@ -73,7 +73,7 @@ import java.util.UUID internal class NameAllocator private constructor( private val allocatedNames: MutableSet, - private val tagToName: MutableMap + private val tagToName: MutableMap, ) { constructor() : this(mutableSetOf(), mutableMapOf()) diff --git a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/ir.kt b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/ir.kt index ffd74470..cffc1466 100644 --- a/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/ir.kt +++ b/moshi-ir/moshi-compiler-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/compiler/util/ir.kt @@ -95,7 +95,7 @@ internal fun IrElement?.locationIn(file: IrFile): CompilerMessageSourceLocation val sourceRangeInfo = file.fileEntry.getSourceRangeInfo( beginOffset = this?.startOffset ?: SYNTHETIC_OFFSET, - endOffset = this?.endOffset ?: SYNTHETIC_OFFSET + endOffset = this?.endOffset ?: SYNTHETIC_OFFSET, ) return CompilerMessageLocationWithRange.create( path = sourceRangeInfo.filePath, @@ -103,7 +103,7 @@ internal fun IrElement?.locationIn(file: IrFile): CompilerMessageSourceLocation columnStart = sourceRangeInfo.startColumnNumber + 1, lineEnd = sourceRangeInfo.endLineNumber + 1, columnEnd = sourceRangeInfo.endColumnNumber + 1, - lineContent = null + lineContent = null, )!! } @@ -114,14 +114,14 @@ internal inline fun MessageCollector.error(declaration: IrDeclaration, message: internal inline fun MessageCollector.error( noinline location: (() -> CompilerMessageSourceLocation)?, - message: () -> String + message: () -> String, ) { report(CompilerMessageSeverity.ERROR, message(), location?.invoke()) } internal fun IrConstructor.irConstructorBody( context: IrGeneratorContext, - blockBody: DeclarationIrBuilder.(MutableList) -> Unit + blockBody: DeclarationIrBuilder.(MutableList) -> Unit, ) { val startOffset = UNDEFINED_OFFSET val endOffset = UNDEFINED_OFFSET @@ -130,15 +130,12 @@ internal fun IrConstructor.irConstructorBody( generatorContext = context, symbol = IrSimpleFunctionSymbolImpl(), startOffset = startOffset, - endOffset = endOffset + endOffset = endOffset, ) body = - context.irFactory - .createBlockBody( - startOffset = startOffset, - endOffset = endOffset, - ) - .apply { constructorIrBuilder.blockBody(statements) } + context.irFactory.createBlockBody(startOffset = startOffset, endOffset = endOffset).apply { + constructorIrBuilder.blockBody(statements) + } } internal fun DeclarationIrBuilder.irInstanceInitializerCall( @@ -168,13 +165,13 @@ internal fun IrPluginContext.createIrBuilder(symbol: IrSymbol): DeclarationIrBui internal fun IrPluginContext.irType( classId: ClassId, nullable: Boolean = false, - arguments: List = emptyList() + arguments: List = emptyList(), ): IrType = referenceClass(classId)!!.createType(hasQuestionMark = nullable, arguments = arguments) // returns null: Any? for boxed types and 0: for primitives internal fun IrBuilderWithScope.defaultPrimitiveValue( type: IrType, - pluginContext: IrPluginContext + pluginContext: IrPluginContext, ): IrExpression { // TODO check unit/void/nothing val defaultPrimitive: IrExpression? = @@ -227,7 +224,7 @@ internal fun IrClass.addOverride( name: String, returnType: IrType, modality: Modality = Modality.FINAL, - overloadFilter: (function: IrSimpleFunction) -> Boolean = { true } + overloadFilter: (function: IrSimpleFunction) -> Boolean = { true }, ): IrSimpleFunction = addFunction(name, returnType, modality).apply { overriddenSymbols = @@ -253,7 +250,7 @@ internal fun IrBuilderWithScope.irBinOp( pluginContext: IrPluginContext, name: Name, lhs: IrExpression, - rhs: IrExpression + rhs: IrExpression, ): IrExpression { val classFqName = (lhs.type as IrSimpleType).classOrNull!!.owner.fqNameWhenAvailable!! val symbol = @@ -265,7 +262,7 @@ internal fun IrBuilderWithScope.irInvoke( dispatchReceiver: IrExpression? = null, callee: IrFunctionSymbol, vararg args: IrExpression, - typeHint: IrType? = null + typeHint: IrType? = null, ): IrMemberAccessExpression<*> { assert(callee.isBound) { "Symbol $callee expected to be bound" } val returnType = typeHint ?: callee.owner.returnType @@ -281,7 +278,7 @@ internal val IrProperty.isTransient: Boolean internal fun IrBuilderWithScope.irAnd( pluginContext: IrPluginContext, lhs: IrExpression, - rhs: IrExpression + rhs: IrExpression, ): IrExpression = irBinOp(pluginContext, OperatorNameConventions.AND, lhs, rhs) internal fun Sequence.joinToIrAnd( diff --git a/moshi-ir/moshi-compiler-plugin/src/test/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitorTest.kt b/moshi-ir/moshi-compiler-plugin/src/test/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitorTest.kt index 73f8b1db..36e303f5 100644 --- a/moshi-ir/moshi-compiler-plugin/src/test/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitorTest.kt +++ b/moshi-ir/moshi-compiler-plugin/src/test/kotlin/dev/zacsweers/moshix/ir/compiler/MoshiIrVisitorTest.kt @@ -70,7 +70,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JvmInline @JsonClass(generateAdapter = true) value class ValueClass(val i: Int = 0) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -96,7 +96,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { fun newInstance(a: Int, b: Int) = PrivateConstructor(a, b) } } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -115,7 +115,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class PrivateConstructorParameter(private var a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -137,7 +137,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { private var a: Int = -1 private var b: Int = -1 } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -156,7 +156,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) interface Interface - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -176,7 +176,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true, generator="customGenerator") interface Interface - """ + """, ) ) assertThat(result.exitCode).isEqualTo(OK) @@ -194,7 +194,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) abstract class AbstractClass(val a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -214,7 +214,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) sealed class SealedClass(val a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -236,7 +236,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) inner class InnerClass(val a: Int) } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -258,7 +258,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { enum class KotlinEnum { A, B } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -284,7 +284,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class LocalClass(val a: Int) } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -304,7 +304,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) private class PrivateClass(val a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -326,7 +326,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { object ObjectDeclaration { var a = 5 } - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -346,7 +346,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class RequiredTransientConstructorParameter(@Transient var a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -366,7 +366,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class RequiredTransientConstructorParameter(@Json(ignore = true) var a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -385,7 +385,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class NonPropertyConstructorParameter(a: Int, val b: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -406,8 +406,8 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) data class Foo(val a: Int) - """ - ) + """, + ), ) .compile() assertThat(result.messages).contains("Invalid option value for TODO") @@ -428,7 +428,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class Class2(private var c: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -449,7 +449,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class ExtendsPlatformClass(var a: Int) : Date() - """ + """, ) ) assertThat(result.messages).contains("supertype java.util.Date is not a Kotlin type") @@ -468,7 +468,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class ExtendsJavaType(var b: Int) : JavaSuperclass() - """ + """, ), SourceFile.java( "JavaSuperclass.java", @@ -477,8 +477,8 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { public class JavaSuperclass { public int a = 1; } - """ - ) + """, + ), ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) assertThat(result.messages) @@ -507,7 +507,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ + """, ) ) // We instantiate directly, no FIELD site target necessary @@ -537,7 +537,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) class ClassWithQualifier(@UpperCase val a: Int) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) @@ -559,7 +559,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) data class Person(val firstName: FirstName, val lastName: LastName, val hairColor: String) - """ + """, ) ) assertThat(result.exitCode).isEqualTo(OK) @@ -691,8 +691,8 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { val arg64: Long = 64, val arg65: Long = 65 ) - """ - ) + """, + ), ) val result = compilation.compile() assertThat(result.exitCode).isEqualTo(OK) @@ -840,8 +840,8 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @JsonClass(generateAdapter = true) data class Example(val firstName: String) - """ - ) + """, + ), ) val result = compilation.compile() assertThat(result.exitCode).isEqualTo(OK) @@ -880,7 +880,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @TypeLabel("a") class TypeA : BaseType() } - """ + """, ) val result = compile(source) @@ -909,7 +909,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -949,7 +949,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -992,7 +992,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -1018,7 +1018,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { @TypeLabel("a") class TypeA : BaseType() } - """ + """, ) val result = compile(source) @@ -1029,7 +1029,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { private fun prepareCompilation( generatedAnnotation: String? = null, - vararg sourceFiles: SourceFile + vararg sourceFiles: SourceFile, ): KotlinCompilation { return KotlinCompilation().apply { workingDir = compilationDir @@ -1044,7 +1044,7 @@ class MoshiIrVisitorTest(private val useK2: Boolean) { if (generatedAnnotation != null) { processor.option( MoshiCommandLineProcessor.OPTION_GENERATED_ANNOTATION, - generatedAnnotation + generatedAnnotation, ) } } diff --git a/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt b/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt index 399b9e86..2bcae837 100644 --- a/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt +++ b/moshi-ir/moshi-gradle-plugin/src/main/kotlin/dev/zacsweers/moshix/ir/gradle/MoshiGradleSubplugin.kt @@ -21,11 +21,7 @@ import org.jetbrains.kotlin.gradle.plugin.SubpluginOption class MoshiGradleSubplugin : KotlinCompilerPluginSupportPlugin { private companion object { - val SUPPORTED_PLATFORMS = - setOf( - KotlinPlatformType.androidJvm, - KotlinPlatformType.jvm, - ) + val SUPPORTED_PLATFORMS = setOf(KotlinPlatformType.androidJvm, KotlinPlatformType.jvm) } override fun apply(target: Project) { @@ -44,7 +40,7 @@ class MoshiGradleSubplugin : KotlinCompilerPluginSupportPlugin { fun addKspDep(configurationName: String) { target.dependencies.add( configurationName, - "dev.zacsweers.moshix:moshi-proguard-rule-gen:$VERSION" + "dev.zacsweers.moshix:moshi-proguard-rule-gen:$VERSION", ) } @@ -79,7 +75,7 @@ class MoshiGradleSubplugin : KotlinCompilerPluginSupportPlugin { SubpluginArtifact( groupId = "dev.zacsweers.moshix", artifactId = "moshi-compiler-plugin", - version = VERSION + version = VERSION, ) override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true @@ -100,14 +96,14 @@ class MoshiGradleSubplugin : KotlinCompilerPluginSupportPlugin { // Minimum Moshi version project.dependencies.add( kotlinCompilation.implementationConfigurationName, - "com.squareup.moshi:moshi:1.13.0" + "com.squareup.moshi:moshi:1.13.0", ) val enableSealed = extension.enableSealed.get() if (enableSealed) { project.dependencies.add( kotlinCompilation.implementationConfigurationName, - "dev.zacsweers.moshix:moshi-sealed-runtime:$VERSION" + "dev.zacsweers.moshix:moshi-sealed-runtime:$VERSION", ) } diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt index 965e04d8..89bc0b93 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/DualKotlinTest.kt @@ -514,7 +514,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) @@ -528,7 +528,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 @@ -550,7 +550,7 @@ class DualKotlinTest { int = 3, long = 3, float = 3.2f, - double = 3.2 + double = 3.2, ) assertThat(adapter.toJson(instance)).isEqualTo(testJson) @@ -576,7 +576,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 @@ -617,7 +617,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 @@ -690,7 +690,7 @@ class DualKotlinTest { class MultipleTransientConstructorParameters( @Transient var a: Int = -1, var b: Int = -1, - @Transient var c: Int = -1 + @Transient var c: Int = -1, ) @Test @@ -754,7 +754,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 diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt index c9d31a30..46e0d8b5 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/CompileOnlyTests.kt @@ -53,7 +53,7 @@ data class TestModel(val someVariable: Int, val anotherVariable: String) @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) @@ -67,7 +67,7 @@ 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 @@ -104,7 +104,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 diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt index 10e06ef8..a455110b 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt @@ -81,7 +81,7 @@ class ComplexGenericsInheritanceTest { data = Person("layer4F") data2 = "layer4F" data3 = "layer4F" - } + }, ) .apply { layer3C = listOf(1, 2, 3) diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt index 00854eb0..8e2f4cb4 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/DefaultConstructorTest.kt @@ -55,7 +55,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-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt index ff67e079..ff2acc0e 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/GeneratedAdaptersTest.kt @@ -142,7 +142,7 @@ class GeneratedAdaptersTest { val foo: String, val bar: String = "", val nullableBar: String? = null, - val bazList: List = emptyList() + val bazList: List = emptyList(), ) @Test @@ -204,7 +204,7 @@ class GeneratedAdaptersTest { mutableMapOf(), emptyList(), emptySet(), - emptyMap() + emptyMap(), ) val json = adapter.toJson(specialCollections) @@ -219,7 +219,7 @@ class GeneratedAdaptersTest { val mutableMap: MutableMap, val immutableList: List, val immutableSet: Set, - val immutableMap: Map + val immutableMap: Map, ) @Test @@ -239,7 +239,7 @@ class GeneratedAdaptersTest { mutableListOf("immutableMutableList"), mutableListOf("immutableImmutableList"), mutableListOf("mutableMutableList"), - mutableListOf("mutableImmutableList") + mutableListOf("mutableImmutableList"), ) val json = adapter.toJson(mutableProperties) @@ -260,7 +260,7 @@ class GeneratedAdaptersTest { val nullableImmutableMutableList: MutableList?, val nullableImmutableImmutableList: List?, var nullableMutableMutableList: MutableList?, - var nullableMutableImmutableList: List + var nullableMutableImmutableList: List, ) @Test @@ -274,7 +274,7 @@ class GeneratedAdaptersTest { setOf("foo", null, "bar"), mapOf("foo" to "bar", "baz" to null), null, - 1 + 1, ) val noNullsTypeParams = @@ -283,7 +283,7 @@ class GeneratedAdaptersTest { nullableTypeParams.nullableSet, nullableTypeParams.nullableMap.filterValues { it != null }, null, - 1 + 1, ) val json = adapter.toJson(nullableTypeParams) @@ -301,7 +301,7 @@ class GeneratedAdaptersTest { val nullableSet: Set, val nullableMap: Map, val nullableT: T?, - val nonNullT: T + val nonNullT: T, ) @Test @@ -576,7 +576,7 @@ class GeneratedAdaptersTest { class MultipleTransientConstructorParameters( @Transient var a: Int = -1, var b: Int = -1, - @Transient var c: Int = -1 + @Transient var c: Int = -1, ) @Test @@ -680,7 +680,7 @@ class GeneratedAdaptersTest { 129, 130, 131, - 132 + 132, ) val json = (""" @@ -737,7 +737,7 @@ class GeneratedAdaptersTest { var v29: Int, var v30: Int, var v31: Int, - var v32: Int + var v32: Int, ) @Test @@ -779,7 +779,7 @@ class GeneratedAdaptersTest { 130, 131, 132, - 133 + 133, ) val json = (""" @@ -838,7 +838,7 @@ class GeneratedAdaptersTest { var v30: Int, var v31: Int, var v32: Int, - var v33: Int + var v33: Int, ) @Test @@ -1033,7 +1033,7 @@ class GeneratedAdaptersTest { @JsonClass(generateAdapter = true) class MultiplePropertiesShareAdapter( @Uppercase(true) var a: String, - @Uppercase(true) var b: String + @Uppercase(true) var b: String, ) @Test @@ -1415,7 +1415,7 @@ class GeneratedAdaptersTest { String, String, String, - String + String, ) -> Boolean)? = null, ) @@ -1428,5 +1428,5 @@ data class NullableTypeParams( val nullableSet: Set, val nullableMap: Map, val nullableT: T?, - val nonNullT: T + val nonNullT: T, ) diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt index 97e55c25..c451b59c 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MultipleMasksTest.kt @@ -120,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-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/MessageTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/MessageTest.kt index 82ccd28c..a1c8efe0 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/MessageTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/MessageTest.kt @@ -41,7 +41,7 @@ class MessageTest { adapter, Message.Success("Okay!"), Message.Error(mapOf("order" to 66.0)), - Message.Unknown + Message.Unknown, ) } @@ -52,7 +52,7 @@ class MessageTest { adapter, MessageWithNullDefault.Success("Okay!"), MessageWithNullDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -63,7 +63,7 @@ class MessageTest { adapter, MessageWithNoDefault.Success("Okay!"), MessageWithNoDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -71,7 +71,7 @@ class MessageTest { adapter: JsonAdapter, success: T, error: T, - defaultInstance: T? + defaultInstance: T?, ) { assertThat(adapter.fromJson("{\"type\":\"success\",\"value\":\"Okay!\"}")).isEqualTo(success) // Test alternates diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/ObjectSerializationTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/ObjectSerializationTest.kt index d0f84711..22a4fd42 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/ObjectSerializationTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/ObjectSerializationTest.kt @@ -46,7 +46,7 @@ class ObjectSerializationTest { FunctionSpec( name = "tacoFactory", returnType = Type.VoidType, - parameters = mapOf("param1" to Type.IntType, "param2" to Type.BooleanType) + parameters = mapOf("param1" to Type.IntType, "param2" to Type.BooleanType), ) ) } diff --git a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/SealedInterfaceMessageTest.kt b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/SealedInterfaceMessageTest.kt index fc692153..56b050f7 100644 --- a/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/SealedInterfaceMessageTest.kt +++ b/moshi-ir/moshi-kotlin-tests/src/test/kotlin/dev/zacsweers/moshi/sealed/SealedInterfaceMessageTest.kt @@ -35,7 +35,7 @@ class SealedInterfaceMessageTest { adapter, SealedInterfaceMessage.Success("Okay!"), SealedInterfaceMessage.Error(mapOf("order" to 66.0)), - SealedInterfaceMessage.Unknown + SealedInterfaceMessage.Unknown, ) } @@ -46,7 +46,7 @@ class SealedInterfaceMessageTest { adapter, MessageWithNullDefault.Success("Okay!"), MessageWithNullDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -57,7 +57,7 @@ class SealedInterfaceMessageTest { adapter, MessageWithNoDefault.Success("Okay!"), MessageWithNoDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -65,7 +65,7 @@ class SealedInterfaceMessageTest { adapter: JsonAdapter, success: T, error: T, - defaultInstance: T? + defaultInstance: T?, ) { assertThat(adapter.fromJson("{\"type\":\"success\",\"value\":\"Okay!\"}")).isEqualTo(success) // Test alternates diff --git a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptors.kt b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptors.kt index 069d31aa..22a1d3df 100644 --- a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptors.kt +++ b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptors.kt @@ -28,7 +28,7 @@ private val PRIMITIVE_CLASS_TO_DESC = Long::class.javaPrimitiveType to 'J', Short::class.javaPrimitiveType to 'S', Boolean::class.javaPrimitiveType to 'Z', - Void::class.javaPrimitiveType to 'V' + Void::class.javaPrimitiveType to 'V', ) @Suppress("RecursivePropertyAccessor") diff --git a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/KtTypes.kt b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/KtTypes.kt index d7874787..474f46ba 100644 --- a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/KtTypes.kt +++ b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/KtTypes.kt @@ -93,7 +93,7 @@ internal data class KtParameter( val km: KmValueParameter, val index: Int, val rawType: Class<*>, - val annotations: List + val annotations: List, ) { val name get() = km.name @@ -110,7 +110,7 @@ internal data class KtConstructor( val km: KmConstructor, val jvm: Constructor<*>, val parameters: List, - val isDefault: Boolean + val isDefault: Boolean, ) { init { jvm.isAccessible = true @@ -204,7 +204,7 @@ internal data class KtProperty( val jvmGetter: Method?, val jvmSetter: Method?, val jvmAnnotationsMethod: Method?, - val parameter: KtParameter? + val parameter: KtParameter?, ) { init { jvmField?.isAccessible = true diff --git a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/MetadataKotlinJsonAdapterFactory.kt b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/MetadataKotlinJsonAdapterFactory.kt index 7e2a87ea..99965a08 100644 --- a/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/MetadataKotlinJsonAdapterFactory.kt +++ b/moshi-metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/reflect/MetadataKotlinJsonAdapterFactory.kt @@ -69,7 +69,7 @@ internal class KotlinJsonAdapter( private val constructor: KtConstructor, private val allBindings: List?>, private val nonIgnoredBindings: List>, - private val options: JsonReader.Options + private val options: JsonReader.Options, ) : JsonAdapter() { override fun fromJson(reader: JsonReader): T { @@ -109,7 +109,7 @@ internal class KotlinJsonAdapter( throw Util.missingProperty( constructor.parameters[i].name, allBindings[i]?.jsonName, - reader + reader, ) } values[i] = null // Replace absent with null. @@ -150,7 +150,7 @@ internal class KotlinJsonAdapter( val jsonName: String?, val adapter: JsonAdapter

, val property: KtProperty, - val propertyIndex: Int = property.parameter?.index ?: -1 + val propertyIndex: Int = property.parameter?.index ?: -1, ) { fun get(value: K): Any? { @@ -178,7 +178,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: KtParameter, value: Any?): Any? = null @@ -282,7 +282,7 @@ public class MetadataKotlinJsonAdapterFactory : JsonAdapter.Factory { jvmGetter = getterMethod, jvmSetter = setterMethod, jvmAnnotationsMethod = annotationsMethod, - parameter = ktParameter + parameter = ktParameter, ) val allAnnotations = ktProperty.annotations.toMutableList() val jsonAnnotation = allAnnotations.filterIsInstance().firstOrNull() @@ -305,7 +305,7 @@ public class MetadataKotlinJsonAdapterFactory : JsonAdapter.Factory { moshi.adapter( resolvedPropertyType, Util.jsonAnnotations(allAnnotations.toTypedArray()), - property.name + property.name, ) bindingsByName[property.name] = @@ -341,7 +341,7 @@ public class MetadataKotlinJsonAdapterFactory : JsonAdapter.Factory { @Suppress("DEPRECATION") arguments valueEquals other.arguments && classifier == other.classifier && - flags == other.flags && + isNullable == other.isNullable && flexibleTypeUpperBound valueEquals other.flexibleTypeUpperBound && outerType valueEquals other.outerType } @@ -399,13 +399,13 @@ private fun Class<*>.header(): Metadata? { data2 = data2, extraString = extraString, packageName = packageName, - extraInt = extraInt + extraInt = extraInt, ) } } private fun Metadata.toKmClass(): KmClass? { - val classMetadata = KotlinClassMetadata.read(this) + val classMetadata = KotlinClassMetadata.readLenient(this) if (classMetadata !is KotlinClassMetadata.Class) { return null } diff --git a/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptorsTest.kt b/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptorsTest.kt index d1107844..38f12d87 100644 --- a/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptorsTest.kt +++ b/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/JvmDescriptorsTest.kt @@ -37,7 +37,7 @@ class JvmDescriptorsTest { Long::class.javaPrimitiveType, Short::class.javaPrimitiveType, Boolean::class.javaPrimitiveType, - Void::class.javaPrimitiveType + Void::class.javaPrimitiveType, ) .inOrder() } diff --git a/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/KotlinJsonAdapterTest.kt b/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/KotlinJsonAdapterTest.kt index 46df9a55..9b823534 100644 --- a/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/KotlinJsonAdapterTest.kt +++ b/moshi-metadata-reflect/src/test/kotlin/dev/zacsweers/moshix/reflect/KotlinJsonAdapterTest.kt @@ -327,7 +327,7 @@ class KotlinJsonAdapterTest { class MultipleTransientConstructorParameters( @Transient var a: Int = -1, var b: Int = -1, - @Transient var c: Int = -1 + @Transient var c: Int = -1, ) @Test @@ -828,7 +828,7 @@ class KotlinJsonAdapterTest { 129, 130, 131, - 132 + 132, ) val json = (""" @@ -884,7 +884,7 @@ class KotlinJsonAdapterTest { var v29: Int, var v30: Int, var v31: Int, - var v32: Int + var v32: Int, ) @Test @@ -926,7 +926,7 @@ class KotlinJsonAdapterTest { 130, 131, 132, - 133 + 133, ) val json = (""" @@ -984,7 +984,7 @@ class KotlinJsonAdapterTest { var v30: Int, var v31: Int, var v32: Int, - var v33: Int + var v33: Int, ) data class Box(val data: T) @@ -997,7 +997,7 @@ class KotlinJsonAdapterTest { Types.newParameterizedTypeWithOwner( KotlinJsonAdapterTest::class.java, Box::class.java, - String::class.java + String::class.java, ) ) assertThat(stringBoxAdapter.fromJson("""{"data":"hello"}""")).isEqualTo(Box("hello")) @@ -1018,8 +1018,8 @@ class KotlinJsonAdapterTest { Types.newParameterizedTypeWithOwner( KotlinJsonAdapterTest::class.java, Box::class.java, - String::class.java - ) + String::class.java, + ), ) val adapter = moshi.adapter>>(type).indent(" ") val json = @@ -1142,7 +1142,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToStandardReflection::class.java, """{"map":{"key":"value"}}""", - MapOfStringToStandardReflection(mapOf("key" to "value")) + MapOfStringToStandardReflection(mapOf("key" to "value")), ) } @@ -1154,7 +1154,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToStandardCodegen::class.java, """{"map":{"key":"value"}}""", - MapOfStringToStandardCodegen(mapOf("key" to "value")) + MapOfStringToStandardCodegen(mapOf("key" to "value")), ) } @@ -1167,7 +1167,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToEnumReflection::class.java, """{"map":{"key":"A"}}""", - MapOfStringToEnumReflection(mapOf("key" to KotlinEnum.A)) + MapOfStringToEnumReflection(mapOf("key" to KotlinEnum.A)), ) } @@ -1179,7 +1179,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToEnumCodegen::class.java, """{"map":{"key":"A"}}""", - MapOfStringToEnumCodegen(mapOf("key" to KotlinEnum.A)) + MapOfStringToEnumCodegen(mapOf("key" to KotlinEnum.A)), ) } @@ -1192,7 +1192,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToCollectionReflection::class.java, """{"map":{"key":[]}}""", - MapOfStringToCollectionReflection(mapOf("key" to listOf())) + MapOfStringToCollectionReflection(mapOf("key" to listOf())), ) } @@ -1204,7 +1204,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToCollectionCodegen::class.java, """{"map":{"key":[]}}""", - MapOfStringToCollectionCodegen(mapOf("key" to listOf())) + MapOfStringToCollectionCodegen(mapOf("key" to listOf())), ) } @@ -1217,7 +1217,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToMapReflection::class.java, """{"map":{"key":{}}}""", - MapOfStringToMapReflection(mapOf("key" to mapOf())) + MapOfStringToMapReflection(mapOf("key" to mapOf())), ) } @@ -1229,7 +1229,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToMapCodegen::class.java, """{"map":{"key":{}}}""", - MapOfStringToMapCodegen(mapOf("key" to mapOf())) + MapOfStringToMapCodegen(mapOf("key" to mapOf())), ) } @@ -1242,7 +1242,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToArrayReflection::class.java, """{"map":{"key":[]}}""", - MapOfStringToArrayReflection(mapOf("key" to arrayOf())) + MapOfStringToArrayReflection(mapOf("key" to arrayOf())), ) } @@ -1254,7 +1254,7 @@ class KotlinJsonAdapterTest { mapWildcardsParameterizedTest( MapOfStringToArrayCodegen::class.java, """{"map":{"key":[]}}""", - MapOfStringToArrayCodegen(mapOf("key" to arrayOf())) + MapOfStringToArrayCodegen(mapOf("key" to arrayOf())), ) } @@ -1267,7 +1267,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))), ) } @@ -1279,7 +1279,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-proguard-rule-gen/build.gradle.kts b/moshi-proguard-rule-gen/build.gradle.kts index 88cf5261..4eef2fca 100644 --- a/moshi-proguard-rule-gen/build.gradle.kts +++ b/moshi-proguard-rule-gen/build.gradle.kts @@ -24,9 +24,7 @@ plugins { tasks.withType().configureEach { compilerOptions { - freeCompilerArgs.addAll( - "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi", - ) + freeCompilerArgs.addAll("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") } } diff --git a/moshi-proguard-rule-gen/src/main/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessor.kt b/moshi-proguard-rule-gen/src/main/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessor.kt index 1678fbb9..2b39366e 100644 --- a/moshi-proguard-rule-gen/src/main/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessor.kt +++ b/moshi-proguard-rule-gen/src/main/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessor.kt @@ -19,9 +19,8 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi import com.squareup.moshi.kotlin.codegen.api.ProguardConfig -public class MoshiProguardGenSymbolProcessor( - private val environment: SymbolProcessorEnvironment, -) : SymbolProcessor { +public class MoshiProguardGenSymbolProcessor(private val environment: SymbolProcessorEnvironment) : + SymbolProcessor { internal companion object { @@ -97,18 +96,18 @@ public class MoshiProguardGenSymbolProcessor( adapterConstructorParams = adapterConstructorParams, // Not actually true but in our case we don't need the generated rules for htis targetConstructorHasDefaults = false, - targetConstructorParams = emptyList() + targetConstructorParams = emptyList(), ) environment.logger.info( "MOSHI: Writing proguard rules for ${targetType.canonicalName}: $config", - clazz + clazz, ) val fileName = config.outputFilePathWithoutExtension(targetType.canonicalName) environment.codeGenerator .createNewFile( Dependencies( false, - sources = clazz.containingFile?.let { arrayOf(it) } ?: emptyArray() + sources = clazz.containingFile?.let { arrayOf(it) } ?: emptyArray(), ), packageName = "", fileName = fileName, @@ -146,7 +145,7 @@ public class MoshiProguardGenSymbolProcessor( private fun KSClassDeclaration.walkSealedSubtypes( elements: MutableSet, - skipAnnotationCheck: Boolean + skipAnnotationCheck: Boolean, ) { if (isSealed) { if (!skipAnnotationCheck) { diff --git a/moshi-proguard-rule-gen/src/test/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessorTest.kt b/moshi-proguard-rule-gen/src/test/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessorTest.kt index 8f4106ef..e7f9091f 100644 --- a/moshi-proguard-rule-gen/src/test/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessorTest.kt +++ b/moshi-proguard-rule-gen/src/test/kotlin/dev/zacsweers/moshix/proguardgen/MoshiProguardGenSymbolProcessorTest.kt @@ -53,7 +53,7 @@ class MoshiSealedSymbolProcessorProviderTest { class TypeCImpl : TypeC() } } - """ + """, ) val compilation = prepareCompilation(source) @@ -99,7 +99,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("b") class TypeB : BaseType() } - """ + """, ) val compilation = @@ -132,7 +132,7 @@ class MoshiSealedSymbolProcessorProviderTest { class TypeCImpl : TypeC() } } - """ + """, ) val compilation = diff --git a/moshi-sealed/codegen/build.gradle.kts b/moshi-sealed/codegen/build.gradle.kts index 4cbcb3a1..ff4be18f 100644 --- a/moshi-sealed/codegen/build.gradle.kts +++ b/moshi-sealed/codegen/build.gradle.kts @@ -34,15 +34,13 @@ 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", ) } tasks.withType().configureEach { compilerOptions { - freeCompilerArgs.addAll( - "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi", - ) + freeCompilerArgs.addAll("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") } } diff --git a/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorProvider.kt b/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorProvider.kt index 1e1615f6..89a0d5a0 100644 --- a/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorProvider.kt +++ b/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorProvider.kt @@ -94,7 +94,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment // like for stylistic reasons. "LocalVariableName", // KotlinPoet always generates explicit public modifiers for public members. - "RedundantVisibilityModifier" + "RedundantVisibilityModifier", ) .let { suppressions -> AnnotationSpec.builder(Suppress::class) @@ -158,7 +158,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment logger.error( "@NestedSealed-annotated subtype $type is inappropriately annotated with @JsonClass(generator = " + "\"sealed:$labelKey\").", - type + type, ) return@forEach } @@ -205,7 +205,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment if (constructor?.isVisibleFrom(type) == false) { logger.error( "Fallback adapter type $adapterType and its primary constructor must be visible from $type", - fallbackAdapterAnnotation + fallbackAdapterAnnotation, ) return } @@ -223,7 +223,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment if (!symbols.moshi.isAssignableFrom(moshiParam.type.resolve())) { logger.error( "Fallback adapter type's primary constructor can only have a Moshi parameter", - fallbackAdapterAnnotation + fallbackAdapterAnnotation, ) return } @@ -232,7 +232,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment else -> { logger.error( "Fallback adapter type's primary constructor can only have a Moshi parameter", - fallbackAdapterAnnotation + fallbackAdapterAnnotation, ) return } @@ -240,7 +240,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment fallbackStrategy = FallbackStrategy.FallbackAdapter( className = adapterType.toClassName(), - hasMoshiParam = hasMoshiParam + hasMoshiParam = hasMoshiParam, ) } else if (useDefaultNull) { fallbackStrategy = FallbackStrategy.Null @@ -263,7 +263,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment Cannot have both @DefaultNull and @DefaultObject. @DefaultNull type: $subtype """ .trimIndent(), - subtype + subtype, ) return } else { @@ -278,7 +278,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment seenLabels = seenLabels, objectAdapters = objectAdapters, originatingKSFiles = originatingKSFiles, - className = className + className = className, ) } } @@ -291,7 +291,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment generatedAnnotation = generatedAnnotation, subtypes = sealedSubtypes, objectAdapters = objectAdapters, - errorLogger = { message -> logger.error(message, type) } + errorLogger = { message -> logger.error(message, type) }, ) { addAnnotation(COMMON_SUPPRESS) for (file in originatingKSFiles) { @@ -337,7 +337,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment seenLabels, objectAdapters, className, - skipJsonClassCheck = true + skipJsonClassCheck = true, ) return classType?.let { sequenceOf(it) } ?: emptySequence() } else { @@ -365,7 +365,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment symbols = symbols, seenLabels = seenLabels, objectAdapters = objectAdapters, - className = className + className = className, ) return classType?.let { sequenceOf(it) } ?: emptySequence() } @@ -378,7 +378,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment seenLabels: MutableMap, objectAdapters: MutableList, className: ClassName = subtype.toClassName(), - skipJsonClassCheck: Boolean = false + skipJsonClassCheck: Boolean = false, ): Subtype? { // Regular subtype, read its label val labelAnnotation = @@ -420,7 +420,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment seenLabels.put(alternate, className)?.let { prev -> logger.error( "Duplicate alternate label '$alternate' defined for $className and $prev.", - rootType + rootType, ) return null } @@ -431,7 +431,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment if (labelKey != null) { logger.error( "Sealed subtype $subtype is annotated with @JsonClass(generator = \"sealed:$labelKey\") and @TypeLabel.", - subtype + subtype, ) return null } @@ -444,7 +444,7 @@ private class MoshiSealedSymbolProcessor(environment: SymbolProcessorEnvironment CodeBlock.of( ".add(%1T::class.java,ยท%2T(%1T))", className, - ObjectJsonAdapter::class.asClassName() + ObjectJsonAdapter::class.asClassName(), ) ) } @@ -474,7 +474,7 @@ internal sealed interface FallbackStrategy { className, constructorParams, JsonAdapter::class.asClassName(), - ANY + ANY, ) } } diff --git a/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/TypeCreation.kt b/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/TypeCreation.kt index c31ac199..48f1e347 100644 --- a/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/TypeCreation.kt +++ b/moshi-sealed/codegen/src/main/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/TypeCreation.kt @@ -54,7 +54,7 @@ internal fun createType( subtypes: Set, objectAdapters: List, errorLogger: (String) -> Unit, - typeSpecHook: TypeSpec.Builder.() -> Unit + typeSpecHook: TypeSpec.Builder.() -> Unit, ): FileSpec? { var finalFallbackStrategy = fallbackStrategy val adapterName = @@ -96,7 +96,7 @@ internal fun createType( "%T.of(%T::class.java, %S)\n", PolymorphicJsonAdapterFactory::class, targetType, - labelKey + labelKey, ) for (subtype in subtypes) { @@ -116,7 +116,7 @@ internal fun createType( runtimeAdapterInitializer.add( " .withSubtype(%T::class.java, %S)\n", subtype.className, - label + label, ) } } @@ -129,7 +129,7 @@ internal fun createType( targetType, MemberName("kotlin.collections", "emptySet"), moshiArg, - jsonAdapterType + jsonAdapterType, ) val runtimeAdapterProperty = diff --git a/moshi-sealed/codegen/src/test/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorTest.kt b/moshi-sealed/codegen/src/test/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorTest.kt index 9f888ed3..87ad27f4 100644 --- a/moshi-sealed/codegen/src/test/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorTest.kt +++ b/moshi-sealed/codegen/src/test/kotlin/dev/zacsweers/moshix/sealed/codegen/ksp/MoshiSealedSymbolProcessorTest.kt @@ -51,7 +51,7 @@ class MoshiSealedSymbolProcessorProviderTest { class TypeCImpl : TypeC() } } - """ + """, ) val compilation = prepareCompilation(source) @@ -117,7 +117,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("a") class TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -142,7 +142,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("b", alternateLabels = ["aa"]) class TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -167,7 +167,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("b") class TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -206,7 +206,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("a") class TypeA : BaseType() } - """ + """, ) val result = compile(source) @@ -235,7 +235,7 @@ class MoshiSealedSymbolProcessorProviderTest { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -275,7 +275,7 @@ class MoshiSealedSymbolProcessorProviderTest { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -318,7 +318,7 @@ class MoshiSealedSymbolProcessorProviderTest { @DefaultObject object TypeB : BaseType() } - """ + """, ) val result = compile(source) @@ -347,7 +347,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("a") class TypeA : BaseType() } - """ + """, ) val result = compile(source) @@ -373,7 +373,7 @@ class MoshiSealedSymbolProcessorProviderTest { @TypeLabel("b") object TypeB : BaseType() } - """ + """, ) val compilation = prepareCompilation(source) @@ -443,7 +443,7 @@ class MoshiSealedSymbolProcessorProviderTest { @JsonClass(generateAdapter = true, generator = "sealed:type") sealed interface BaseType - """ + """, ) val subType = @@ -457,7 +457,7 @@ class MoshiSealedSymbolProcessorProviderTest { @JsonClass(generateAdapter = true) @TypeLabel("a") - data class SubType(val foo: String): BaseType""" + data class SubType(val foo: String): BaseType""", ) val compilation = prepareCompilation(base, subType) @@ -505,18 +505,14 @@ class MoshiSealedSymbolProcessorProviderTest { ) } - private fun prepareCompilation( - vararg sourceFiles: SourceFile, - ): KotlinCompilation = + private fun prepareCompilation(vararg sourceFiles: SourceFile): KotlinCompilation = KotlinCompilation().apply { sources = sourceFiles.toList() inheritClassPath = true symbolProcessorProviders = listOf(MoshiSealedSymbolProcessorProvider()) } - private fun compile( - vararg sourceFiles: SourceFile, - ): CompilationResult { + private fun compile(vararg sourceFiles: SourceFile): CompilationResult { return prepareCompilation(*sourceFiles).compile() } } diff --git a/moshi-sealed/metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MetadataMoshiSealedJsonAdapterFactory.kt b/moshi-sealed/metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MetadataMoshiSealedJsonAdapterFactory.kt index d75231e9..4664f2a0 100644 --- a/moshi-sealed/metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MetadataMoshiSealedJsonAdapterFactory.kt +++ b/moshi-sealed/metadata-reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MetadataMoshiSealedJsonAdapterFactory.kt @@ -165,13 +165,13 @@ private fun Class<*>.header(): Metadata? { data2 = data2, extraString = extraString, packageName = packageName, - extraInt = extraInt + extraInt = extraInt, ) } } private fun Metadata.toKmClass(): KmClass? { - val classMetadata = KotlinClassMetadata.read(this) + val classMetadata = KotlinClassMetadata.readLenient(this) if (classMetadata !is KotlinClassMetadata.Class) { return null } @@ -232,7 +232,7 @@ private fun walkTypeLabels( subtypeKmClass, labels, objectSubtypes, - skipJsonClassCheck = subtypeKmClass.kind == ClassKind.OBJECT + skipJsonClassCheck = subtypeKmClass.kind == ClassKind.OBJECT, ) } } @@ -242,7 +242,7 @@ private fun addLabelKeyForType( subtypeKmClass: KmClass, labels: MutableMap>, objectSubtypes: MutableMap, Any>, - skipJsonClassCheck: Boolean = false + skipJsonClassCheck: Boolean = false, ) { // Regular subtype, read its label val labelAnnotation = diff --git a/moshi-sealed/reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MoshiSealedJsonAdapterFactory.kt b/moshi-sealed/reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MoshiSealedJsonAdapterFactory.kt index 716930b9..e0c11794 100644 --- a/moshi-sealed/reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MoshiSealedJsonAdapterFactory.kt +++ b/moshi-sealed/reflect/src/main/kotlin/dev/zacsweers/moshix/sealed/reflect/MoshiSealedJsonAdapterFactory.kt @@ -193,7 +193,7 @@ private fun walkTypeLabels( subtype, labels, objectSubtypes, - skipJsonClassCheck = subtype.objectInstance != null + skipJsonClassCheck = subtype.objectInstance != null, ) } } @@ -202,7 +202,7 @@ private fun addLabelKeyForType( subtype: KClass<*>, labels: MutableMap>, objectSubtypes: MutableMap, Any>, - skipJsonClassCheck: Boolean = false + skipJsonClassCheck: Boolean = false, ) { // Regular subtype, read its label val subtypeClazz = subtype.java diff --git a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/MessageTest.kt b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/MessageTest.kt index 452ace20..dc56fe09 100644 --- a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/MessageTest.kt +++ b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/MessageTest.kt @@ -82,7 +82,7 @@ class MessageTest(type: Type) { adapter, Message.Success("Okay!"), Message.Error(mapOf("order" to 66.0)), - Message.Unknown + Message.Unknown, ) } @@ -93,7 +93,7 @@ class MessageTest(type: Type) { adapter, MessageWithNullDefault.Success("Okay!"), MessageWithNullDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -144,7 +144,7 @@ class MessageTest(type: Type) { adapter, MessageWithNoDefault.Success("Okay!"), MessageWithNoDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -152,7 +152,7 @@ class MessageTest(type: Type) { adapter: JsonAdapter, success: T, error: T, - defaultInstance: T? + defaultInstance: T?, ) { assertThat(adapter.fromJson("{\"type\":\"success\",\"value\":\"Okay!\"}")).isEqualTo(success) // Test alternates diff --git a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/ObjectSerializationTest.kt b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/ObjectSerializationTest.kt index fbd25946..992c9f0c 100644 --- a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/ObjectSerializationTest.kt +++ b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/ObjectSerializationTest.kt @@ -84,7 +84,7 @@ class ObjectSerializationTest(type: Type) { FunctionSpec( name = "tacoFactory", returnType = VoidType, - parameters = mapOf("param1" to IntType, "param2" to BooleanType) + parameters = mapOf("param1" to IntType, "param2" to BooleanType), ) ) } diff --git a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/SealedInterfaceMessageTest.kt b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/SealedInterfaceMessageTest.kt index 6bac3758..1338df02 100644 --- a/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/SealedInterfaceMessageTest.kt +++ b/moshi-sealed/sample/src/test/kotlin/dev/zacsweers/moshix/sealed/sample/test/SealedInterfaceMessageTest.kt @@ -70,7 +70,7 @@ class SealedInterfaceMessageTest(type: Type) { adapter, SealedInterfaceMessage.Success("Okay!"), SealedInterfaceMessage.Error(mapOf("order" to 66.0)), - SealedInterfaceMessage.Unknown + SealedInterfaceMessage.Unknown, ) } @@ -81,7 +81,7 @@ class SealedInterfaceMessageTest(type: Type) { adapter, MessageWithNullDefault.Success("Okay!"), MessageWithNullDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -92,7 +92,7 @@ class SealedInterfaceMessageTest(type: Type) { adapter, MessageWithNoDefault.Success("Okay!"), MessageWithNoDefault.Error(mapOf("order" to 66.0)), - null + null, ) } @@ -100,7 +100,7 @@ class SealedInterfaceMessageTest(type: Type) { adapter: JsonAdapter, success: T, error: T, - defaultInstance: T? + defaultInstance: T?, ) { assertThat(adapter.fromJson("{\"type\":\"success\",\"value\":\"Okay!\"}")).isEqualTo(success) // Test alternates