Skip to content

Commit

Permalink
Fix README
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Oct 5, 2024
1 parent 073470e commit 7ed27cd
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 27 deletions.
66 changes: 54 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,14 @@ val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation(
baseNameProperty = "blockingBaseName",
suffixProperty = "blockingSuffix",
asPropertyProperty = "blockingAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmBlockingAnnotationInfo.defaultSuffix,
defaultSuffix = "Blocking",
)
val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "asyncBaseName",
suffixProperty = "asyncSuffix",
asPropertyProperty = "asyncAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
defaultSuffix = "Async",
)
val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
Expand All @@ -633,23 +633,65 @@ val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
defaultSuffix = "Async",
)

// The transform functions
val jvmBlockingFunction = FunctionInfo("com.example", null, "runInBlocking")
val jvmAsyncFunction = FunctionInfo("com.example", null, "runInAsync")
val jsPromiseFunction = FunctionInfo("com.example", null, "runInPromise")

// The transformers
val suspendTransTransformerForJvmBlocking: Transformer = jvmBlockingTransformer.copy(
val suspendTransTransformerForJvmBlocking: Transformer = Transformer(
markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes +
jvmSuspendTransMarkAnnotationForBlocking.classInfo
transformFunctionInfo = jvmBlockingFunction,
transformReturnType = null, // same as origin function
transformReturnTypeGeneric = false,
// include @JvmSynthetic into origin function
originFunctionIncludeAnnotations = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
),
copyAnnotationsToSyntheticFunction = true,
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
SuspendTransformConfiguration.kotlinOptInClassInfo,
suspendTransMarkAnnotationClassInfo,
),
// Include into synthetic function's annotations
syntheticFunctionIncludeAnnotations = listOf()
)

val suspendTransTransformerForJvmAsync: Transformer = jvmAsyncTransformer.copy(
val suspendTransTransformerForJvmAsync: Transformer = Transformer(
markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes +
jvmSuspendTransMarkAnnotationForAsync.classInfo
transformFunctionInfo = jvmAsyncFunction,
transformReturnType = ClassInfo("java.util.concurrent", "CompletableFuture"),
transformReturnTypeGeneric = true, // Future's generic type is origin function's return type.
// include @JvmSynthetic into origin function
originFunctionIncludeAnnotations = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
),
copyAnnotationsToSyntheticFunction = true,
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
suspendTransMarkAnnotationClassInfo,
SuspendTransformConfiguration.kotlinOptInClassInfo,
),
// Include into synthetic function's annotations
syntheticFunctionIncludeAnnotations = listOf()
)

val suspendTransTransformerForJsPromise: Transformer = jsPromiseTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes +
jsSuspendTransMarkAnnotationForPromise.classInfo,
val suspendTransTransformerForJsPromise: Transformer = Transformer(
markAnnotation = jsSuspendTransMarkAnnotationForPromise,
transformFunctionInfo = jsPromiseFunction,
transformReturnType = ClassInfo("kotlin.js", "Promise"),
transformReturnTypeGeneric = true, // Promise's generic type is origin function's return type.
originFunctionIncludeAnnotations = listOf(),
copyAnnotationsToSyntheticFunction = true,
// excludes: @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.kotlinOptInClassInfo,
suspendTransMarkAnnotationClassInfo,
),
syntheticFunctionIncludeAnnotations = listOf()
)

// The above section can also be considered to be defined in `buildSrc`.
Expand Down
72 changes: 57 additions & 15 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,23 @@ public annotation class SuspendTrans(
然后,配置你的构建脚本

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

// 标记注解定义
// The mark annotations
val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "blockingBaseName",
suffixProperty = "blockingSuffix",
asPropertyProperty = "blockingAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmBlockingAnnotationInfo.defaultSuffix,
defaultSuffix = "Blocking",
)
val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
baseNameProperty = "asyncBaseName",
suffixProperty = "asyncSuffix",
asPropertyProperty = "asyncAsProperty",
defaultSuffix = SuspendTransformConfiguration.jvmAsyncAnnotationInfo.defaultSuffix,
defaultSuffix = "Async",
)
val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
suspendTransMarkAnnotationClassInfo,
Expand All @@ -635,23 +635,65 @@ val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation(
defaultSuffix = "Async",
)

// 转化函数定义
val suspendTransTransformerForJvmBlocking: Transformer = jvmBlockingTransformer.copy(
// The transform functions
val jvmBlockingFunction = FunctionInfo("com.example", null, "runInBlocking")
val jvmAsyncFunction = FunctionInfo("com.example", null, "runInAsync")
val jsPromiseFunction = FunctionInfo("com.example", null, "runInPromise")

// The transformers
val suspendTransTransformerForJvmBlocking: Transformer = Transformer(
markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmBlockingTransformer.copyAnnotationExcludes +
jvmSuspendTransMarkAnnotationForBlocking.classInfo
transformFunctionInfo = jvmBlockingFunction,
transformReturnType = null, // same as origin function
transformReturnTypeGeneric = false,
// include @JvmSynthetic into origin function
originFunctionIncludeAnnotations = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
),
copyAnnotationsToSyntheticFunction = true,
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
SuspendTransformConfiguration.kotlinOptInClassInfo,
suspendTransMarkAnnotationClassInfo,
),
// Include into synthetic function's annotations
syntheticFunctionIncludeAnnotations = listOf()
)

val suspendTransTransformerForJvmAsync: Transformer = jvmAsyncTransformer.copy(
val suspendTransTransformerForJvmAsync: Transformer = Transformer(
markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
copyAnnotationExcludes = SuspendTransformConfiguration.jvmAsyncTransformer.copyAnnotationExcludes +
jvmSuspendTransMarkAnnotationForAsync.classInfo
transformFunctionInfo = jvmAsyncFunction,
transformReturnType = ClassInfo("java.util.concurrent", "CompletableFuture"),
transformReturnTypeGeneric = true, // Future's generic type is origin function's return type.
// include @JvmSynthetic into origin function
originFunctionIncludeAnnotations = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
),
copyAnnotationsToSyntheticFunction = true,
// excludes: @JvmSynthetic, @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.jvmSyntheticClassInfo,
suspendTransMarkAnnotationClassInfo,
SuspendTransformConfiguration.kotlinOptInClassInfo,
),
// Include into synthetic function's annotations
syntheticFunctionIncludeAnnotations = listOf()
)

val suspendTransTransformerForJsPromise: Transformer = jsPromiseTransformer.copy(
markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes +
jsSuspendTransMarkAnnotationForPromise.classInfo,
val suspendTransTransformerForJsPromise: Transformer = Transformer(
markAnnotation = jsSuspendTransMarkAnnotationForPromise,
transformFunctionInfo = jsPromiseFunction,
transformReturnType = ClassInfo("kotlin.js", "Promise"),
transformReturnTypeGeneric = true, // Promise's generic type is origin function's return type.
originFunctionIncludeAnnotations = listOf(),
copyAnnotationsToSyntheticFunction = true,
// excludes: @OptIn, @SuspendTrans
copyAnnotationExcludes = listOf(
SuspendTransformConfiguration.kotlinOptInClassInfo,
suspendTransMarkAnnotationClassInfo,
),
syntheticFunctionIncludeAnnotations = listOf()
)

// 上面这些东西也可以考虑在 `buildSrc` 中定义。
Expand Down

0 comments on commit 7ed27cd

Please sign in to comment.