Class MacroGroovyMethods
java.lang.Object
org.codehaus.groovy.macro.methods.MacroGroovyMethods
Macro extension methods and helpers used during macro expansion.
- Since:
- 2.5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDelegate used inside macro closures for$vsubstitutions. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPlaceholder method name used for value substitution inside macros. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ListExpressionbuildSubstitutions(SourceUnit source, ASTNode expr) Collects substitution closures referenced by$vcalls.protected static ClosureExpressiongetClosureArgument(SourceUnit source, MethodCallExpression call) Returns the closure argument from a macro-style method call.protected static TupleExpressiongetMacroArguments(SourceUnit source, MethodCallExpression call) Extracts tuple arguments from a macro-style method call.static <T> TRuntime stub formacro(asIs) { ... }calls.static <T> TRuntime stub formacro { ... }calls.static <T> Tmacro(Object self, CompilePhase compilePhase, boolean asIs, Closure cl) Runtime stub formacro(phase, asIs) { ... }calls.static <T> Tmacro(Object self, CompilePhase compilePhase, Closure cl) Runtime stub formacro(phase) { ... }calls.static Expressionmacro(MacroContext macroContext, ClosureExpression closureExpression) Rewrites a macro closure into an expression builder call.static Expressionmacro(MacroContext macroContext, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression) Rewrites a macro closure into an expression builder call.static Expressionmacro(MacroContext macroContext, PropertyExpression phaseExpression, ClosureExpression closureExpression) Rewrites a macro closure into an expression builder call.static Expressionmacro(MacroContext macroContext, PropertyExpression phaseExpression, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression) Rewrites a macro closure into an expression builder call.
-
Field Details
-
DOLLAR_VALUE
Placeholder method name used for value substitution inside macros.- See Also:
-
-
Constructor Details
-
MacroGroovyMethods
public MacroGroovyMethods()
-
-
Method Details
-
macro
Runtime stub formacro { ... }calls.- Type Parameters:
T- the inferred result type- Parameters:
self- the receivercl- the macro closure- Returns:
- never returns normally
-
macro
Rewrites a macro closure into an expression builder call.- Parameters:
macroContext- the current macro contextclosureExpression- 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 formacro(asIs) { ... }calls.- Type Parameters:
T- the inferred result type- Parameters:
self- the receiverasIs- whether to keep the closure block intactcl- 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 contextasIsConstantExpression- whether to keep the closure block intactclosureExpression- 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 formacro(phase) { ... }calls.- Type Parameters:
T- the inferred result type- Parameters:
self- the receivercompilePhase- the phase used to parse the macro bodycl- 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 contextphaseExpression- the compile phase expressionclosureExpression- 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 formacro(phase, asIs) { ... }calls.- Type Parameters:
T- the inferred result type- Parameters:
self- the receivercompilePhase- the phase used to parse the macro bodyasIs- whether to keep the closure block intactcl- 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 contextphaseExpression- the compile phase expressionasIsConstantExpression- whether to keep the closure block intactclosureExpression- the macro closure- Returns:
- an expression that builds the macro result
-
buildSubstitutions
Collects substitution closures referenced by$vcalls.- Parameters:
source- the current source unitexpr- the AST node to scan- Returns:
- a list expression containing substitution closures
-
getMacroArguments
Extracts tuple arguments from a macro-style method call.- Parameters:
source- the current source unitcall- the method call to inspect- Returns:
- the tuple expression, or
nullafter reporting an error
-
getClosureArgument
Returns the closure argument from a macro-style method call.- Parameters:
source- the current source unitcall- the method call to inspect- Returns:
- the trailing closure argument, or
nullafter reporting an error
-