You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by MG <mg...@arscreat.com> on 2018/05/25 22:00:32 UTC

Groovy 2.5 @Macro ?

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 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



Re: Groovy 2.5 @Macro ?

Posted by MG <mg...@arscreat.com>.
Thank you Paul,
mg

On 27.05.2018 02:56, Paul King wrote:
> I'll try to add in some basic information. I didn't realise that 
> wasn't covered at all.
>
> On Sun, May 27, 2018 at 9:55 AM, mg <mgbiz@arscreat.com 
> <ma...@arscreat.com>> wrote:
>
>     Hi Guillaume,
>
>     yes, there seems to be nothing on @Macro.
>
>     Cheers,
>     mg
>
>     -------- Ursprüngliche Nachricht --------
>     Von: Guillaume Laforge <glaforge@gmail.com
>     <ma...@gmail.com>>
>     Datum: 26.05.18 21:15 (GMT+01:00)
>     An: dev@groovy.apache.org <ma...@groovy.apache.org>
>     Betreff: Re: Groovy 2.5 @Macro ?
>
>     Did you also check the documentation?
>     http://docs.groovy-lang.org/next/html/documentation/#_macros
>     <http://docs.groovy-lang.org/next/html/documentation/#_macros>
>
>     On Sat, May 26, 2018 at 7:04 PM mg <mgbiz@arscreat.com
>     <ma...@arscreat.com>> wrote:
>
>         Hi Cedric,
>
>         thank you for replying. I did try having the @Macro annotated
>         in a (static) method in a seperate class first, then moved it
>         closer to the test. I posted that  for brevity, and since I
>         was banking on the author of the feature to set me straight...
>
>         The release notes
>         (http://groovy-lang.org/releasenotes/groovy-2.5.html
>         <http://groovy-lang.org/releasenotes/groovy-2.5.html>)
>         currently have the following to say on the topic:
>
>
>             Macro support
>
>         With Groovy 2.5, you can write macros in Groovy!
>
>
>               Expressions and statements
>
>         TBD
>
>
>               Macro classes
>
>         TBD
>
>
>               AST matching
>
>         TBD
>
>
>         -------- Ursprüngliche Nachricht --------
>         Von: Cédric Champeau <cedric.champeau@gmail.com
>         <ma...@gmail.com>>
>         Datum: 26.05.18 18:12 (GMT+01:00)
>         An: dev@groovy.apache.org <ma...@groovy.apache.org>
>         Betreff: Re: Groovy 2.5 @Macro ?
>
>         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
>         <ma...@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
>             <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.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 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
>>
>>
>
>
>
>     -- 
>     Guillaume Laforge
>     Apache Groovy committer & PMC Vice-President
>     Developer Advocate @ Google Cloud Platform
>
>     Blog: http://glaforge.appspot.com/ <http://glaforge.appspot.com/>
>     Twitter: @glaforge <http://twitter.com/glaforge>
>
>


Re: Groovy 2.5 @Macro ?

Posted by Paul King <pa...@asert.com.au>.
I'll try to add in some basic information. I didn't realise that wasn't
covered at all.

On Sun, May 27, 2018 at 9:55 AM, mg <mg...@arscreat.com> wrote:

> Hi Guillaume,
>
> yes, there seems to be nothing on @Macro.
>
> Cheers,
> mg
>
> -------- Ursprüngliche Nachricht --------
> Von: Guillaume Laforge <gl...@gmail.com>
> Datum: 26.05.18 21:15 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Groovy 2.5 @Macro ?
>
> Did you also check the documentation?
> http://docs.groovy-lang.org/next/html/documentation/#_macros
>
> On Sat, May 26, 2018 at 7:04 PM mg <mg...@arscreat.com> wrote:
>
>> Hi Cedric,
>>
>> thank you for replying. I did try having the @Macro annotated in a
>> (static) method in a seperate class first, then moved it closer to the
>> test. I posted that  for brevity, and since I was banking on the author of
>> the feature to set me straight...
>>
>> The release notes (http://groovy-lang.org/releasenotes/groovy-2.5.html)
>> currently have the following to say on the topic:
>> Macro support
>>
>> With Groovy 2.5, you can write macros in Groovy!
>> Expressions and statements
>>
>> TBD
>> Macro classes
>>
>> TBD
>> AST matching
>>
>> TBD
>>
>> -------- Ursprüngliche Nachricht --------
>> Von: Cédric Champeau <ce...@gmail.com>
>> Datum: 26.05.18 18:12 (GMT+01:00)
>> An: dev@groovy.apache.org
>> Betreff: Re: Groovy 2.5 @Macro ?
>>
>> 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 <mg...@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
>>>
>>>
>>>
>>>
>
> --
> Guillaume Laforge
> Apache Groovy committer & PMC Vice-President
> Developer Advocate @ Google Cloud Platform
>
> Blog: http://glaforge.appspot.com/
> Twitter: @glaforge <http://twitter.com/glaforge>
>

Re: Groovy 2.5 @Macro ?

Posted by mg <mg...@arscreat.com>.
Hi Guillaume,
yes, there seems to be nothing on @Macro.
Cheers,mg
-------- Ursprüngliche Nachricht --------Von: Guillaume Laforge <gl...@gmail.com> Datum: 26.05.18  21:15  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
Did you also check the documentation?http://docs.groovy-lang.org/next/html/documentation/#_macros

On Sat, May 26, 2018 at 7:04 PM mg <mg...@arscreat.com> wrote:
Hi Cedric,
thank you for replying. I did try having the @Macro annotated in a (static) method in a seperate class first, then moved it closer to the test. I posted that  for brevity, and since I was banking on the author of the feature to set me straight...
The release notes (http://groovy-lang.org/releasenotes/groovy-2.5.html) currently have the following to say on the topic:Macro supportWith Groovy 2.5, you can write macros in Groovy!Expressions and statementsTBDMacro classesTBDAST matchingTBD
-------- Ursprüngliche Nachricht --------Von: Cédric Champeau <ce...@gmail.com> Datum: 26.05.18  18:12  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
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 <mg...@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.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 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

      

      

    
    

  




-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-PresidentDeveloper Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/Twitter: @glaforge

Re: Groovy 2.5 @Macro ?

Posted by Guillaume Laforge <gl...@gmail.com>.
Did you also check the documentation?
http://docs.groovy-lang.org/next/html/documentation/#_macros

On Sat, May 26, 2018 at 7:04 PM mg <mg...@arscreat.com> wrote:

> Hi Cedric,
>
> thank you for replying. I did try having the @Macro annotated in a
> (static) method in a seperate class first, then moved it closer to the
> test. I posted that  for brevity, and since I was banking on the author of
> the feature to set me straight...
>
> The release notes (http://groovy-lang.org/releasenotes/groovy-2.5.html)
> currently have the following to say on the topic:
> Macro support
>
> With Groovy 2.5, you can write macros in Groovy!
> Expressions and statements
>
> TBD
> Macro classes
>
> TBD
> AST matching
>
> TBD
>
> -------- Ursprüngliche Nachricht --------
> Von: Cédric Champeau <ce...@gmail.com>
> Datum: 26.05.18 18:12 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Groovy 2.5 @Macro ?
>
> 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 <mg...@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
>>
>>
>>
>>

-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Blog: http://glaforge.appspot.com/
Twitter: @glaforge <http://twitter.com/glaforge>

Re: Groovy 2.5 @Macro ?

Posted by mg <mg...@arscreat.com>.
Hi Cedric,
thank you for replying. I did try having the @Macro annotated in a (static) method in a seperate class first, then moved it closer to the test. I posted that  for brevity, and since I was banking on the author of the feature to set me straight...
The release notes (http://groovy-lang.org/releasenotes/groovy-2.5.html) currently have the following to say on the topic:Macro supportWith Groovy 2.5, you can write macros in Groovy!Expressions and statementsTBDMacro classesTBDAST matchingTBD
-------- Ursprüngliche Nachricht --------Von: Cédric Champeau <ce...@gmail.com> Datum: 26.05.18  18:12  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
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 <mg...@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.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 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

      

      

    
    

  



Re: Groovy 2.5 @Macro ?

Posted by Cédric Champeau <ce...@gmail.com>.
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 <mg...@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
>
>
>
>

Re: Groovy 2.5 @Macro ?

Posted by Paul King <pa...@asert.com.au>.
I've done some very minimal doco already but have more to do.

On Sun., 27 May 2018, 8:47 pm mg, <mg...@arscreat.com> wrote:

> I saw that, but assertScript is used for many tests, outside of the
> special requirements of @Macro...
>
> I'll test the documentation, once you get round to doing that :-)
>
> -------- Ursprüngliche Nachricht --------
> Von: Paul King <pa...@asert.com.au>
> Datum: 27.05.18 04:20 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Groovy 2.5 @Macro ?
>
> Actually, if you look at src/test in groovy-macro, you'll see that the
> macro methods and META-INF file are there. The deferred compilation
> is achieved using assertScript.
>
>
> On Sun, May 27, 2018 at 11:21 AM, Paul King <pa...@asert.com.au> wrote:
>
>>
>> Macro expansion is done early (CONVERSION) and it expects to find the
>> method it
>> will be expanding into available on the classpath at that point.
>>
>> It is pretty much the same reasons as for extension modules:
>>
>> http://groovy-lang.org/metaprogramming.html#_extension_modules_and_classpath
>>
>>
>>
>> On Sun, May 27, 2018 at 10:02 AM, mg <mg...@arscreat.com> wrote:
>>
>>> Hi Paul,
>>>
>>> why this restriction ? I thought this feature was here to e.g. simply
>>> support logging of the form
>>> "$variableExpression.name=$variableExpression.value", etc:
>>>
>>>
>>> https://github.com/bsideup/macro-methods-workshop/blob/master/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
>>>
>>> ?
>>>
>>> Cheers,
>>> mg
>>>
>>>
>>> -------- Ursprüngliche Nachricht --------
>>> Von: Paul King <pa...@asert.com.au>
>>> Datum: 27.05.18 01:50 (GMT+01:00)
>>> An: dev@groovy.apache.org
>>> Betreff: Re: Groovy 2.5 @Macro ?
>>>
>>> Your best bet is to have the macro class and META-INF/services file
>>> under src/main and your usage under src/test.
>>> If you want to do it all in one file, you can create a temp directory,
>>> stuff the META-INF/services file in it, add that directory
>>> to the classpath dynamically and then run your code using the macro with
>>> a new GroovyShell().
>>>
>>> On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:
>>>
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>
>>
>

Re: Groovy 2.5 @Macro ?

Posted by Cédric Champeau <ce...@gmail.com>.
It could very well be a packaging bug: if the macro transformation
descriptor is not on class path, it won't work. I'm on my phone now so I
can't check, but it would explain.

Le dim. 27 mai 2018 à 18:47, mg <mg...@arscreat.com> a écrit :

> I saw that, but assertScript is used for many tests, outside of the
> special requirements of @Macro...
>
> I'll test the documentation, once you get round to doing that :-)
>
> -------- Ursprüngliche Nachricht --------
> Von: Paul King <pa...@asert.com.au>
> Datum: 27.05.18 04:20 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Groovy 2.5 @Macro ?
>
> Actually, if you look at src/test in groovy-macro, you'll see that the
> macro methods and META-INF file are there. The deferred compilation
> is achieved using assertScript.
>
>
> On Sun, May 27, 2018 at 11:21 AM, Paul King <pa...@asert.com.au> wrote:
>
>>
>> Macro expansion is done early (CONVERSION) and it expects to find the
>> method it
>> will be expanding into available on the classpath at that point.
>>
>> It is pretty much the same reasons as for extension modules:
>>
>> http://groovy-lang.org/metaprogramming.html#_extension_modules_and_classpath
>>
>>
>>
>> On Sun, May 27, 2018 at 10:02 AM, mg <mg...@arscreat.com> wrote:
>>
>>> Hi Paul,
>>>
>>> why this restriction ? I thought this feature was here to e.g. simply
>>> support logging of the form
>>> "$variableExpression.name=$variableExpression.value", etc:
>>>
>>>
>>> https://github.com/bsideup/macro-methods-workshop/blob/master/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
>>>
>>> ?
>>>
>>> Cheers,
>>> mg
>>>
>>>
>>> -------- Ursprüngliche Nachricht --------
>>> Von: Paul King <pa...@asert.com.au>
>>> Datum: 27.05.18 01:50 (GMT+01:00)
>>> An: dev@groovy.apache.org
>>> Betreff: Re: Groovy 2.5 @Macro ?
>>>
>>> Your best bet is to have the macro class and META-INF/services file
>>> under src/main and your usage under src/test.
>>> If you want to do it all in one file, you can create a temp directory,
>>> stuff the META-INF/services file in it, add that directory
>>> to the classpath dynamically and then run your code using the macro with
>>> a new GroovyShell().
>>>
>>> On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:
>>>
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>
>>
>

Re: Groovy 2.5 @Macro ?

Posted by mg <mg...@arscreat.com>.
I saw that, but assertScript is used for many tests, outside of the special requirements of @Macro...
I'll test the documentation, once you get round to doing that :-)
-------- Ursprüngliche Nachricht --------Von: Paul King <pa...@asert.com.au> Datum: 27.05.18  04:20  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
Actually, if you look at src/test in groovy-macro, you'll see that themacro methods and META-INF file are there. The deferred compilationis achieved using assertScript.

On Sun, May 27, 2018 at 11:21 AM, Paul King <pa...@asert.com.au> wrote:



Macro expansion is done early (CONVERSION) and it expects to find the method itwill be expanding into available on the classpath at that point.
It is pretty much the same reasons as for extension modules:
http://groovy-lang.org/metaprogramming.html#_extension_modules_and_classpath



On Sun, May 27, 2018 at 10:02 AM, mg <mg...@arscreat.com> wrote:
Hi Paul,
why this restriction ? I thought this feature was here to e.g. simply support logging of the form "$variableExpression.name=$variableExpression.value", etc:
https://github.com/bsideup/macro-methods-workshop/blob/master/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
?
Cheers,mg

-------- Ursprüngliche Nachricht --------Von: Paul King <pa...@asert.com.au> Datum: 27.05.18  01:50  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
Your best bet is to have the macro class and META-INF/services file under src/main and your usage under src/test.If you want to do it all in one file, you can create a temp directory, stuff the META-INF/services file in it, add that directoryto the classpath dynamically and then run your code using the macro with a new GroovyShell().
On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:

  
    
  
  
    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.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 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

      

      

    
    

  








Re: Groovy 2.5 @Macro ?

Posted by Paul King <pa...@asert.com.au>.
Actually, if you look at src/test in groovy-macro, you'll see that the
macro methods and META-INF file are there. The deferred compilation
is achieved using assertScript.


On Sun, May 27, 2018 at 11:21 AM, Paul King <pa...@asert.com.au> wrote:

>
> Macro expansion is done early (CONVERSION) and it expects to find the
> method it
> will be expanding into available on the classpath at that point.
>
> It is pretty much the same reasons as for extension modules:
> http://groovy-lang.org/metaprogramming.html#_extension_modules_and_
> classpath
>
>
>
> On Sun, May 27, 2018 at 10:02 AM, mg <mg...@arscreat.com> wrote:
>
>> Hi Paul,
>>
>> why this restriction ? I thought this feature was here to e.g. simply
>> support logging of the form "$variableExpression.name=$variableExpression.value",
>> etc:
>>
>> https://github.com/bsideup/macro-methods-workshop/blob/maste
>> r/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
>>
>> ?
>>
>> Cheers,
>> mg
>>
>>
>> -------- Ursprüngliche Nachricht --------
>> Von: Paul King <pa...@asert.com.au>
>> Datum: 27.05.18 01:50 (GMT+01:00)
>> An: dev@groovy.apache.org
>> Betreff: Re: Groovy 2.5 @Macro ?
>>
>> Your best bet is to have the macro class and META-INF/services file under
>> src/main and your usage under src/test.
>> If you want to do it all in one file, you can create a temp directory,
>> stuff the META-INF/services file in it, add that directory
>> to the classpath dynamically and then run your code using the macro with
>> a new GroovyShell().
>>
>> On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:
>>
>>> 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/subprojec
>>> ts/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
>>>
>>>
>>>
>>>
>>
>

Re: Groovy 2.5 @Macro ?

Posted by Paul King <pa...@asert.com.au>.
Macro expansion is done early (CONVERSION) and it expects to find the
method it
will be expanding into available on the classpath at that point.

It is pretty much the same reasons as for extension modules:
http://groovy-lang.org/metaprogramming.html#_extension_modules_and_classpath



On Sun, May 27, 2018 at 10:02 AM, mg <mg...@arscreat.com> wrote:

> Hi Paul,
>
> why this restriction ? I thought this feature was here to e.g. simply
> support logging of the form "$variableExpression.name=$variableExpression.value",
> etc:
>
> https://github.com/bsideup/macro-methods-workshop/blob/
> master/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
>
> ?
>
> Cheers,
> mg
>
>
> -------- Ursprüngliche Nachricht --------
> Von: Paul King <pa...@asert.com.au>
> Datum: 27.05.18 01:50 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Groovy 2.5 @Macro ?
>
> Your best bet is to have the macro class and META-INF/services file under
> src/main and your usage under src/test.
> If you want to do it all in one file, you can create a temp directory,
> stuff the META-INF/services file in it, add that directory
> to the classpath dynamically and then run your code using the macro with a
> new GroovyShell().
>
> On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:
>
>> 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/subprojec
>> ts/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
>>
>>
>>
>>
>

Re: Groovy 2.5 @Macro ?

Posted by mg <mg...@arscreat.com>.
Hi Paul,
why this restriction ? I thought this feature was here to e.g. simply support logging of the form "$variableExpression.name=$variableExpression.value", etc:
https://github.com/bsideup/macro-methods-workshop/blob/master/src/test/groovy/com/example/SuperLoggerMacroTest.groovy
?
Cheers,mg

-------- Ursprüngliche Nachricht --------Von: Paul King <pa...@asert.com.au> Datum: 27.05.18  01:50  (GMT+01:00) An: dev@groovy.apache.org Betreff: Re: Groovy 2.5 @Macro ? 
Your best bet is to have the macro class and META-INF/services file under src/main and your usage under src/test.If you want to do it all in one file, you can create a temp directory, stuff the META-INF/services file in it, add that directoryto the classpath dynamically and then run your code using the macro with a new GroovyShell().
On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:

  
    
  
  
    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.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 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

      

      

    
    

  




Re: Groovy 2.5 @Macro ?

Posted by Paul King <pa...@asert.com.au>.
Your best bet is to have the macro class and META-INF/services file under
src/main and your usage under src/test.
If you want to do it all in one file, you can create a temp directory,
stuff the META-INF/services file in it, add that directory
to the classpath dynamically and then run your code using the macro with a
new GroovyShell().

On Sun, May 27, 2018 at 1:15 AM, MG <mg...@arscreat.com> wrote:

> 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
>
>
>
>

Re: Groovy 2.5 @Macro ?

Posted by MG <mg...@arscreat.com>.
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.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 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
>
>