Class MacroGroovyMethods

java.lang.Object
org.codehaus.groovy.macro.methods.MacroGroovyMethods

public class MacroGroovyMethods extends Object
Macro extension methods and helpers used during macro expansion.
Since:
2.5.0
  • Field Details

    • DOLLAR_VALUE

      public static final String DOLLAR_VALUE
      Placeholder method name used for value substitution inside macros.
      See Also:
  • Constructor Details

    • MacroGroovyMethods

      public MacroGroovyMethods()
  • Method Details

    • macro

      public static <T> T macro(Object self, @DelegatesTo(MacroValuePlaceholder.class) Closure cl)
      Runtime stub for macro { ... } calls.
      Type Parameters:
      T - the inferred result type
      Parameters:
      self - the receiver
      cl - the macro closure
      Returns:
      never returns normally
    • macro

      public static Expression macro(MacroContext macroContext, ClosureExpression closureExpression)
      Rewrites a macro closure into an expression builder call.
      Parameters:
      macroContext - the current macro context
      closureExpression - the macro closure
      Returns:
      an expression that builds the macro result
    • macro

      public static <T> T macro(Object self, boolean asIs, @DelegatesTo(MacroValuePlaceholder.class) Closure cl)
      Runtime stub for macro(asIs) { ... } calls.
      Type Parameters:
      T - the inferred result type
      Parameters:
      self - the receiver
      asIs - whether to keep the closure block intact
      cl - the macro closure
      Returns:
      never returns normally
    • macro

      public static Expression macro(MacroContext macroContext, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression)
      Rewrites a macro closure into an expression builder call.
      Parameters:
      macroContext - the current macro context
      asIsConstantExpression - whether to keep the closure block intact
      closureExpression - the macro closure
      Returns:
      an expression that builds the macro result
    • macro

      public static <T> T macro(Object self, CompilePhase compilePhase, @DelegatesTo(MacroValuePlaceholder.class) Closure cl)
      Runtime stub for macro(phase) { ... } calls.
      Type Parameters:
      T - the inferred result type
      Parameters:
      self - the receiver
      compilePhase - the phase used to parse the macro body
      cl - the macro closure
      Returns:
      never returns normally
    • macro

      public static Expression macro(MacroContext macroContext, PropertyExpression phaseExpression, ClosureExpression closureExpression)
      Rewrites a macro closure into an expression builder call.
      Parameters:
      macroContext - the current macro context
      phaseExpression - the compile phase expression
      closureExpression - the macro closure
      Returns:
      an expression that builds the macro result
    • macro

      public static <T> T macro(Object self, CompilePhase compilePhase, boolean asIs, @DelegatesTo(MacroValuePlaceholder.class) Closure cl)
      Runtime stub for macro(phase, asIs) { ... } calls.
      Type Parameters:
      T - the inferred result type
      Parameters:
      self - the receiver
      compilePhase - the phase used to parse the macro body
      asIs - whether to keep the closure block intact
      cl - the macro closure
      Returns:
      never returns normally
    • macro

      public static Expression macro(MacroContext macroContext, PropertyExpression phaseExpression, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression)
      Rewrites a macro closure into an expression builder call.
      Parameters:
      macroContext - the current macro context
      phaseExpression - the compile phase expression
      asIsConstantExpression - whether to keep the closure block intact
      closureExpression - the macro closure
      Returns:
      an expression that builds the macro result
    • buildSubstitutions

      public static ListExpression buildSubstitutions(SourceUnit source, ASTNode expr)
      Collects substitution closures referenced by $v calls.
      Parameters:
      source - the current source unit
      expr - the AST node to scan
      Returns:
      a list expression containing substitution closures
    • getMacroArguments

      protected static TupleExpression getMacroArguments(SourceUnit source, MethodCallExpression call)
      Extracts tuple arguments from a macro-style method call.
      Parameters:
      source - the current source unit
      call - the method call to inspect
      Returns:
      the tuple expression, or null after reporting an error
    • getClosureArgument

      protected static ClosureExpression getClosureArgument(SourceUnit source, MethodCallExpression call)
      Returns the closure argument from a macro-style method call.
      Parameters:
      source - the current source unit
      call - the method call to inspect
      Returns:
      the trailing closure argument, or null after reporting an error