[ 
https://issues.apache.org/jira/browse/GROOVY-7712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15060151#comment-15060151
 ] 

Christopher Smith edited comment on GROOVY-7712 at 12/16/15 3:42 PM:
---------------------------------------------------------------------

It appears that this *may* be possible by finding the {{ClassNode}} to which 
the {{annotatedNode}} belongs (which might be the node for a class itself), 
then calling {{cNode.addTransform(OtherTransform.class, newAnnotationNode)}}. 
If this is the canonical way to do this, it is entirely nonobvious; I would be 
happy to help document it but am not sure where all might need to be touched.

This approach still does not permit successfully adding transformations to be 
processed later in this phase; it looks like {{getTransforms(phase)}} is itself 
called just once per phase.


was (Author: chrylis):
It appears that this *may* be possible by finding the {{ClassNode}} to which 
the {{annotatedNode}} belongs (which might be the node for a class itself), 
then calling {{cNode.addTransform(OtherTransform.class, newAnnotationNode)}}. 
If this is the canonical way to do this, it is entirely nonobvious; I would be 
happy to help document it but am not sure where all might need to be touched.

> annotations for AST transformations should be inspected at each phase
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-7712
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7712
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.5
>            Reporter: Christopher Smith
>
> It's possible that this is simply underdefined behavior, but it feels like a 
> bug, and I propose that the correct behavior should be as described below.
> In an AST transformation running during the {{SEMANTIC_ANALYSIS}} phase, I 
> can add an annotation to an element that should trigger another 
> transformation running during a later phase (such as {{CANONICALIZATION}}):
> {code}
> @Override
> protected void doVisit(AnnotationNode annotationNode, AnnotatedNode 
> annotatedNode) {
>     annotatedNode.addAnnotation(new 
> AnnotationNode(make(OtherTransform.class)));
> }
> {code}
> This successfully adds {{@OtherTransform}} to the node (visible in the class 
> output with the appropriate retention policy), but the transformation tied to 
> {{@OtherTransform}} does not execute; it works fine if {{@OtherTransform}} is 
> explicitly annotated on the node in the source code.
> It appears that all annotations are scanned once for transformations by the 
> {{ASTTransformationCollectorCodeVisitor}} and queued for processing, so that 
> annotations added later are never scanned. Instead, a transformation 
> operating in an earlier phase ought to be able to leave behind an instruction 
> for one to be applied in a later phase, at a minimum through a mechanism to 
> imperatively notify the compilation unit that the transformation should be 
> applied to the node.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to