@@ -609,23 +609,23 @@ public annotation class SuspendTrans(
609
609
然后,配置你的构建脚本
610
610
611
611
``` kotlin
612
- // 注解类型
612
+ // The annotation type
613
613
val suspendTransMarkAnnotationClassInfo = ClassInfo (" love.forte.simbot.suspendrunner" , " SuspendTrans" )
614
614
615
- // 标记注解定义
615
+ // The mark annotations
616
616
val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation (
617
617
suspendTransMarkAnnotationClassInfo,
618
618
baseNameProperty = " blockingBaseName" ,
619
619
suffixProperty = " blockingSuffix" ,
620
620
asPropertyProperty = " blockingAsProperty" ,
621
- defaultSuffix = SuspendTransformConfiguration .jvmBlockingAnnotationInfo.defaultSuffix ,
621
+ defaultSuffix = " Blocking " ,
622
622
)
623
623
val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation (
624
624
suspendTransMarkAnnotationClassInfo,
625
625
baseNameProperty = " asyncBaseName" ,
626
626
suffixProperty = " asyncSuffix" ,
627
627
asPropertyProperty = " asyncAsProperty" ,
628
- defaultSuffix = SuspendTransformConfiguration .jvmAsyncAnnotationInfo.defaultSuffix ,
628
+ defaultSuffix = " Async " ,
629
629
)
630
630
val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation (
631
631
suspendTransMarkAnnotationClassInfo,
@@ -635,23 +635,65 @@ val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
635
635
defaultSuffix = " Async" ,
636
636
)
637
637
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 (
640
645
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 ()
643
662
)
644
663
645
- val suspendTransTransformerForJvmAsync: Transformer = jvmAsyncTransformer.copy (
664
+ val suspendTransTransformerForJvmAsync: Transformer = Transformer (
646
665
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 ()
649
682
)
650
683
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 ()
655
697
)
656
698
657
699
// 上面这些东西也可以考虑在 `buildSrc` 中定义。
0 commit comments