groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cédric Champeau <cedric.champ...@gmail.com>
Subject Re: Groovy 2.5 @Macro ?
Date Sat, 26 May 2018 16:12:10 GMT
I didn't check, but I _think_ you can't define a macro and use it in the
same file.

Le sam. 26 mai 2018 à 17:15, MG <mgbiz@arscreat.com> a écrit :

> I would have expected a quick "you can't use it like that / you just have
> to / here is some documentation" reply...
> Then let me rephrase my question: Why are these Groovy 2.5 tests green:
>
> https://github.com/apache/groovy/blob/GROOVY_2_5_X/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/MacroTransformationTest.groovy
> ?
> Cheers,
> mg
>
> On 26.05.2018 00:00, MG wrote:
>
> 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.Expressionimport org.codehaus.groovy.ast.expr.VariableExpressionimport
org.codehaus.groovy.macro.runtime.Macroimport org.codehaus.groovy.macro.runtime.MacroContextimport
org.junit.Ignoreimport org.junit.Testimport static org.codehaus.groovy.ast.tools.GeneralUtils.constX
> 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 ?
> mg
>
>
>
>

Mime
View raw message