[groovy-dev] MetaClass#getClassNode

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy-dev] MetaClass#getClassNode

Jochen Theodorou
hi,

I have spotted the method getClassNode in MetaClass (old MetaClass)
it seems this method does (re)compilation of groovy classes. Don't we
have GroovyClassLaoder for this? Do we really need that method there? I
mean do we need that there with the full power it has now? I would
change that in a version without recompilation.

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

RE: [groovy-dev] MetaClass#getClassNode

Dierk König
this method is e.g. used with the SqlWhereVisitor to
work on the AST of a closure, not to recompile anything but
to emit SQL according the closure's expression.
This finally gives you a compile-time check of your SQL
in a way...

cheers
Mittie

> -----Original Message-----
> From: Jochen Theodorou [mailto:[hidden email]]
> Sent: Mittwoch, 2. November 2005 20:52
> To: [hidden email]
> Subject: [groovy-dev] MetaClass#getClassNode
>
>
> hi,
>
> I have spotted the method getClassNode in MetaClass (old MetaClass)
> it seems this method does (re)compilation of groovy classes. Don't we
> have GroovyClassLaoder for this? Do we really need that method there? I
> mean do we need that there with the full power it has now? I would
> change that in a version without recompilation.
>
> bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] MetaClass#getClassNode

tugwilson
I really don't understand why it's in MetaClass. It seems to be using  
MetaClass as a handy way of caching classNode.

I'd like to find another home for it:)

On 3 Nov 2005, at 09:18, Dierk Koenig wrote:

> this method is e.g. used with the SqlWhereVisitor to
> work on the AST of a closure, not to recompile anything but
> to emit SQL according the closure's expression.
> This finally gives you a compile-time check of your SQL
> in a way...

Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] MetaClass#getClassNode

Jochen Theodorou
In reply to this post by Dierk König
Dierk Koenig schrieb:
> this method is e.g. used with the SqlWhereVisitor to
> work on the AST of a closure,  not to recompile anything but
> to emit SQL according the closure's expression.
> This finally gives you a compile-time check of your SQL
> in a way...

1) way should it have the ability to recompile?
2) it's a compile time check during runtime afaik, since the method is
used at runtime and not at compile time.

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] MetaClass#getClassNode

Jochen Theodorou
In reply to this post by tugwilson
John Wilson schrieb:

> I really don't understand why it's in MetaClass. It seems to be using  
> MetaClass as a handy way of caching classNode.


currently the method is this for me:

    public ClassNode getClassNode() {
        if (classNode == null &&
GroovyObject.class.isAssignableFrom(theClass)) {
            classNode = new ClassNode(theClass);
        }
        return classNode;
    }

really no reason to put it into MetaClass.

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] MetaClass#getClassNode

tugwilson

On 3 Nov 2005, at 18:47, Jochen Theodorou wrote:

> currently the method is this for me:
>
>    public ClassNode getClassNode() {
>        if (classNode == null && GroovyObject.class.isAssignableFrom
> (theClass)) {
>            classNode = new ClassNode(theClass);
>        }
>        return classNode;
>    }

Exactly

>
> really no reason to put it into MetaClass.

I'd like to lose it - however you will see that classNode is cached.  
I think that this is why it's there.

If we can live without the caching then it's trivial to remove it.


John Wilson
The Wilson Partnership
http://www.wilson.co.uk


Reply | Threaded
Open this post in threaded view
|

RE: [groovy-dev] MetaClass#getClassNode

Dierk König
In reply to this post by Jochen Theodorou
> Dierk Koenig schrieb:
> > this method is e.g. used with the SqlWhereVisitor to
> > work on the AST of a closure,  not to recompile anything but
> > to emit SQL according the closure's expression.
> > This finally gives you a compile-time check of your SQL
> > in a way...
>
> 1) way should it have the ability to recompile?

I don't know about other usages but for SqlWhereVisitor there is
no need for recompiling anything.

> 2) it's a compile time check during runtime afaik, since the method is
> used at runtime and not at compile time.

If you choose to use groovyc, then your expression will be parsed
into the AST at parse-time. (Even the class is generated although
never used.)
At runtime that AST is used to create the
Sql 'where' clause.

cheers
Mittie
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] MetaClass#getClassNode

Jochen Theodorou
Dierk Koenig schrieb:
[...]
>>2) it's a compile time check during runtime afaik, since the method is
>>used at runtime and not at compile time.
>
> If you choose to use groovyc, then your expression will be parsed
> into the AST at parse-time. (Even the class is generated although
> never used.)
> At runtime that AST is used to create the
> Sql 'where' clause.

I think you misunderstood... after the parsing step of the compiler, the
Groovy AST is created. The next step is to create the bytecode and the
step after is to output the bytecode. This means of course that there is
an AST to the where clause, but there is no interaction with the
builder. When running the builder, the builder requests a ClassNode from
MetaClass which contains the AST. If it's a groovy run, then maybe the
ast is cached if it's an execution of bytecode then the AST has to be
recreated.

This means that you have problems when you have only bytecode or the
script file differs from the executed file (for exmaple compiled and
then changed)

For me this means, the mechanism can not be replaced as easy as I thought.

A real execution during parse time would surely be interesting.... but I
have currently no ides how to do that

bye blackdrag


Reply | Threaded
Open this post in threaded view
|

RE: [groovy-dev] MetaClass#getClassNode

Dierk König
> > If you choose to use groovyc, then your expression will be parsed
> > into the AST at parse-time. (Even the class is generated although
> > never used.)
> > At runtime that AST is used to create the
> > Sql 'where' clause.
>
> I think you misunderstood...

I think we were talking about different scenarios and problems.

I only wanted to say that getClassNode() is used with the
DataSet class as it provides access to the AST which is then used
with the SqlWhereVisitor.

[..]

> This means that you have problems when you have only bytecode or the
> script file differs from the executed file (for exmaple compiled and
> then changed)

Yep. that's true. I did not think about that scenario.
I guess it means that any Groovy code that uses dataSet.findAll{}
will currently fail when precompiled and no Groovy source is
available.

cheers
Mittie