No description, website, or topics provided.
Java Groovy
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
LICENSE
README.md
build.gradle
gradlew
gradlew.bat

README.md

groovy-macro-methods Download

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