Well, actually that would be my use case.

I'm trying to capture a closure source code (string) when parsing a groovy
config file with a (custom) ConfigSlurper.

I'm able to read the source code from the closure BlockStatement using and
AST xform. Then the idea was to inject it into the nodeMetaData. But it
looks the `myClosure.metaClass.classNode` is returning null.


p

On Thu, Feb 8, 2018 at 2:46 PM, Cédric Champeau <cedric.champ...@gmail.com>
wrote:

> In general `metaClass.classNode` is unsafe: you never know if there's
> going to be something there. It only works for scripts compiled "on the
> fly" for which you keep a reference. Not precompiled classes, typically.
>
> 2018-02-08 14:44 GMT+01:00 Paolo Di Tommaso <paolo.ditomm...@gmail.com>:
>
>> I see. Actually my idea was to populate the nodeMetaData map and access
>> it via `class.metaClass.classNode.nodeMetaData`, but it seems not
>> possible.
>>
>> But the the use of annotation sounds a nice idea.
>>
>> Thanks.
>> p
>>
>> On Thu, Feb 8, 2018 at 2:35 PM, Cédric Champeau <
>> cedric.champ...@gmail.com> wrote:
>>
>>> Unless you have an AST xform that takes that node metadata and injects
>>> it into bytecode in a way that it's available at runtime (say, within an
>>> annotation), no, it's not possible.
>>>
>>> 2018-02-08 14:30 GMT+01:00 Paolo Di Tommaso <paolo.ditomm...@gmail.com>:
>>>
>>>> Dear all,
>>>>
>>>> Is it possible to inject some values in a nodeMetaData during AST
>>>> transformation and access such values at runtime  ?
>>>>
>>>>
>>>> p
>>>>
>>>
>>>
>>
>

Reply via email to