public final class AsyncTransformHelper
extends Object
Shared AST utilities for the async/await/defer language features.
Centralises AST node construction and higher-level rewrites used by the
parser (AstBuilder) so feature logic does not sprawl across the
visitor.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Expression |
buildAsyncCall(Expression closure)Builds AsyncSupport.async(closure) — starts immediately, returns Awaitable. |
|
public static Expression |
buildAsyncGeneratorCall(Expression closure)Builds AsyncSupport.asyncGenerator(closure) — starts immediately, returns Iterable. |
|
public static Expression |
buildAwaitCall(Expression arg)Builds AsyncSupport.await(arg) or for multi-arg:
AsyncSupport.await(Awaitable.all(arg1, arg2, ...)). |
|
public static Expression |
buildCloseIterableCall(Expression source)Builds AsyncSupport.closeIterable(source). |
|
public static Expression |
buildDeferCall(Expression action)Builds AsyncSupport.defer($__deferScope__, action). |
|
public static Expression |
buildToIterableCall(Expression source)Builds AsyncSupport.toIterable(source). |
|
public static Expression |
buildYieldReturnCall(Expression arg)Builds AsyncSupport.yieldReturn($__asyncGen__, expr). |
|
public static boolean |
containsDefer(Statement stmt)Returns true if the statement tree contains a defer call,
without descending into nested closures. |
|
public static boolean |
containsYieldReturn(Statement stmt)Returns true if the statement tree contains a yield return
call, without descending into nested closures. |
|
public static Parameter |
createGenParam()Creates the synthetic generator parameter $__asyncGen__. |
|
public static Expression |
transformAsyncClosure(ClosureExpression closure)Applies defer-scope wrapping and generator parameter injection to an async { ... } closure, then builds the runtime call
(async or asyncGenerator). |
|
public static Statement |
wrapForAwaitLoop(ForStatement forStatement)Rewrites a for await loop into a block that materialises the
source iterable, runs the loop, and closes the source in a finally block:
|
|
public static Statement |
wrapWithDeferScope(Statement body)Wraps a statement block with defer scope management: |
Builds AsyncSupport.async(closure) — starts immediately, returns Awaitable.
Builds AsyncSupport.asyncGenerator(closure) — starts immediately, returns Iterable.
Builds AsyncSupport.await(arg) or for multi-arg:
AsyncSupport.await(Awaitable.all(arg1, arg2, ...)).
Single-arg form casts to Object so static/dynamic overload selection targets AsyncSupport.await, avoiding ambiguity when the argument implements multiple async interfaces (e.g. CompletableFuture implements both CompletionStage and Future).
Builds AsyncSupport.closeIterable(source).
Builds AsyncSupport.defer($__deferScope__, action).
Builds AsyncSupport.toIterable(source).
Builds AsyncSupport.yieldReturn($__asyncGen__, expr).
Returns true if the statement tree contains a defer call,
without descending into nested closures.
Returns true if the statement tree contains a yield return
call, without descending into nested closures.
Creates the synthetic generator parameter $__asyncGen__.
Applies defer-scope wrapping and generator parameter injection to an
async { ... } closure, then builds the runtime call
(async or asyncGenerator).
closure - the parsed async closure expression Rewrites a for await loop into a block that materialises the
source iterable, runs the loop, and closes the source in a finally block:
var $__forAwaitSource_N = AsyncSupport.toIterable(collection)
try {
for (... in $__forAwaitSource_N) { body }
} finally {
AsyncSupport.closeIterable($__forAwaitSource_N)
}
forStatement - the for statement whose collection is the await source