From 943b392522db44fe4e2e947e450918557e816c02 Mon Sep 17 00:00:00 2001 From: Tianyu Zhu Date: Mon, 6 Jan 2025 20:56:15 -0700 Subject: [PATCH] Support Kotlin 2+ (#10) * Support Kotlin 2 * Upgrade junit to 4.13.2 * Resurrect embedded.gradle --- build.gradle | 2 +- integration-test/build.gradle | 2 +- kotlin-plugin/build.gradle | 5 +++-- .../generation/ObjectSerializationIRGeneration.kt | 4 ++-- .../kotlin/me/shika/ObjectSerializationFixTest.kt | 14 +------------- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 08257c3..3966b49 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.20' + id 'org.jetbrains.kotlin.jvm' version '2.0.0' } allprojects { diff --git a/integration-test/build.gradle b/integration-test/build.gradle index daf228f..1e8e328 100644 --- a/integration-test/build.gradle +++ b/integration-test/build.gradle @@ -7,7 +7,7 @@ plugins { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation project('scala-module') - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' kotlinCompilerPluginClasspath project(':kotlin-plugin') } \ No newline at end of file diff --git a/kotlin-plugin/build.gradle b/kotlin-plugin/build.gradle index 887317a..d7216bf 100644 --- a/kotlin-plugin/build.gradle +++ b/kotlin-plugin/build.gradle @@ -10,7 +10,8 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable" - testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0' - testImplementation 'junit:junit:4.12' + // testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0' does not support Kotlin 2 + testImplementation 'dev.zacsweers.kctfork:core:0.6.0' // Fork of kotlin-compile-testing that supports Kotlin 2 + testImplementation 'junit:junit:4.13.2' testImplementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable' } diff --git a/kotlin-plugin/src/main/kotlin/me/shika/generation/ObjectSerializationIRGeneration.kt b/kotlin-plugin/src/main/kotlin/me/shika/generation/ObjectSerializationIRGeneration.kt index 8a97222..880dd62 100644 --- a/kotlin-plugin/src/main/kotlin/me/shika/generation/ObjectSerializationIRGeneration.kt +++ b/kotlin-plugin/src/main/kotlin/me/shika/generation/ObjectSerializationIRGeneration.kt @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid -private object ObjectSerializationOrigin : IrDeclarationOriginImpl("object-serialization-fix", isSynthetic = true) +private val objectSerializationOrigin = IrDeclarationOriginImpl("object-serialization-fix", isSynthetic = true) class ObjectSerializationIrGeneration : IrGenerationExtension { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { @@ -37,7 +37,7 @@ class ObjectSerializationIrGeneration : IrGenerationExtension { name = SERIALIZABLE_READ returnType = context.irBuiltIns.anyNType visibility = DescriptorVisibilities.PUBLIC - origin = ObjectSerializationOrigin + origin = objectSerializationOrigin }.also { function -> // Ensure it is not static function.dispatchReceiverParameter = cls.thisReceiver?.copyTo(function) diff --git a/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt b/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt index 697df7d..dc2b789 100644 --- a/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt +++ b/kotlin-plugin/src/test/kotlin/me/shika/ObjectSerializationFixTest.kt @@ -5,25 +5,13 @@ import com.tschuchort.compiletesting.SourceFile import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.junit.Assert.assertTrue import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.Parameterized -import org.junit.runners.Parameterized.Parameters import java.lang.reflect.Method @OptIn(ExperimentalCompilerApi::class) -@RunWith(Parameterized::class) -class ObjectSerializationFixTest(enableIr: Boolean, enableFir: Boolean) { - companion object { - @Parameters(name = "IR: {0}, FIR: {1}") - @JvmStatic - fun data() = arrayOf(arrayOf(false, false), arrayOf(true, false), arrayOf(true, true)) - } - +class ObjectSerializationFixTest { private val compiler = KotlinCompilation().apply { compilerPluginRegistrars = listOf(ObjectSerializationCompilerPluginRegistrar()) - useIR = enableIr supportsK2 = true - useK2 = enableFir } private val SERIALIZABLE_OBJECT = """