Skip to content

Commit 7ed27cd

Browse files
committed
Fix README
1 parent 073470e commit 7ed27cd

File tree

2 files changed

+111
-27
lines changed

2 files changed

+111
-27
lines changed

README.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,14 @@ val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation(
616616
baseNameProperty = "blockingBaseName",
617617
suffixProperty = "blockingSuffix",
618618
asPropertyProperty = "blockingAsProperty",
619-
defaultSuffix = SuspendTransformConfiguration.jvmBlockingAnnotationInfo.defaultSuffix,
619+
defaultSuffix = "Blocking",
620620
)
621621
val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation(
622622
suspendTransMarkAnnotationClassInfo,
623623
baseNameProperty = "asyncBaseName",
624624
suffixProperty = "asyncSuffix",
625625
asPropertyProperty = "asyncAsProperty",
626-
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
626+
defaultSuffix = "Async",
627627
)
628628
val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
629629
suspendTransMarkAnnotationClassInfo,
@@ -633,23 +633,65 @@ val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
633633
defaultSuffix = "Async",
634634
)
635635

636+
// The transform functions
637+
val jvmBlockingFunction = FunctionInfo("com.example", null, "runInBlocking")
638+
val jvmAsyncFunction = FunctionInfo("com.example", null, "runInAsync")
639+
val jsPromiseFunction = FunctionInfo("com.example", null, "runInPromise")
640+
636641
// The transformers
637-
val suspendTransTransformerForJvmBlocking: Transformer = jvmBlockingTransformer.copy(
642+
val suspendTransTransformerForJvmBlocking: Transformer = Transformer(
638643
markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
639-
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes +
640-
jvmSuspendTransMarkAnnotationForBlocking.classInfo
644+
transformFunctionInfo = jvmBlockingFunction,
645+
transformReturnType = null, // same as origin function
646+
transformReturnTypeGeneric = false,
647+
// include @JvmSynthetic into origin function
648+
originFunctionIncludeAnnotations = listOf(
649+
SuspendTransformConfiguration.jvmSyntheticClassInfo,
650+
),
651+
copyAnnotationsToSyntheticFunction = true,
652+
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
653+
copyAnnotationExcludes = listOf(
654+
SuspendTransformConfiguration.jvmSyntheticClassInfo,
655+
SuspendTransformConfiguration.kotlinOptInClassInfo,
656+
suspendTransMarkAnnotationClassInfo,
657+
),
658+
// Include into synthetic function's annotations
659+
syntheticFunctionIncludeAnnotations = listOf()
641660
)
642661

643-
val suspendTransTransformerForJvmAsync: Transformer = jvmAsyncTransformer.copy(
662+
val suspendTransTransformerForJvmAsync: Transformer = Transformer(
644663
markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
645-
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes +
646-
jvmSuspendTransMarkAnnotationForAsync.classInfo
664+
transformFunctionInfo = jvmAsyncFunction,
665+
transformReturnType = ClassInfo("java.util.concurrent", "CompletableFuture"),
666+
transformReturnTypeGeneric = true, // Future's generic type is origin function's return type.
667+
// include @JvmSynthetic into origin function
668+
originFunctionIncludeAnnotations = listOf(
669+
SuspendTransformConfiguration.jvmSyntheticClassInfo,
670+
),
671+
copyAnnotationsToSyntheticFunction = true,
672+
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
673+
copyAnnotationExcludes = listOf(
674+
SuspendTransformConfiguration.jvmSyntheticClassInfo,
675+
suspendTransMarkAnnotationClassInfo,
676+
SuspendTransformConfiguration.kotlinOptInClassInfo,
677+
),
678+
// Include into synthetic function's annotations
679+
syntheticFunctionIncludeAnnotations = listOf()
647680
)
648681

649-
val suspendTransTransformerForJsPromise: Transformer = jsPromiseTransformer.copy(
650-
markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
651-
copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes +
652-
jsSuspendTransMarkAnnotationForPromise.classInfo,
682+
val suspendTransTransformerForJsPromise: Transformer = Transformer(
683+
markAnnotation = jsSuspendTransMarkAnnotationForPromise,
684+
transformFunctionInfo = jsPromiseFunction,
685+
transformReturnType = ClassInfo("kotlin.js", "Promise"),
686+
transformReturnTypeGeneric = true, // Promise's generic type is origin function's return type.
687+
originFunctionIncludeAnnotations = listOf(),
688+
copyAnnotationsToSyntheticFunction = true,
689+
// excludes: @OptIn, @SuspendTrans
690+
copyAnnotationExcludes = listOf(
691+
SuspendTransformConfiguration.kotlinOptInClassInfo,
692+
suspendTransMarkAnnotationClassInfo,
693+
),
694+
syntheticFunctionIncludeAnnotations = listOf()
653695
)
654696

655697
// The above section can also be considered to be defined in `buildSrc`.

README_CN.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -609,23 +609,23 @@ public annotation class SuspendTrans(
609609
然后,配置你的构建脚本
610610

611611
```kotlin
612-
// 注解类型
612+
// The annotation type
613613
val suspendTransMarkAnnotationClassInfo = ClassInfo("love.forte.simbot.suspendrunner", "SuspendTrans")
614614

615-
// 标记注解定义
615+
// The mark annotations
616616
val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation(
617617
suspendTransMarkAnnotationClassInfo,
618618
baseNameProperty = "blockingBaseName",
619619
suffixProperty = "blockingSuffix",
620620
asPropertyProperty = "blockingAsProperty",
621-
defaultSuffix = SuspendTransformConfiguration.jvmBlockingAnnotationInfo.defaultSuffix,
621+
defaultSuffix = "Blocking",
622622
)
623623
val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation(
624624
suspendTransMarkAnnotationClassInfo,
625625
baseNameProperty = "asyncBaseName",
626626
suffixProperty = "asyncSuffix",
627627
asPropertyProperty = "asyncAsProperty",
628-
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
628+
defaultSuffix = "Async",
629629
)
630630
val 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

Comments
 (0)