bsideup / Groovy Macro Methods
Licence: apache-2.0
Stars: ✭ 14
Programming Languages
java
68154 projects - #9 most used programming language
groovy-macro-methods
Simple macro system for Groovy. Allows you to mark extension method with @Macro, and every call to this method will be translated to expression returned from it.
Usage
Just mark your extension method with @Macro annotation:
import static org.codehaus.groovy.ast.tools.GeneralUtils.*;
public class TestMacroMethods {
@Macro
public static Expression safe(MacroContext macroContext,
MethodCallExpression callExpression) {
return ternaryX(
notNullX(callExpression.getObjectExpression()),
callExpression,
constX(null)
);
}
}
and then, use it as normal method:
def nullObject = null;
assert null == safe(nullObject.hashcode())
License
Project is licensed under the terms of the Apache License, Version 2.0
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].