diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f0b9bde6..5442ba34 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ jdk = "22" jvmTarget = "11" kotlin = "2.1.0" kotlinCompileTesting = "0.7.0" -kotlinpoet = "1.18.1" +kotlinpoet = "2.0.0" ksp = "2.1.0-1.0.29" ktfmt = "0.53" moshi = "1.15.1" 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 f9e77b40..22a12b51 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 @@ -76,39 +76,37 @@ class MoshiSealedSymbolProcessorProviderTest(private val useKSP2: Boolean) { assertThat(generatedAdapter.readText().trim()) .isEqualTo( """ - // Code generated by moshi-sealed. Do not edit. - package test + // Code generated by moshi-sealed. Do not edit. + package test - import com.squareup.moshi.JsonAdapter - import com.squareup.moshi.JsonReader - import com.squareup.moshi.JsonWriter - import com.squareup.moshi.Moshi - import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory - import kotlin.Suppress - import kotlin.collections.emptySet - - @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", - "LocalVariableName", "RedundantVisibilityModifier") - public class BaseTypeJsonAdapter( - moshi: Moshi, - ) : JsonAdapter() { - @Suppress("UNCHECKED_CAST") - private val runtimeAdapter: JsonAdapter = - PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") - .withSubtype(BaseType.TypeA::class.java, "a") - .withSubtype(BaseType.TypeA::class.java, "aa") - .withSubtype(BaseType.TypeB::class.java, "b") - .withSubtype(BaseType.TypeC.TypeCImpl::class.java, "c") - .create(BaseType::class.java, emptySet(), moshi) as JsonAdapter - - override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) - - override fun toJson(writer: JsonWriter, value_: BaseType?) { - runtimeAdapter.toJson(writer, value_) + import com.squareup.moshi.JsonAdapter + import com.squareup.moshi.JsonReader + import com.squareup.moshi.JsonWriter + import com.squareup.moshi.Moshi + import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory + import kotlin.Suppress + import kotlin.collections.emptySet + + @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier") + public class BaseTypeJsonAdapter( + moshi: Moshi, + ) : JsonAdapter() { + @Suppress("UNCHECKED_CAST") + private val runtimeAdapter: JsonAdapter = + PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") + .withSubtype(BaseType.TypeA::class.java, "a") + .withSubtype(BaseType.TypeA::class.java, "aa") + .withSubtype(BaseType.TypeB::class.java, "b") + .withSubtype(BaseType.TypeC.TypeCImpl::class.java, "c") + .create(BaseType::class.java, emptySet(), moshi) as JsonAdapter + + override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) + + override fun toJson(writer: JsonWriter, value_: BaseType?) { + runtimeAdapter.toJson(writer, value_) + } } - } - """ - .trimIndent() + """.trimIndent() ) } @@ -398,48 +396,46 @@ class MoshiSealedSymbolProcessorProviderTest(private val useKSP2: Boolean) { assertThat(generatedFile.readText().trim()) .isEqualTo( """ - // Code generated by moshi-sealed. Do not edit. - package test - - import com.squareup.moshi.JsonAdapter - import com.squareup.moshi.JsonReader - import com.squareup.moshi.JsonWriter - import com.squareup.moshi.Moshi - import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory - import dev.zacsweers.moshix.`sealed`.runtime.`internal`.ObjectJsonAdapter - import kotlin.ExperimentalStdlibApi - import kotlin.OptIn - import kotlin.Suppress - import kotlin.collections.emptySet - - @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", - "LocalVariableName", "RedundantVisibilityModifier") - public class BaseTypeJsonAdapter( - moshi: Moshi, - ) : JsonAdapter() { - private val runtimeAdapter: JsonAdapter - - init { - val moshi_ = moshi.newBuilder() - .add(BaseType.TypeA::class.java, ObjectJsonAdapter(BaseType.TypeA)) - .add(BaseType.TypeB::class.java, ObjectJsonAdapter(BaseType.TypeB)) - .build() - @Suppress("UNCHECKED_CAST") - @OptIn(ExperimentalStdlibApi::class) - runtimeAdapter = PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") - .withSubtype(BaseType.TypeA::class.java, "a") - .withSubtype(BaseType.TypeB::class.java, "b") - .create(BaseType::class.java, emptySet(), moshi_) as JsonAdapter - } - - override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) + // Code generated by moshi-sealed. Do not edit. + package test - override fun toJson(writer: JsonWriter, value_: BaseType?) { - runtimeAdapter.toJson(writer, value_) + import com.squareup.moshi.JsonAdapter + import com.squareup.moshi.JsonReader + import com.squareup.moshi.JsonWriter + import com.squareup.moshi.Moshi + import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory + import dev.zacsweers.moshix.`sealed`.runtime.`internal`.ObjectJsonAdapter + import kotlin.ExperimentalStdlibApi + import kotlin.OptIn + import kotlin.Suppress + import kotlin.collections.emptySet + + @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier") + public class BaseTypeJsonAdapter( + moshi: Moshi, + ) : JsonAdapter() { + private val runtimeAdapter: JsonAdapter + + init { + val moshi_ = moshi.newBuilder() + .add(BaseType.TypeA::class.java, ObjectJsonAdapter(BaseType.TypeA)) + .add(BaseType.TypeB::class.java, ObjectJsonAdapter(BaseType.TypeB)) + .build() + @Suppress("UNCHECKED_CAST") + @OptIn(ExperimentalStdlibApi::class) + runtimeAdapter = PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") + .withSubtype(BaseType.TypeA::class.java, "a") + .withSubtype(BaseType.TypeB::class.java, "b") + .create(BaseType::class.java, emptySet(), moshi_) as JsonAdapter + } + + override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) + + override fun toJson(writer: JsonWriter, value_: BaseType?) { + runtimeAdapter.toJson(writer, value_) + } } - } - """ - .trimIndent() + """.trimIndent() ) } @@ -484,36 +480,34 @@ class MoshiSealedSymbolProcessorProviderTest(private val useKSP2: Boolean) { assertThat(generatedAdapter.readText().trim()) .isEqualTo( """ - // Code generated by moshi-sealed. Do not edit. - package test + // Code generated by moshi-sealed. Do not edit. + package test - import com.squareup.moshi.JsonAdapter - import com.squareup.moshi.JsonReader - import com.squareup.moshi.JsonWriter - import com.squareup.moshi.Moshi - import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory - import kotlin.Suppress - import kotlin.collections.emptySet - - @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", - "LocalVariableName", "RedundantVisibilityModifier") - public class BaseTypeJsonAdapter( - moshi: Moshi, - ) : JsonAdapter() { - @Suppress("UNCHECKED_CAST") - private val runtimeAdapter: JsonAdapter = - PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") - .withSubtype(SubType::class.java, "a") - .create(BaseType::class.java, emptySet(), moshi) as JsonAdapter - - override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) - - override fun toJson(writer: JsonWriter, value_: BaseType?) { - runtimeAdapter.toJson(writer, value_) + import com.squareup.moshi.JsonAdapter + import com.squareup.moshi.JsonReader + import com.squareup.moshi.JsonWriter + import com.squareup.moshi.Moshi + import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory + import kotlin.Suppress + import kotlin.collections.emptySet + + @Suppress("DEPRECATION", "unused", "ClassName", "REDUNDANT_PROJECTION", "RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier") + public class BaseTypeJsonAdapter( + moshi: Moshi, + ) : JsonAdapter() { + @Suppress("UNCHECKED_CAST") + private val runtimeAdapter: JsonAdapter = + PolymorphicJsonAdapterFactory.of(BaseType::class.java, "type") + .withSubtype(SubType::class.java, "a") + .create(BaseType::class.java, emptySet(), moshi) as JsonAdapter + + override fun fromJson(reader: JsonReader): BaseType? = runtimeAdapter.fromJson(reader) + + override fun toJson(writer: JsonWriter, value_: BaseType?) { + runtimeAdapter.toJson(writer, value_) + } } - } - """ - .trimIndent() + """.trimIndent() ) }