Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created July 16, 2018 12:30
Show Gist options
  • Save olegchir/8142d2830570fda45e81d64edcbbfca6 to your computer and use it in GitHub Desktop.
Save olegchir/8142d2830570fda45e81d64edcbbfca6 to your computer and use it in GitHub Desktop.
//До 2.5 приходилось писать так:
def clazz = new MethodCallExpression(new VariableExpression("this"), "getClass", EMPTY_ARGUMENTS)
def body = new ExpressionStatement(new MethodCallExpression(clazz, "getName", EMPTY_ARGUMENTS))
classNode.addMethod('getDescription', ACC_PUBLIC, STRING_TYPE, EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body)
//После 2.5 первые две строчки превращаются в такое:
def body = macro(true) {
getClass().name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment