diff --git a/buildSrc/src/main/kotlin/IProject.kt b/buildSrc/src/main/kotlin/IProject.kt index 2a256d7..6102c48 100644 --- a/buildSrc/src/main/kotlin/IProject.kt +++ b/buildSrc/src/main/kotlin/IProject.kt @@ -11,7 +11,7 @@ object IProject : ProjectDetail() { // Remember the libs.versions.toml! val ktVersion = "2.0.20-Beta1" - val pluginVersion = "0.9.1" + val pluginVersion = "0.9.2" override val version: String = "$ktVersion-$pluginVersion" @@ -46,6 +46,6 @@ object IProject : ProjectDetail() { fun Project.setupWith(ktVersion: String) { group = IProject.GROUP description = IProject.DESCRIPTION - val mergedVersion = ktVersion + "-" + IProject.pluginVersion.toString() + val mergedVersion = ktVersion + "-" + IProject.pluginVersion version = if (IS_SNAPSHOT) "$mergedVersion-SNAPSHOT" else mergedVersion } diff --git a/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt b/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt index 920ecdc..58dd3ea 100644 --- a/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt +++ b/compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/fir/SuspendTransformFirTransformer.kt @@ -415,7 +415,29 @@ class SuspendTransformFirTransformer( excludes.any { ex -> annotationClassId == ex } } - addAll(notCompileAnnotationsCopied) + /* + * Create a new annotation based the annotation from the original function. + * It will be crashed with `IllegalArgumentException: Failed requirement` + * when using the `notCompileAnnotationsCopied` directly + * if there have some arguments with type `KClass`, + * e.g. `annotation class OneAnnotation(val target: KClass<*>)` or `kotlin.OptIn`. + * + * See https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin/issues/56 + */ + val copied = notCompileAnnotationsCopied.map { a -> + buildAnnotation { + annotationTypeRef = buildResolvedTypeRef { + type = a.resolvedType + } + this.typeArguments.addAll(a.typeArguments) + this.argumentMapping = buildAnnotationArgumentMapping { + this.source = a.source + this.mapping.putAll(a.argumentMapping.mapping) + } + } + } + + addAll(copied) } // try add @Generated(by = ...) diff --git a/compiler/suspend-transform-plugin/src/test-gen/love/forte/plugin/suspendtrans/runners/CodeGenTestRunnerGenerated.java b/compiler/suspend-transform-plugin/src/test-gen/love/forte/plugin/suspendtrans/runners/CodeGenTestRunnerGenerated.java index dc64411..e4f20de 100644 --- a/compiler/suspend-transform-plugin/src/test-gen/love/forte/plugin/suspendtrans/runners/CodeGenTestRunnerGenerated.java +++ b/compiler/suspend-transform-plugin/src/test-gen/love/forte/plugin/suspendtrans/runners/CodeGenTestRunnerGenerated.java @@ -43,4 +43,10 @@ public void testOverride() { public void testTypeAttr() { runTest("src/testData/codegen/typeAttr.kt"); } + + @Test + @TestMetadata("opt.kt") + public void testOpt() { + runTest("src/testData/codegen/opt.kt"); + } } diff --git a/compiler/suspend-transform-plugin/src/testData/codegen/opt.asm.txt b/compiler/suspend-transform-plugin/src/testData/codegen/opt.asm.txt new file mode 100644 index 0000000..153e73d --- /dev/null +++ b/compiler/suspend-transform-plugin/src/testData/codegen/opt.asm.txt @@ -0,0 +1,53 @@ +public abstract interface OneOptAnno : java/lang/Object, java/lang/annotation/Annotation { + +} + +final class OptInTest$runAsync$1 : kotlin/coroutines/jvm/internal/SuspendLambda, kotlin/jvm/functions/Function1 { + int label + + final OptInTest this$0 + + void (OptInTest $receiver, kotlin.coroutines.Continuation $completion) + + public final kotlin.coroutines.Continuation create(kotlin.coroutines.Continuation $completion) + + public final java.lang.Object invoke(kotlin.coroutines.Continuation p1) + + public java.lang.Object invoke(java.lang.Object p1) + + public final java.lang.Object invokeSuspend(java.lang.Object $result) +} + +final class OptInTest$runBlocking$1 : kotlin/coroutines/jvm/internal/SuspendLambda, kotlin/jvm/functions/Function1 { + int label + + final OptInTest this$0 + + void (OptInTest $receiver, kotlin.coroutines.Continuation $completion) + + public final kotlin.coroutines.Continuation create(kotlin.coroutines.Continuation $completion) + + public final java.lang.Object invoke(kotlin.coroutines.Continuation p1) + + public java.lang.Object invoke(java.lang.Object p1) + + public final java.lang.Object invokeSuspend(java.lang.Object $result) +} + +public final class OptInTest : java/lang/Object { + public void () + + public final static java.lang.Object access$run0(OptInTest $this, kotlin.coroutines.Continuation $completion) + + public final java.lang.Object run(kotlin.coroutines.Continuation $completion) + + private final java.lang.Object run0(kotlin.coroutines.Continuation $completion) + + public final java.util.concurrent.CompletableFuture runAsync() + + public final int runBlocking() +} + +public abstract interface Values : java/lang/Object, java/lang/annotation/Annotation { + public abstract java.lang.Class target() +} diff --git a/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.ir.txt b/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.ir.txt new file mode 100644 index 0000000..cb18846 --- /dev/null +++ b/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.ir.txt @@ -0,0 +1,125 @@ +FILE fqName: fileName:/Main.kt + CLASS ANNOTATION_CLASS name:OneOptAnno modality:OPEN visibility:public superTypes:[kotlin.Annotation] + annotations: + RequiresOptIn(message = , level = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:ERROR' type=kotlin.RequiresOptIn.Level) + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.OneOptAnno + CONSTRUCTOR visibility:public <> () returnType:.OneOptAnno [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:OneOptAnno modality:OPEN visibility:public superTypes:[kotlin.Annotation]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS ANNOTATION_CLASS name:Values modality:OPEN visibility:public superTypes:[kotlin.Annotation] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Values + PROPERTY name:target visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:target type:kotlin.reflect.KClass<*> visibility:private [final] + EXPRESSION_BODY + GET_VAR 'target: kotlin.reflect.KClass<*> declared in .Values.' type=kotlin.reflect.KClass<*> origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Values) returnType:kotlin.reflect.KClass<*> + correspondingProperty: PROPERTY name:target visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Values + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.reflect.KClass<*> declared in .Values' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:target type:kotlin.reflect.KClass<*> visibility:private [final]' type=kotlin.reflect.KClass<*> origin=null + receiver: GET_VAR ': .Values declared in .Values.' type=.Values origin=null + CONSTRUCTOR visibility:public <> (target:kotlin.reflect.KClass<*>) returnType:.Values [primary] + VALUE_PARAMETER name:target index:0 type:kotlin.reflect.KClass<*> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Values modality:OPEN visibility:public superTypes:[kotlin.Annotation]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:OptInTest modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.OptInTest + CONSTRUCTOR visibility:public <> () returnType:.OptInTest [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:OptInTest modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN GENERATED[love.forte.plugin.suspendtrans.fir.SuspendTransformPluginKey] name:runAsync visibility:public modality:FINAL <> ($this:.OptInTest) returnType:java.util.concurrent.CompletableFuture + annotations: + OptIn(markerClass = [CLASS_REFERENCE 'CLASS ANNOTATION_CLASS name:OneOptAnno modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass<.OneOptAnno>]) + Values(target = CLASS_REFERENCE 'CLASS CLASS name:OptInTest modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.reflect.KClass<.OptInTest>) + JvmBlocking(baseName = , suffix = , asProperty = ) + Api4J + $this: VALUE_PARAMETER name: type:.OptInTest + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun runAsync (): java.util.concurrent.CompletableFuture declared in .OptInTest' + CALL 'public final fun $runInAsync$ (block: kotlin.coroutines.SuspendFunction0, scope: kotlinx.coroutines.CoroutineScope?): java.util.concurrent.CompletableFuture declared in love.forte.plugin.suspendtrans.runtime' type=java.util.concurrent.CompletableFuture origin=null + : + block: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:java.util.concurrent.CompletableFuture [suspend] + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): java.util.concurrent.CompletableFuture declared in .OptInTest.runAsync' + CALL 'public final fun run (): kotlin.Int declared in .OptInTest' type=kotlin.Int origin=null + $this: GET_VAR ': .OptInTest declared in .OptInTest.runAsync' type=.OptInTest origin=null + FUN GENERATED[love.forte.plugin.suspendtrans.fir.SuspendTransformPluginKey] name:runBlocking visibility:public modality:FINAL <> ($this:.OptInTest) returnType:kotlin.Int + annotations: + OptIn(markerClass = [CLASS_REFERENCE 'CLASS ANNOTATION_CLASS name:OneOptAnno modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass<.OneOptAnno>]) + Values(target = CLASS_REFERENCE 'CLASS CLASS name:OptInTest modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.reflect.KClass<.OptInTest>) + JvmAsync(baseName = , suffix = , asProperty = ) + Api4J + $this: VALUE_PARAMETER name: type:.OptInTest + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun runBlocking (): kotlin.Int declared in .OptInTest' + CALL 'public final fun $runInBlocking$ (block: kotlin.coroutines.SuspendFunction0): T of love.forte.plugin.suspendtrans.runtime.$runInBlocking$ declared in love.forte.plugin.suspendtrans.runtime' type=T of love.forte.plugin.suspendtrans.runtime.$runInBlocking$ origin=null + : + block: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Int [suspend] + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .OptInTest.runBlocking' + CALL 'public final fun run (): kotlin.Int declared in .OptInTest' type=kotlin.Int origin=null + $this: GET_VAR ': .OptInTest declared in .OptInTest.runBlocking' type=.OptInTest origin=null + FUN name:run visibility:public modality:FINAL <> ($this:.OptInTest) returnType:kotlin.Int [suspend] + annotations: + OptIn(markerClass = [CLASS_REFERENCE 'CLASS ANNOTATION_CLASS name:OneOptAnno modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass<.OneOptAnno>]) + Values(target = CLASS_REFERENCE 'CLASS CLASS name:OptInTest modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.reflect.KClass<.OptInTest>) + JvmBlocking(baseName = , suffix = , asProperty = ) + JvmAsync(baseName = , suffix = , asProperty = ) + JvmSynthetic + $this: VALUE_PARAMETER name: type:.OptInTest + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun run (): kotlin.Int declared in .OptInTest' + CALL 'private final fun run0 (): kotlin.Int declared in .OptInTest' type=kotlin.Int origin=null + $this: GET_VAR ': .OptInTest declared in .OptInTest.run' type=.OptInTest origin=null + FUN name:run0 visibility:private modality:FINAL <> ($this:.OptInTest) returnType:kotlin.Int [suspend] + annotations: + OneOptAnno + $this: VALUE_PARAMETER name: type:.OptInTest + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun run0 (): kotlin.Int declared in .OptInTest' + CONST Int type=kotlin.Int value=1 diff --git a/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.txt b/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.txt new file mode 100644 index 0000000..1b75ae8 --- /dev/null +++ b/compiler/suspend-transform-plugin/src/testData/codegen/opt.fir.txt @@ -0,0 +1,34 @@ +FILE: Main.kt + @R|kotlin/RequiresOptIn|(level = Q|kotlin/RequiresOptIn.Level|.R|kotlin/RequiresOptIn.Level.ERROR|) public final annotation class OneOptAnno : R|kotlin/Annotation| { + public constructor(): R|OneOptAnno| { + super() + } + + } + public final annotation class Values : R|kotlin/Annotation| { + public constructor(target: R|kotlin/reflect/KClass<*>|): R|Values| { + super() + } + + public final val target: R|kotlin/reflect/KClass<*>| = R|/target| + public get(): R|kotlin/reflect/KClass<*>| + + } + public final class OptInTest : R|kotlin/Any| { + public constructor(): R|OptInTest| { + super() + } + + @R|OneOptAnno|() private final suspend fun run0(): R|kotlin/Int| { + ^run0 Int(1) + } + + @R|kotlin/OptIn|(markerClass = vararg((Q|OneOptAnno|))) @R|Values|(target = (Q|OptInTest|)) @R|love/forte/plugin/suspendtrans/annotation/JvmBlocking|() @R|love/forte/plugin/suspendtrans/annotation/JvmAsync|() public final suspend fun run(): R|kotlin/Int| { + ^run this@R|/OptInTest|.R|/OptInTest.run0|() + } + + @R|kotlin/OptIn|(markerClass = vararg((Q|OneOptAnno|))) @R|Values|(target = (Q|OptInTest|)) @R|love/forte/plugin/suspendtrans/annotation/JvmBlocking|() @R|love/forte/plugin/suspendtrans/annotation/Api4J|() public final fun runAsync(): R|java/util/concurrent/CompletableFuture| + + @R|kotlin/OptIn|(markerClass = vararg((Q|OneOptAnno|))) @R|Values|(target = (Q|OptInTest|)) @R|love/forte/plugin/suspendtrans/annotation/JvmAsync|() @R|love/forte/plugin/suspendtrans/annotation/Api4J|() public final fun runBlocking(): R|kotlin/Int| + + } diff --git a/compiler/suspend-transform-plugin/src/testData/codegen/opt.kt b/compiler/suspend-transform-plugin/src/testData/codegen/opt.kt new file mode 100644 index 0000000..8278602 --- /dev/null +++ b/compiler/suspend-transform-plugin/src/testData/codegen/opt.kt @@ -0,0 +1,27 @@ +// FIR_DUMP +// DUMP_IR +// SOURCE +// FILE: Main.kt [MainKt#main] + +import kotlinx.coroutines.suspendCancellableCoroutine +import love.forte.plugin.suspendtrans.annotation.JvmAsync +import love.forte.plugin.suspendtrans.annotation.JvmBlocking +import kotlin.annotation.AnnotationRetention.SOURCE +import kotlin.coroutines.resume +import kotlin.reflect.KClass + +@RequiresOptIn(level = RequiresOptIn.Level.ERROR) +annotation class OneOptAnno + +annotation class Values(val target: KClass<*>) + +class OptInTest { + @OneOptAnno + private suspend fun run0() = 1 + + @OptIn(OneOptAnno::class) + @Values(OptInTest::class) + @JvmBlocking + @JvmAsync + suspend fun run(): Int = run0() +} diff --git a/samples/sample-js/build.gradle.kts b/samples/sample-js/build.gradle.kts index 411011e..3e2ac95 100644 --- a/samples/sample-js/build.gradle.kts +++ b/samples/sample-js/build.gradle.kts @@ -25,55 +25,40 @@ repositories { apply(plugin = "love.forte.plugin.suspend-transform") -//tasks.withType { -// kotlinOptions { - // useK2 -// languageVersion = "2.0" -// } -//} - - - +@OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { + compilerOptions { + freeCompilerArgs.addAll( + "-Xexpect-actual-classes" + ) + } + js(IR) { nodejs() useEsModules() generateTypeScriptDefinitions() binaries.executable() - @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { target = "es2015" useEsClasses = true freeCompilerArgs.addAll( // https://kotlinlang.org/docs/whatsnew20.html#per-file-compilation-for-kotlin-js-projects - "-Xir-per-file" + "-Xir-per-file", ) } - -// compilations.all { -// kotlinOptions { -// useEsClasses = true -// } -// } } sourceSets { named("jsMain") { dependencies { implementation(kotlin("stdlib")) - // val pluginVersion = "0.4.0" - // api("love.forte.plugin.suspend-transform:suspend-transform-runtime:$pluginVersion") - // api("love.forte.plugin.suspend-transform:suspend-transform-annotation:$pluginVersion") -// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") api(libs.kotlinx.coroutines.core) } } } } - - extensions.getByType().apply { transformers[TargetPlatform.JS] = mutableListOf( SuspendTransformConfiguration.jsPromiseTransformer.copy( diff --git a/samples/sample-js/src/commonMain/kotlin/Key.kt b/samples/sample-js/src/commonMain/kotlin/Key.kt new file mode 100644 index 0000000..84d7ed4 --- /dev/null +++ b/samples/sample-js/src/commonMain/kotlin/Key.kt @@ -0,0 +1,17 @@ +@file:OptIn(ExperimentalJsExport::class) + +import love.forte.plugin.suspendtrans.annotation.JsPromise + + +/** + * + * @author ForteScarlet + */ +@JsExport +abstract class Key { + + @JsPromise + @JsExport.Ignore + abstract suspend fun run(): Any + +} diff --git a/samples/sample-js/src/commonMain/kotlin/KeyImpl.kt b/samples/sample-js/src/commonMain/kotlin/KeyImpl.kt new file mode 100644 index 0000000..924a3d7 --- /dev/null +++ b/samples/sample-js/src/commonMain/kotlin/KeyImpl.kt @@ -0,0 +1,10 @@ +import love.forte.plugin.suspendtrans.annotation.JsPromise + +/** + * + * @author ForteScarlet + */ +expect class KeyImpl : Key { + @JsPromise + override suspend fun run(): ByteArray +} diff --git a/samples/sample-js/src/jsMain/kotlin/ExpectKeyImpl.js.kt b/samples/sample-js/src/jsMain/kotlin/ExpectKeyImpl.js.kt new file mode 100644 index 0000000..837f76e --- /dev/null +++ b/samples/sample-js/src/jsMain/kotlin/ExpectKeyImpl.js.kt @@ -0,0 +1,12 @@ +import love.forte.plugin.suspendtrans.annotation.JsPromise + +@OptIn(ExperimentalJsExport::class) +@JsExport +actual class KeyImpl : Key() { + + @JsExport.Ignore + @JsPromise + actual override suspend fun run(): ByteArray { + TODO("Not yet implemented") + } +} diff --git a/samples/sample-js/src/jsMain/kotlin/OptInClass.kt b/samples/sample-js/src/jsMain/kotlin/OptInClass.kt new file mode 100644 index 0000000..8cc39de --- /dev/null +++ b/samples/sample-js/src/jsMain/kotlin/OptInClass.kt @@ -0,0 +1,9 @@ +/** + * + * @author ForteScarlet + */ +class OptInClass { + + suspend fun run(): Int = 1 + +} diff --git a/samples/sample-jvm/build.gradle.kts b/samples/sample-jvm/build.gradle.kts index df13ac2..dc63c99 100644 --- a/samples/sample-jvm/build.gradle.kts +++ b/samples/sample-jvm/build.gradle.kts @@ -1,3 +1,7 @@ +import love.forte.plugin.suspendtrans.ClassInfo +import love.forte.plugin.suspendtrans.SuspendTransformConfiguration.Companion.jvmAsyncTransformer +import love.forte.plugin.suspendtrans.SuspendTransformConfiguration.Companion.jvmBlockingTransformer +import love.forte.plugin.suspendtrans.TargetPlatform import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension plugins { @@ -15,17 +19,10 @@ buildscript { mavenCentral() } dependencies { - //this.implementation() - classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:2.0.20-Beta1-0.9.1") + classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:2.0.20-Beta1-0.9.2") } } - -//withType { -// sourceCompatibility = "11" -// targetCompatibility = "11" -//} - kotlin { compilerOptions { freeCompilerArgs.add("-Xjvm-default=all") @@ -33,14 +30,6 @@ kotlin { } } -//tasks.withType { -// kotlinOptions { -// freeCompilerArgs += "-Xjvm-default=all" - // useK2 -// languageVersion = "2.0" -// } -//} - repositories { mavenLocal() } @@ -51,15 +40,28 @@ dependencies { api(kotlin("stdlib")) api(kotlin("test-junit5")) api(kotlin("reflect")) -// val pluginVersion = "0.4.0" -// api("love.forte.plugin.suspend-transform:suspend-transform-runtime:$pluginVersion") -// api("love.forte.plugin.suspend-transform:suspend-transform-annotation:$pluginVersion") -// api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.") api(libs.kotlinx.coroutines.core) } extensions.getByType().apply { - useJvmDefault() +// useJvmDefault() + transformers[TargetPlatform.JVM] = mutableListOf( + // Add `kotlin.OptIn` to copyAnnotationExcludes + jvmBlockingTransformer.copy( + copyAnnotationExcludes = buildList { + addAll(jvmBlockingTransformer.copyAnnotationExcludes) + add(ClassInfo("kotlin", "OptIn")) + } + ), + + // Add `kotlin.OptIn` to copyAnnotationExcludes + jvmAsyncTransformer.copy( + copyAnnotationExcludes = buildList { + addAll(jvmAsyncTransformer.copyAnnotationExcludes) + add(ClassInfo("kotlin", "OptIn")) + } + ) + ) } tasks.withType { diff --git a/samples/sample-jvm/src/main/kotlin/love/forte/plugin/suspendtrans/sample/OptInTest.kt b/samples/sample-jvm/src/main/kotlin/love/forte/plugin/suspendtrans/sample/OptInTest.kt new file mode 100644 index 0000000..0411a5c --- /dev/null +++ b/samples/sample-jvm/src/main/kotlin/love/forte/plugin/suspendtrans/sample/OptInTest.kt @@ -0,0 +1,25 @@ +package love.forte.plugin.suspendtrans.sample + +import kotlinx.coroutines.suspendCancellableCoroutine +import love.forte.plugin.suspendtrans.annotation.JvmAsync +import love.forte.plugin.suspendtrans.annotation.JvmBlocking +import kotlin.coroutines.resume +import kotlin.reflect.KClass + +@RequiresOptIn(level = RequiresOptIn.Level.ERROR) +annotation class OneOptAnno + +annotation class Values(val target: KClass<*>) + +class OptInTest { + @OneOptAnno + private suspend fun run0() = suspendCancellableCoroutine { + it.resume(1) + } + + @OptIn(OneOptAnno::class) + @Values(OptInTest::class) + @JvmBlocking + @JvmAsync + suspend fun run(): Int = run0() +} diff --git a/settings.gradle.kts b/settings.gradle.kts index f7702be..55c352e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,6 +28,6 @@ include(":runtime:suspend-transform-runtime") include(":plugins:suspend-transform-plugin-gradle") //Samples -//include(":samples:sample-jvm") -//include(":samples:sample-js") +include(":samples:sample-jvm") +include(":samples:sample-js") //include(":samples:sample-wasmJs")