Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] adding inheritance of a class definition after
parsing

Jochen Theodorou

2008-08-21

Replies: Find Java Web Hosting

Author LoginPost Reply
david kment schrieb:
>> if it is not for normal classes, but scripts, then you can use a custom
>> compiler configuration and set your script base class.Other than that,
>> there is no way, unless you want to transform the AST... which actually
>> isn't that difficult.
>
> after thinking about it, and for the sake of my own flexibility, i should
> really try the AST way as a solution for this and other related endavours.
>
> can you give me a short explanation how getting to the AST works,
> and how it can be integrated in the workflow read --> parse --> execute ?
>
> i found no reference to the AST in the documentation. API documentation yes,
> but not general documentation.

the documentation is something that needs to be worked on in this area I
guess... It is a new feature in 1.6, so it won't do in versions before
and you will need at last 1.6-beta1. As for how to accomplish this I
suggest you take a look at
http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/groovy/beans/Bindable.java
http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/groovy/beans/BindableASTTransformation.java
and their usage for example
http://shemnon.com/speling/2008/04/bindable-observable-properties.html
(from the author of the ast transformation code)

If you can have clear points of where you compile and run the groovy
code, then I suggest you take a look at
http://blackdragsview.blogspot.com/2006/11/chitchat-with-groovy-compiler.html
which shows how to add default imports. Of course you can "easily"
change the super class with this too.

As for the workflow... the nice thing about the annotation based ast
transformation is, that it is automatically integrated into the
compiler, nothing to worry about. In th other case it is a bit more
difficult, which is exactly why we added the first way ;)

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.