|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Groovy AST not taking?I'm working on a "WithLog" AST transform that will basically do this to the attached class:
private static final Logger log = Logger.getLogger(WhateverTheClassNameIs.class) Not a big deal. Once I got my head wrapped around what is going on, I created this annotation and impl: https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/WithLog.groovy https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/WithLogImpl.groovy Unfortunately, this test doesn't work: https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/test/unit/ASTTransformTests.groovy https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/testing/Foo.groovy Any idea why? I'm totally at a loss for how to debug Groovy AST transforms when they don't seem to be being called at all, but are compiled in fine. ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?Hi Robert,
your transform works fine for me, so I guess there is a problem with the way you build/run your code. To investigate your transform, I used the following class: class WithLogTest { static void main(args) { def clazz = new GroovyClassLoader().parseClass(""" class WLT { static run() { println HasLog.log } } @foo.WithLog class HasLog {} """) clazz.run() } } Now set a break point in the transform and run the class. Your transform can be simplified to: @GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) public class WithLogImpl implements ASTTransformation { public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { def classNode = nodes[1] // nodes[0] is the annotation that triggered the transform classNode.addField("log", ClassNode.ACC_PUBLIC | ClassNode.ACC_STATIC | ClassNode.ACC_FINAL, new ClassNode(Logger), new StaticMethodCallExpression(new ClassNode(Logger), "getLogger", new ClassExpression(classNode)) ) } } One downside of using a local transform for this task is that you won't be able to refer to 'log' via its class name from within the class because the Groovy compiler will complain about a missing property 'log' before your transform kicks in. To solve this problem you'll probably need to use a global transform in phase CONVERSION. Such a transform will look pretty much like your version of the local transform, only that it will take a bit more work to identify @WithLog annotations because types haven't been resolved yet. Hope this helps. Cheers, Peter PS: Please provide output and/or stacktrace when asking such a question.
|
|
|
Re: Groovy AST not taking?Comments interspersed.
Peter Niederwieser wrote: > Hi Robert, > To investigate your transform, I used the following class: > > class WithLogTest { > static void main(args) { > def clazz = new GroovyClassLoader().parseClass(""" > class WLT { > static run() { > println HasLog.log > } > } > > @foo.WithLog > class HasLog {} > """) > > clazz.run() > } > } > > Your transform can be simplified to: > > @GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) > public class WithLogImpl implements ASTTransformation { > public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { > def classNode = nodes[1] // nodes[0] is the annotation that triggered > the transform > classNode.addField("log", > ClassNode.ACC_PUBLIC | ClassNode.ACC_STATIC | ClassNode.ACC_FINAL, > new ClassNode(Logger), > new StaticMethodCallExpression(new ClassNode(Logger), "getLogger", > new ClassExpression(classNode)) > ) > } > } > looks copy-pasted from Hamlet's Behind the Times blog post), which says this: == The public visit(ASTNode[], SourceUnit) method is invoked for each source unit that contains your target annotation. The AST you receive is not for the @WithLogging annotated method, it is for the entire file that contains @WithLogging. == Is that a lie? Or is there something different going on? > One downside of using a local transform for this task is that you won't be > able to refer to 'log' via its class name from within the class because the > Groovy compiler will complain about a missing property 'log' before your > transform kicks in. To solve this problem you'll probably need to use a > global transform in phase CONVERSION. Such a transform will look pretty much > like your version of the local transform, only that it will take a bit more > work to identify @WithLog annotations because types haven't been resolved > yet. > I thought that AST Transforms mangled the class during compilation. I want my log property to not only be visible via Groovy, but to Java classes, too. Do I really need to do a global transform for this? I really don't like the sound of that, because it creates hassle in compiling. Is there a better Compile Phase I could be using? The documentation on compile phases is practically non-existent, so I'm just aping what I'm seeing in the example. http://groovy.codehaus.org/api/org/codehaus/groovy/control/CompilePhase.html > PS: Please provide output and/or stacktrace when asking such a question. > Sorry -- the complaint was a missing property exception for "log" when I called "assertNotNull Foo.log". ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?And with regard to build -- is there a particular stunt I need to pull to ensure a local transform
is used? I thought it was sufficient to just have it in the class path. ~~ Robert. Peter Niederwieser wrote: > Hi Robert, > > your transform works fine for me, so I guess there is a problem with the way > you build/run your code. > > To investigate your transform, I used the following class: > > class WithLogTest { > static void main(args) { > def clazz = new GroovyClassLoader().parseClass(""" > class WLT { > static run() { > println HasLog.log > } > } > > @foo.WithLog > class HasLog {} > """) > > clazz.run() > } > } > > Now set a break point in the transform and run the class. > > Your transform can be simplified to: > > @GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) > public class WithLogImpl implements ASTTransformation { > public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { > def classNode = nodes[1] // nodes[0] is the annotation that triggered > the transform > classNode.addField("log", > ClassNode.ACC_PUBLIC | ClassNode.ACC_STATIC | ClassNode.ACC_FINAL, > new ClassNode(Logger), > new StaticMethodCallExpression(new ClassNode(Logger), "getLogger", > new ClassExpression(classNode)) > ) > } > } > > One downside of using a local transform for this task is that you won't be > able to refer to 'log' via its class name from within the class because the > Groovy compiler will complain about a missing property 'log' before your > transform kicks in. To solve this problem you'll probably need to use a > global transform in phase CONVERSION. Such a transform will look pretty much > like your version of the local transform, only that it will take a bit more > work to identify @WithLog annotations because types haven't been resolved > yet. > > Hope this helps. > > Cheers, > Peter > > PS: Please provide output and/or stacktrace when asking such a question. > > > Robert Fischer wrote: >> I'm working on a "WithLog" AST transform that will basically do this to >> the attached class: >> >> private static final Logger log = >> Logger.getLogger(WhateverTheClassNameIs.class) >> >> Not a big deal. Once I got my head wrapped around what is going on, I >> created this annotation and impl: >> >> https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/WithLog.groovy >> https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/WithLogImpl.groovy >> >> Unfortunately, this test doesn't work: >> >> https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/test/unit/ASTTransformTests.groovy >> https://svn.codehaus.org/grails-plugins/grails-sublog/trunk/src/groovy/testing/Foo.groovy >> >> Any idea why? I'm totally at a loss for how to debug Groovy AST >> transforms when they don't seem to >> be being called at all, but are compiled in fine. >> >> ~~ Robert Fischer, Smokejumper IT Consulting. >> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >> >> Check out my book, "Grails Persistence with GORM and GSQL"! >> http://www.smokejumperit.com/redirect.html >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?I just used a different package when copying your code. The documentation is wrong. The ASTTransformation interface is used both for local and global transforms. For local transforms, ASTTranformation.visit() is called once per annotated node (class, method, or field; method parameters don't seem to be supported). The first element in the ASTNode array holds the annotation, the second one the annotated node. For global transforms, ASTTranformation.visit() is called once per file. The first element in the ASTNode array holds the ModuleNode representing the file. It does. No. The reason why I suggested a global transform is that the compiler seems to do some checks for static properties during semantic analysis. Therefore you might need to add 'log' before semantic analysis if you want to support all ways that it could be accessed (qualified, unqualified, from the same class, from other classes, etc.). But only global transforms can be run before semantic analysis (i.e. in phase CONVERSION). There isn't really much difference between local and global transforms. Global transforms don't create more hassles. It's only that the unit of work is more coarse-grained (ModuleNode instead of an annotated node), and that you need to include a properties file along with your transform in order to activate it. In return you gain more flexibility. In general CANONICALIZATION is recommended, although the current compiler does not perform any canonicalization so you could just as well choose SEMANTIC_ANALYSIS. What this gives you over CONVERSION is that types etc. have been resolved and that the AST more accurately reflects the program (a few ASTNodes are replaced during semantic analysis). Some transforms need to do their stuff before semantic analysis. For example this is necessary when adding an import, or a parameter to a method declaration. In that case you need a global transform. Yes that should be sufficient. A transform and the code to be transformed must be compiled separately, and the transform must be on the compile classpath when the latter is compiled. What happens when you run my "test"? Are you using plain groovyc or a build tool/IDE? Cheers, Peter |
|
|
Re: Groovy AST not taking?I haven't run your tests, so I'm not sure what the result is. Since my error was a lack of "log"
property, it sounds like this conversion problem was the issue. > No. The reason why I suggested a global transform is that the compiler seems > to do some checks for static properties during semantic analysis. Therefore > you might need to add 'log' before semantic analysis if you want to support > all ways that it could be accessed (qualified, unqualified, from the same > class, from other classes, etc.). But only global transforms can be run > before semantic analysis (i.e. in phase CONVERSION). > Ah. Sucky. Is this something I should open a JIRA on? Seems off to me. ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?What is it that seems off to you? The fact that only global transforms can run in phase conversion? There is a good reason for this: It's not possible to tell if @WithLog is annotated with @GroovyASTTransformationClass before its type has been resolved (which happens in phase semantic analysis).
In general, writing a global transform isn't harder than writing a local one. Your case is an exception because in phase conversion it's not completely trivial to correctly identify a @WithLog annotation (which you would get for free with a local transform). Before you go down this route, I suggest to verify my belief that phase semantic analysis, and therefore a local transform, isn't good enough for your case. The example that didn't seem to work with your original transform was: @WithLog class Foo { def foo() { assert log != null // OK assert Foo.log != null // compile error } } Cheers, Peter
|
|
|
Re: Groovy AST not taking?This was failing for me, too.
@WithLog class Foo { def exposeLog() { log } } Which is what made me initially suspect it wasn't taking. ~~ Robert. Peter Niederwieser wrote: > What is it that seems off to you? The fact that only global transforms can > run in phase conversion? There is a good reason for this: It's not possible > to tell if @WithLog is annotated with @GroovyASTTransformationClass before > its type has been resolved (which happens in phase semantic analysis). > In general, writing a global transform isn't harder than writing a local > one. Your case is an exception because in phase conversion it's not > completely trivial to correctly identify a @WithLog annotation (which you > would get for free with a local transform). Before you go down this route, I > suggest to verify my belief that phase semantic analysis, and therefore a > local transform, isn't good enough for your case. The example that didn't > seem to work with your original transform was: > > @WithLog > class Foo { > def foo() { > assert log != null // OK > assert Foo.log != null // compile error > } > } > > Cheers, > Peter > > > Robert Fischer wrote: >> I haven't run your tests, so I'm not sure what the result is. Since my >> error was a lack of "log" >> property, it sounds like this conversion problem was the issue. >> >>> No. The reason why I suggested a global transform is that the compiler >>> seems >>> to do some checks for static properties during semantic analysis. >>> Therefore >>> you might need to add 'log' before semantic analysis if you want to >>> support >>> all ways that it could be accessed (qualified, unqualified, from the same >>> class, from other classes, etc.). But only global transforms can be run >>> before semantic analysis (i.e. in phase CONVERSION). >>> >> Ah. Sucky. Is this something I should open a JIRA on? Seems off to me. >> >> ~~ Robert Fischer, Smokejumper IT Consulting. >> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >> >> Check out my book, "Grails Persistence with GORM and GSQL"! >> http://www.smokejumperit.com/redirect.html >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?Also, my errors were runtime, not compile-time. And what seemed off is that there was validation
happening on static calls at compile time -- after all, is it any different if I were to inject log to the class via metaclass mangling? ~~ Robert. Peter Niederwieser wrote: > What is it that seems off to you? The fact that only global transforms can > run in phase conversion? There is a good reason for this: It's not possible > to tell if @WithLog is annotated with @GroovyASTTransformationClass before > its type has been resolved (which happens in phase semantic analysis). > In general, writing a global transform isn't harder than writing a local > one. Your case is an exception because in phase conversion it's not > completely trivial to correctly identify a @WithLog annotation (which you > would get for free with a local transform). Before you go down this route, I > suggest to verify my belief that phase semantic analysis, and therefore a > local transform, isn't good enough for your case. The example that didn't > seem to work with your original transform was: > > @WithLog > class Foo { > def foo() { > assert log != null // OK > assert Foo.log != null // compile error > } > } > > Cheers, > Peter > > > Robert Fischer wrote: >> I haven't run your tests, so I'm not sure what the result is. Since my >> error was a lack of "log" >> property, it sounds like this conversion problem was the issue. >> >>> No. The reason why I suggested a global transform is that the compiler >>> seems >>> to do some checks for static properties during semantic analysis. >>> Therefore >>> you might need to add 'log' before semantic analysis if you want to >>> support >>> all ways that it could be accessed (qualified, unqualified, from the same >>> class, from other classes, etc.). But only global transforms can be run >>> before semantic analysis (i.e. in phase CONVERSION). >>> >> Ah. Sucky. Is this something I should open a JIRA on? Seems off to me. >> >> ~~ Robert Fischer, Smokejumper IT Consulting. >> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >> >> Check out my book, "Grails Persistence with GORM and GSQL"! >> http://www.smokejumperit.com/redirect.html >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?Since your latest example works for me, there must be something wrong with your setup. Therefore let me repeat the question: how to you build and run your code? And do the standard transforms (e.g. @Singleton) work for you? Agreed. But before investigating this any further, I'd like to find out why your transform doesn't work for you. Cheers, Peter
|
|
|
Re: Groovy AST not taking?I'm trying to do this as a Grails plugin. The standards work just fine.
I think my problem is that I need to compile the transform into a jar that lives in ./lib before I do the larger project compile. For this build issue, i've started that conversation on grails-user. ~~ Robert. Peter Niederwieser wrote: > > Robert Fischer wrote: >> Also, my errors were runtime, not compile-time. >> > Since your latest example works for me, there must be something wrong with > your setup. Therefore let me repeat the question: how to you build and run > your code? And do the standard transforms (e.g. @Singleton) work for you? > > > Robert Fischer wrote: >> And what seemed off is that there was validation >> happening on static calls at compile time -- after all, is it any >> different if I were to inject log >> to the class via metaclass mangling? >> > Agreed. But before investigating this any further, I'd like to find out why > your transform doesn't work for you. > > Cheers, > Peter > > > Robert Fischer wrote: >> Also, my errors were runtime, not compile-time. And what seemed off is >> that there was validation >> happening on static calls at compile time -- after all, is it any >> different if I were to inject log >> to the class via metaclass mangling? >> >> ~~ Robert. >> >> Peter Niederwieser wrote: >>> What is it that seems off to you? The fact that only global transforms >>> can >>> run in phase conversion? There is a good reason for this: It's not >>> possible >>> to tell if @WithLog is annotated with @GroovyASTTransformationClass >>> before >>> its type has been resolved (which happens in phase semantic analysis). >>> In general, writing a global transform isn't harder than writing a local >>> one. Your case is an exception because in phase conversion it's not >>> completely trivial to correctly identify a @WithLog annotation (which you >>> would get for free with a local transform). Before you go down this >>> route, I >>> suggest to verify my belief that phase semantic analysis, and therefore a >>> local transform, isn't good enough for your case. The example that didn't >>> seem to work with your original transform was: >>> >>> @WithLog >>> class Foo { >>> def foo() { >>> assert log != null // OK >>> assert Foo.log != null // compile error >>> } >>> } >>> >>> Cheers, >>> Peter >>> >>> >>> Robert Fischer wrote: >>>> I haven't run your tests, so I'm not sure what the result is. Since my >>>> error was a lack of "log" >>>> property, it sounds like this conversion problem was the issue. >>>> >>>>> No. The reason why I suggested a global transform is that the compiler >>>>> seems >>>>> to do some checks for static properties during semantic analysis. >>>>> Therefore >>>>> you might need to add 'log' before semantic analysis if you want to >>>>> support >>>>> all ways that it could be accessed (qualified, unqualified, from the >>>>> same >>>>> class, from other classes, etc.). But only global transforms can be run >>>>> before semantic analysis (i.e. in phase CONVERSION). >>>>> >>>> Ah. Sucky. Is this something I should open a JIRA on? Seems off to >>>> me. >>>> >>>> ~~ Robert Fischer, Smokejumper IT Consulting. >>>> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >>>> >>>> Check out my book, "Grails Persistence with GORM and GSQL"! >>>> http://www.smokejumperit.com/redirect.html >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe from this list, please visit: >>>> >>>> http://xircles.codehaus.org/manage_email >>>> >>>> >>>> >>>> >> -- >> ~~ Robert Fischer, Smokejumper IT Consulting. >> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >> >> Check out my book, "Grails Persistence with GORM and GSQL"! >> http://www.smokejumperit.com/redirect.html >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?How do I go about identifying the @WithLog annotation? What was I getting for free as a local
transform? ~~ Robert. Peter Niederwieser wrote: > What is it that seems off to you? The fact that only global transforms can > run in phase conversion? There is a good reason for this: It's not possible > to tell if @WithLog is annotated with @GroovyASTTransformationClass before > its type has been resolved (which happens in phase semantic analysis). > In general, writing a global transform isn't harder than writing a local > one. Your case is an exception because in phase conversion it's not > completely trivial to correctly identify a @WithLog annotation (which you > would get for free with a local transform). Before you go down this route, I > suggest to verify my belief that phase semantic analysis, and therefore a > local transform, isn't good enough for your case. The example that didn't > seem to work with your original transform was: > > @WithLog > class Foo { > def foo() { > assert log != null // OK > assert Foo.log != null // compile error > } > } > > Cheers, > Peter > > > Robert Fischer wrote: >> I haven't run your tests, so I'm not sure what the result is. Since my >> error was a lack of "log" >> property, it sounds like this conversion problem was the issue. >> >>> No. The reason why I suggested a global transform is that the compiler >>> seems >>> to do some checks for static properties during semantic analysis. >>> Therefore >>> you might need to add 'log' before semantic analysis if you want to >>> support >>> all ways that it could be accessed (qualified, unqualified, from the same >>> class, from other classes, etc.). But only global transforms can be run >>> before semantic analysis (i.e. in phase CONVERSION). >>> >> Ah. Sucky. Is this something I should open a JIRA on? Seems off to me. >> >> ~~ Robert Fischer, Smokejumper IT Consulting. >> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >> >> Check out my book, "Grails Persistence with GORM and GSQL"! >> http://www.smokejumperit.com/redirect.html >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?> How do I go about identifying the @WithLog annotation? What was I getting
> for free as a local transform? Within your visit method you can navigate thru the SourceUnit parameter and find all the classes defined. ClassNode is an AnnotatedNode, so then you just make a call to ClassNode#getAnnotation(String) and check for your annotation. Making it fool proof in an early phase is not simple b/c the annotation could be imported, static imported, or imported with an alias. The AstBuilder has to do something like this. I can point you to what I did if you want to see, but as you are discovering sometimes I make mistakes ( I didn't mean to lie in the wiki! ) Peter, thanks for the info about ASTTranformation.visit(). I will update the wiki page. -- Hamlet D'Arcy hamletdrc@... On Sat, Jun 27, 2009 at 9:07 PM, Robert Fischer<robert.fischer@...> wrote: > How do I go about identifying the @WithLog annotation? What was I getting > for free as a local transform? > > ~~ Robert. > > Peter Niederwieser wrote: >> >> What is it that seems off to you? The fact that only global transforms can >> run in phase conversion? There is a good reason for this: It's not >> possible >> to tell if @WithLog is annotated with @GroovyASTTransformationClass before >> its type has been resolved (which happens in phase semantic analysis). >> In general, writing a global transform isn't harder than writing a local >> one. Your case is an exception because in phase conversion it's not >> completely trivial to correctly identify a @WithLog annotation (which you >> would get for free with a local transform). Before you go down this route, >> I >> suggest to verify my belief that phase semantic analysis, and therefore a >> local transform, isn't good enough for your case. The example that didn't >> seem to work with your original transform was: >> >> @WithLog >> class Foo { >> def foo() { >> assert log != null // OK >> assert Foo.log != null // compile error >> } >> } >> >> Cheers, >> Peter >> >> >> Robert Fischer wrote: >>> >>> I haven't run your tests, so I'm not sure what the result is. Since my >>> error was a lack of "log" property, it sounds like this conversion >>> problem was the issue. >>> >>>> No. The reason why I suggested a global transform is that the compiler >>>> seems >>>> to do some checks for static properties during semantic analysis. >>>> Therefore >>>> you might need to add 'log' before semantic analysis if you want to >>>> support >>>> all ways that it could be accessed (qualified, unqualified, from the >>>> same >>>> class, from other classes, etc.). But only global transforms can be run >>>> before semantic analysis (i.e. in phase CONVERSION). >>>> >>> Ah. Sucky. Is this something I should open a JIRA on? Seems off to me. >>> >>> ~~ Robert Fischer, Smokejumper IT Consulting. >>> Enfranchised Mind Blog http://EnfranchisedMind.com/blog >>> >>> Check out my book, "Grails Persistence with GORM and GSQL"! >>> http://www.smokejumperit.com/redirect.html >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >>> >>> >> > > -- > ~~ Robert Fischer, Smokejumper IT Consulting. > Enfranchised Mind Blog http://EnfranchisedMind.com/blog > > Check out my book, "Grails Persistence with GORM and GSQL"! > http://www.smokejumperit.com/redirect.html > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --
Hamlet D'Arcy |
|
|
Re: Groovy AST not taking?Sure: point me to what you've done.
Sounds like some logic which should be moved into SourceUnit. ~~ Robert. Hamlet D'Arcy wrote: >> How do I go about identifying the @WithLog annotation? What was I getting >> for free as a local transform? > > Within your visit method you can navigate thru the SourceUnit > parameter and find all the classes defined. ClassNode is an > AnnotatedNode, so then you just make a call to > ClassNode#getAnnotation(String) and check for your annotation. Making > it fool proof in an early phase is not simple b/c the annotation could > be imported, static imported, or imported with an alias. The > AstBuilder has to do something like this. I can point you to what I > did if you want to see, but as you are discovering sometimes I make > mistakes ( I didn't mean to lie in the wiki! ) > > Peter, thanks for the info about ASTTranformation.visit(). I will > update the wiki page. > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?http://subversion.assembla.com/svn/AstBuilderPrototype/src/main/org/codehaus/groovy/ast/builder/transform/AstFactoryTransformation.groovy
In this file I'm looking for specific method invocations, but it shows a proof of concept. You annotation may be referenced via fully qualified classname, an import, a static import, or an alias. So be sure to walk through both: sourceUnit.getAST().imports sourceUnit.getAST().importPackages to see what was imported. I collect all the ways the class in question could be referenced and put it in a list. THen I just check all declarations to see if the class indeed is referenced. You'll need to walk through sourceUnit.getAST()?.getClasses Do you want to support this field on anonymous classes? Don't forget to walk through those if you need to! -- Hamlet D'Arcy hamletdrc@... On Sat, Jun 27, 2009 at 9:47 PM, Robert Fischer<robert.fischer@...> wrote: > Sure: point me to what you've done. > > Sounds like some logic which should be moved into SourceUnit. > > ~~ Robert. > > Hamlet D'Arcy wrote: >>> >>> How do I go about identifying the @WithLog annotation? What was I >>> getting >>> for free as a local transform? >> >> Within your visit method you can navigate thru the SourceUnit >> parameter and find all the classes defined. ClassNode is an >> AnnotatedNode, so then you just make a call to >> ClassNode#getAnnotation(String) and check for your annotation. Making >> it fool proof in an early phase is not simple b/c the annotation could >> be imported, static imported, or imported with an alias. The >> AstBuilder has to do something like this. I can point you to what I >> did if you want to see, but as you are discovering sometimes I make >> mistakes ( I didn't mean to lie in the wiki! ) >> >> Peter, thanks for the info about ASTTranformation.visit(). I will >> update the wiki page. >> > > -- > ~~ Robert Fischer, Smokejumper IT Consulting. > Enfranchised Mind Blog http://EnfranchisedMind.com/blog > > Check out my book, "Grails Persistence with GORM and GSQL"! > http://www.smokejumperit.com/redirect.html > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --
Hamlet D'Arcy |
|
|
Re: Groovy AST not taking?Anonymous classes are part of the sourceUnit.getAST().classes collection, aren't they?
~~ Robert. Hamlet D'Arcy wrote: > http://subversion.assembla.com/svn/AstBuilderPrototype/src/main/org/codehaus/groovy/ast/builder/transform/AstFactoryTransformation.groovy > > In this file I'm looking for specific method invocations, but it shows > a proof of concept. > > You annotation may be referenced via fully qualified classname, an > import, a static import, or an alias. So be sure to walk through both: > sourceUnit.getAST().imports > sourceUnit.getAST().importPackages > to see what was imported. > > I collect all the ways the class in question could be referenced and > put it in a list. THen I just check all declarations to see if the > class indeed is referenced. > > You'll need to walk through sourceUnit.getAST()?.getClasses > > Do you want to support this field on anonymous classes? Don't forget > to walk through those if you need to! > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?Robert Fischer schrieb:
> Anonymous classes are part of the sourceUnit.getAST().classes > collection, aren't they? as for Closures, no, but then they are ClosureExpressions. And I guess they are not of interest to you. As for real inner classes, yes, but only in 1.7. And for AIC, currently they are added, but this is not fixed in stone yet Note: "real" anonymous inner classes do exist for 1.7 only bye blackdrag -- Jochen "blackdrag" Theodorou The Groovy Project Tech Lead (http://groovy.codehaus.org) http://blackdragsview.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?> Robert Fischer tweets:
> @aalmiray ASTs *would* be great if there was any kind of documentation or any kind of reasonable error handling/verification. What parts would you most like to see improved? On Sun, Jun 28, 2009 at 5:35 AM, Jochen Theodorou<blackdrag@...> wrote: > Robert Fischer schrieb: >> >> Anonymous classes are part of the sourceUnit.getAST().classes collection, >> aren't they? > > as for Closures, no, but then they are ClosureExpressions. And I guess they > are not of interest to you. As for real inner classes, yes, but only in 1.7. > And for AIC, currently they are added, but this is not fixed in stone yet > > Note: "real" anonymous inner classes do exist for 1.7 only > > bye blackdrag > > -- > Jochen "blackdrag" Theodorou > The Groovy Project Tech Lead (http://groovy.codehaus.org) > http://blackdragsview.blogspot.com/ > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- Hamlet D'Arcy hamletdrc@... --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --
Hamlet D'Arcy |
|
|
Re: Groovy AST not taking?Pretty much any of it. What the compilation order is, and why people would pick different stages.
Since there are apparently added difficulties at certain stages, what those difficulties are and how to work with/around them would be great. How to decide between doing a local and global transform. A couple examples of standard use cases. As for error handling -- again, pretty much any of it. A compiler flag to signal what transforms are being applied would be a good start. I would add more, but apparently I can't even get the ASTs to take in Grails (see grails-user for more on that). The reasonable error handling/verification comment came in part because it's increasingly clear that I'll need to get into the IDE slog if I'm going to continue to do AST development, which is too bad -- I've enjoyed being able to do development with 2 GB of ancient RAM and have it still be snappy. ~~ Robert. Hamlet D'Arcy wrote: >> Robert Fischer tweets: >> @aalmiray ASTs *would* be great if there was any kind of documentation or any kind of reasonable error handling/verification. > > What parts would you most like to see improved? > > > On Sun, Jun 28, 2009 at 5:35 AM, Jochen Theodorou<blackdrag@...> wrote: >> Robert Fischer schrieb: >>> Anonymous classes are part of the sourceUnit.getAST().classes collection, >>> aren't they? >> as for Closures, no, but then they are ClosureExpressions. And I guess they >> are not of interest to you. As for real inner classes, yes, but only in 1.7. >> And for AIC, currently they are added, but this is not fixed in stone yet >> >> Note: "real" anonymous inner classes do exist for 1.7 only >> >> bye blackdrag >> >> -- >> Jochen "blackdrag" Theodorou >> The Groovy Project Tech Lead (http://groovy.codehaus.org) >> http://blackdragsview.blogspot.com/ >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> > > > -- ~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Check out my book, "Grails Persistence with GORM and GSQL"! http://www.smokejumperit.com/redirect.html --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Groovy AST not taking?More documentation would certainly help. But I think we have covered most if not all of the points you are raising in this thread. For "standard" use cases see the built-in transformations. Also Guillaume's "What's new in Groovy 1.6" article is helpful. The compiler does provide information if it encounters a problem with a transform (e.g. it complains if you try to run a local transform in phase conversion). Your problem seems to be that there is something wrong with your build, and therefore the compiler doesn't even know about your transform. How should it then provide diagnostic information? Or maybe it's a problem with Grails. Why not try with plain Groovy first? Cheers, Peter |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |