AST nodeMetaData

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

AST nodeMetaData

Paolo Di Tommaso
Dear all, 

Is it possible to inject some values in a nodeMetaData during AST transformation and access such values at runtime  ?


p
Reply | Threaded
Open this post in threaded view
|

Re: AST nodeMetaData

Cédric Champeau
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 <[hidden email]>:
Dear all, 

Is it possible to inject some values in a nodeMetaData during AST transformation and access such values at runtime  ?


p

Reply | Threaded
Open this post in threaded view
|

Re: AST nodeMetaData

Paolo Di Tommaso
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 <[hidden email]> 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 <[hidden email]>:
Dear all, 

Is it possible to inject some values in a nodeMetaData during AST transformation and access such values at runtime  ?


p


Reply | Threaded
Open this post in threaded view
|

Re: AST nodeMetaData

Cédric Champeau
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 <[hidden email]>:
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 <[hidden email]> 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 <[hidden email]>:
Dear all, 

Is it possible to inject some values in a nodeMetaData during AST transformation and access such values at runtime  ?


p



Reply | Threaded
Open this post in threaded view
|

Re: AST nodeMetaData

Paolo Di Tommaso
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.



On Thu, Feb 8, 2018 at 2:46 PM, Cédric Champeau <[hidden email]> 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 <[hidden email]>:
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 <[hidden email]> 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 <[hidden email]>:
Dear all, 

Is it possible to inject some values in a nodeMetaData during AST transformation and access such values at runtime  ?


p