You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/07/05 16:59:00 UTC
[jira] [Commented] (GROOVY-7712) annotations for AST transformations should be inspected at each phase
[ https://issues.apache.org/jira/browse/GROOVY-7712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17562760#comment-17562760 ]
Eric Milles commented on GROOVY-7712:
-------------------------------------
Yes, if you add to the AST, including a transform annotation, you should be using "cn.addTransform(...)" if your code runs after {{ASTTransformationVisitor}}. This is an intermediate/advanced case, but there are examples of this -- most commonly adding static compilation to a new method:
{code:java}
MethodNode mn = ...
AnnotationNode an = new AnnotationNode(COMPILESTATIC_CLASSNODE);
mn.addAnnotation(an);
cn.addTransform(StaticCompileTransformation.class, an);
cn.addMethod(mn);
{code}
[~paulk] Is this something that should be documented or is there a guide out there that can be referenced?
> 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
> Priority: Major
>
> 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
(v8.20.10#820010)