Skip to content

Commit b4cdf3c

Browse files
committed
Enhance documentation for Transformer class, clarifying usage of transform annotations, nullable scope parameters, and annotation copying behavior.
1 parent ff09eec commit b4cdf3c

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

compiler/suspend-transform-plugin-configuration/src/main/kotlin/love/forte/plugin/suspendtrans/configuration/SuspendTransformConfiguration.kt

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,71 +227,85 @@ class IncludeAnnotation @InternalSuspendTransformConfigurationApi constructor(
227227
@Serializable
228228
class Transformer @InternalSuspendTransformConfigurationApi constructor(
229229
/**
230-
* 函数上的某种标记。
230+
* Information about the marker annotation that marks functions to be transformed.
231231
*/
232232
val markAnnotation: MarkAnnotation,
233233

234234
/**
235-
* 用于转化的函数信息。
235+
* Information of the transform function.
236236
*
237-
* 这个函数的实际格式必须为
237+
* The actual format of this function must be:
238238
*
239239
* ```kotlin
240-
* fun <T> <fun-name>(block: suspend () -> T[, scope: CoroutineScope = ...]): T {
240+
* fun <T> <fun-name>(block: suspend () -> T[, scope: CoroutineScope? = ...]): T {
241241
* // ...
242242
* }
243243
* ```
244244
*
245-
* 其中,此异步函数可以有第二个参数,此参数格式必须为 [kotlinx.coroutines.CoroutineScope]
246-
* 如果存在此参数,当转化函数所处类型自身实现了 [kotlinx.coroutines.CoroutineScope] 时,将会将其自身作为参数填入,类似于:
245+
* Among them, this asynchronous function can have a second parameter, which must be of type [kotlinx.coroutines.CoroutineScope] and is recommended to be nullable.
246+
* If this parameter exists, when the type containing the transform function implements [kotlinx.coroutines.CoroutineScope] itself, it will fill in itself as a parameter, similar to:
247247
*
248248
* ```kotlin
249249
* class Bar : CoroutineScope {
250-
* @Xxx
250+
* @Xxx // your custom transform function's mark annotation
251251
* suspend fun foo(): Foo
252252
*
253253
* @Api4J fun fooXxx(): CompletableFuture<Foo> = transform(block = { foo() }, scope = this)
254254
* }
255+
* ```
256+
*
257+
* If the scope parameter is nullable, then the effect is similar to:
258+
*
259+
* ```kotlin
260+
* class Bar {
261+
* @Xxx // your custom transform function's mark annotation
262+
* suspend fun foo(): Foo
263+
*
264+
* @Api4J fun fooXxx(): CompletableFuture<Foo> = transform(block = { foo() }, scope = this as? CoroutineScope)
265+
* }
266+
* ```
267+
* Therefore, when nullable it is more inheritance-friendly - when the subclass extends CoroutineScope the parameter can take effect, regardless of whether it overrides this function.
268+
*
255269
*/
256270
val transformFunctionInfo: FunctionInfo,
257271

258272
/**
259-
* 转化后的返回值类型, 为null时代表与原函数一致。
273+
* The return type after transformation. When null, it represents the same as the original function.
260274
*/
261275
val transformReturnType: ClassInfo?,
262276

263277
// TODO TypeGeneric for suspend function return type and transform function return type?
264278

265279
/**
266-
* 转化后的返回值类型中,是否存在需要与原本返回值类型一致的泛型。
280+
* Whether there are generics in the transformed return type that need to be consistent with the original return type.
267281
*/
268282
val transformReturnTypeGeneric: Boolean,
269283

270284
/**
271-
* 函数生成后,需要在原函数上追加的注解信息。
285+
* Annotation information that needs to be added to the original function after function generation.
272286
*
273-
* 例如追加个 `@kotlin.jvm.JvmSynthetic` 之类的。
287+
* For example, add something like `@kotlin.jvm.JvmSynthetic`.
274288
*/
275289
val originFunctionIncludeAnnotations: List<IncludeAnnotation>,
276290

277291
/**
278-
* 需要在生成出来的函数上追加的注解信息。(不需要指定 `@Generated`
292+
* Annotation information that needs to be added to the generated function. (No need to specify `@Generated`)
279293
*/
280294
val syntheticFunctionIncludeAnnotations: List<IncludeAnnotation>,
281295

282296
/**
283-
* 是否复制源函数上的注解到新的函数上。
284-
* 如果生成的是属性类型,则表示是否复制到 `getter` 上。
297+
* Whether to copy annotations from the source function to the new function.
298+
* If generated as a property type, it indicates whether to copy to the `getter`.
285299
*/
286300
val copyAnnotationsToSyntheticFunction: Boolean,
287301

288302
/**
289-
* 复制原函数上注解时需要排除掉的注解。
303+
* Annotations to be excluded when copying annotations from the original function.
290304
*/
291305
val copyAnnotationExcludes: List<ClassInfo>,
292306

293307
/**
294-
* 如果是生成属性的话,是否复制源函数上的注解到新的属性上
308+
* If generating a property, whether to copy annotations from the source function to the new property
295309
*
296310
* @since 0.9.0
297311
*/

0 commit comments

Comments
 (0)