Class AsyncTransformHelper

java.lang.Object
org.codehaus.groovy.transform.AsyncTransformHelper

public final class AsyncTransformHelper extends Object
Shared AST utilities for the async/await/defer language features.

Centralises AST node construction for the parser (AstBuilder).

Since:
6.0.0
  • Method Details

    • buildAwaitCall

      public static Expression buildAwaitCall(Expression arg)
      Builds AsyncSupport.await(arg) or for multi-arg: AsyncSupport.await(Awaitable.all(arg1, arg2, ...)).
    • buildDeferCall

      public static Expression buildDeferCall(Expression action)
      Builds AsyncSupport.defer($__deferScope__, action).
    • buildYieldReturnCall

      public static Expression buildYieldReturnCall(Expression arg)
      Builds AsyncSupport.yieldReturn($__asyncGen__, expr).
    • buildAsyncCall

      public static Expression buildAsyncCall(Expression closure)
      Builds AsyncSupport.async(closure) — starts immediately, returns Awaitable.
    • buildAsyncGeneratorCall

      public static Expression buildAsyncGeneratorCall(Expression closure)
      Builds AsyncSupport.asyncGenerator(closure) — starts immediately, returns Iterable.
    • buildToIterableCall

      public static Expression buildToIterableCall(Expression source)
      Builds AsyncSupport.toIterable(source).
    • buildCloseIterableCall

      public static Expression buildCloseIterableCall(Expression source)
      Builds AsyncSupport.closeIterable(source).
    • createGenParam

      public static Parameter createGenParam()
      Creates the synthetic generator parameter $__asyncGen__.
    • containsYieldReturn

      public static boolean containsYieldReturn(Statement stmt)
      Returns true if the statement tree contains a yield return call, without descending into nested closures.
    • injectGenParamIntoYieldReturnCalls

      public static void injectGenParamIntoYieldReturnCalls(Statement stmt, Parameter genParam)
      Rewrites yieldReturn(expr) calls to yieldReturn($__asyncGen__, expr) by injecting the generator parameter reference.
    • containsDefer

      public static boolean containsDefer(Statement stmt)
      Returns true if the statement tree contains a defer call, without descending into nested closures.
    • wrapWithDeferScope

      public static Statement wrapWithDeferScope(Statement body)
      Wraps a statement block with defer scope management:
       var $__deferScope__ = AsyncSupport.createDeferScope()
       try { original body }
       finally { AsyncSupport.executeDeferScope($__deferScope__) }