groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergei Egorov <bsid...@gmail.com>
Subject Re: [groovy-macro] static method call expressions
Date Tue, 19 Apr 2016 15:43:20 GMT
Hey Mario,

Good catch! Maybe we should add it to documentation (when there will be
some :D )


BR,
Sergei

On Tue, Apr 19, 2016 at 6:21 PM Mario Garcia <mario.ggar@gmail.com> wrote:

> I figured out why:
>
> By default macros are using CompilePhase.CONVERSION and at this point the
> compiler doesn't care about types. That's why it didn't recognized neither
> "JsonOutput" (When using JsonOutput.toJson...) nor "groovy" (When using
> groovy.json.JsonOutput.toJson...):
>
> The way it's working now is:
>
> Statement stmt = macro(CompilePhase.SEMANTIC_ANALYSIS, true) {
>     groovy.json.JsonOutput($v{mapExpression})
> }
>
> or...
>
> MethodCallExpression methodCall = macro(CompilePhase.SEMANTIC_ANALYSIS) {
>     groovy.json.JsonOutput($v{mapExpression})
> }
>
> ...in case you wanted to get the method call expression directly.
> Mario
>
> 2016-04-11 14:26 GMT+02:00 Mario Garcia <mario.ggar@gmail.com>:
>
>> Hello:
>>
>> I'm playing a little bit with groovy-macro, BTW it's really cool how easy
>> you can create statements and expressions.
>>
>> However I'm having some issues when trying to create an static method
>> call:
>>
>> *    Statement callJsonOutput(final MapExpression mapExpression) {*
>> *        return macro(true) { JsonOutput.toJson($v{ mapExpression }) }*
>> *    }*
>>
>> When executing the test, it complains because "JsonOutput" class is not
>> found. That's correct, but I can't make it work either by doing:
>>
>> *    Statement callJsonOutput(final MapExpression mapExpression) {*
>> *        return macro(true) { groovy.json.JsonOutput.toJson($v{
>> mapExpression }) }*
>> *    }*
>>
>> Any ideas ?
>> Mario
>>
>
>

Mime
View raw message