groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <>
Subject Groovy 2.5 @Macro ?
Date Fri, 25 May 2018 22:00:32 GMT
Hi guys,

giving the new Groovy 2.5 macro functionality a spin, and would have 
expected the code below to replace the "call" to nv(x) with the AST 
expression created in the method, i.e. returning the name of the 
"passed" variable. Instead no macro magic happens, and the compilation 
accordingly fails with "groovy.lang.MissingMethodException: No signature 
of method: groovy.GroovyMacroSpike.nv() is applicable for argument 
types: (Integer) values: [123]":

import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.macro.runtime.Macro import org.codehaus.groovy.macro.runtime.MacroContext
import org.junit.Ignore import org.junit.Test import static

class GroovyMacroSpike {
   @Test @Ignore void nvTest() {
     final x =123 assert x ==123 assert nv(x) =="x" }

   @Macro Expression nv(MacroContext ctx, VariableExpression variable) {
     return constX(variable.getName());

What is missing to make this work ?

View raw message