@@ -609,23 +609,23 @@ public annotation class SuspendTrans(
609609然后,配置你的构建脚本
610610
611611``` kotlin
612- // 注解类型
612+ // The annotation type
613613val suspendTransMarkAnnotationClassInfo = ClassInfo (" love.forte.simbot.suspendrunner" , " SuspendTrans" )
614614
615- // 标记注解定义
615+ // The mark annotations
616616val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation (
617617 suspendTransMarkAnnotationClassInfo,
618618 baseNameProperty = " blockingBaseName" ,
619619 suffixProperty = " blockingSuffix" ,
620620 asPropertyProperty = " blockingAsProperty" ,
621- defaultSuffix = SuspendTransformConfiguration .jvmBlockingAnnotationInfo.defaultSuffix ,
621+ defaultSuffix = " Blocking " ,
622622)
623623val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation (
624624 suspendTransMarkAnnotationClassInfo,
625625 baseNameProperty = " asyncBaseName" ,
626626 suffixProperty = " asyncSuffix" ,
627627 asPropertyProperty = " asyncAsProperty" ,
628- defaultSuffix = SuspendTransformConfiguration .jvmAsyncAnnotationInfo.defaultSuffix ,
628+ defaultSuffix = " Async " ,
629629)
630630val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation (
631631 suspendTransMarkAnnotationClassInfo,
@@ -635,23 +635,65 @@ val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
635635 defaultSuffix = " Async" ,
636636)
637637
638- // 转化函数定义
639- val suspendTransTransformerForJvmBlocking: Transformer = jvmBlockingTransformer.copy(
638+ // The transform functions
639+ val jvmBlockingFunction = FunctionInfo (" com.example" , null , " runInBlocking" )
640+ val jvmAsyncFunction = FunctionInfo (" com.example" , null , " runInAsync" )
641+ val jsPromiseFunction = FunctionInfo (" com.example" , null , " runInPromise" )
642+
643+ // The transformers
644+ val suspendTransTransformerForJvmBlocking: Transformer = Transformer (
640645 markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
641- copyAnnotationExcludes = SuspendTransformConfiguration .jvmBlockingTransformer.copyAnnotationExcludes +
642- jvmSuspendTransMarkAnnotationForBlocking.classInfo
646+ transformFunctionInfo = jvmBlockingFunction,
647+ transformReturnType = null , // same as origin function
648+ transformReturnTypeGeneric = false ,
649+ // include @JvmSynthetic into origin function
650+ originFunctionIncludeAnnotations = listOf (
651+ SuspendTransformConfiguration .jvmSyntheticClassInfo,
652+ ),
653+ copyAnnotationsToSyntheticFunction = true ,
654+ // excludes: @JvmSynthetic, @OptIn, @SuspendTrans
655+ copyAnnotationExcludes = listOf (
656+ SuspendTransformConfiguration .jvmSyntheticClassInfo,
657+ SuspendTransformConfiguration .kotlinOptInClassInfo,
658+ suspendTransMarkAnnotationClassInfo,
659+ ),
660+ // Include into synthetic function's annotations
661+ syntheticFunctionIncludeAnnotations = listOf ()
643662)
644663
645- val suspendTransTransformerForJvmAsync: Transformer = jvmAsyncTransformer.copy (
664+ val suspendTransTransformerForJvmAsync: Transformer = Transformer (
646665 markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
647- copyAnnotationExcludes = SuspendTransformConfiguration .jvmAsyncTransformer.copyAnnotationExcludes +
648- jvmSuspendTransMarkAnnotationForAsync.classInfo
666+ transformFunctionInfo = jvmAsyncFunction,
667+ transformReturnType = ClassInfo (" java.util.concurrent" , " CompletableFuture" ),
668+ transformReturnTypeGeneric = true , // Future's generic type is origin function's return type.
669+ // include @JvmSynthetic into origin function
670+ originFunctionIncludeAnnotations = listOf (
671+ SuspendTransformConfiguration .jvmSyntheticClassInfo,
672+ ),
673+ copyAnnotationsToSyntheticFunction = true ,
674+ // excludes: @JvmSynthetic, @OptIn, @SuspendTrans
675+ copyAnnotationExcludes = listOf (
676+ SuspendTransformConfiguration .jvmSyntheticClassInfo,
677+ suspendTransMarkAnnotationClassInfo,
678+ SuspendTransformConfiguration .kotlinOptInClassInfo,
679+ ),
680+ // Include into synthetic function's annotations
681+ syntheticFunctionIncludeAnnotations = listOf ()
649682)
650683
651- val suspendTransTransformerForJsPromise: Transformer = jsPromiseTransformer.copy(
652- markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
653- copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes +
654- jsSuspendTransMarkAnnotationForPromise.classInfo,
684+ val suspendTransTransformerForJsPromise: Transformer = Transformer (
685+ markAnnotation = jsSuspendTransMarkAnnotationForPromise,
686+ transformFunctionInfo = jsPromiseFunction,
687+ transformReturnType = ClassInfo (" kotlin.js" , " Promise" ),
688+ transformReturnTypeGeneric = true , // Promise's generic type is origin function's return type.
689+ originFunctionIncludeAnnotations = listOf (),
690+ copyAnnotationsToSyntheticFunction = true ,
691+ // excludes: @OptIn, @SuspendTrans
692+ copyAnnotationExcludes = listOf (
693+ SuspendTransformConfiguration .kotlinOptInClassInfo,
694+ suspendTransMarkAnnotationClassInfo,
695+ ),
696+ syntheticFunctionIncludeAnnotations = listOf ()
655697)
656698
657699// 上面这些东西也可以考虑在 `buildSrc` 中定义。
0 commit comments