[
https://issues.apache.org/jira/browse/GROOVY-10713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17574673#comment-17574673
]
Yih Tsern commented on GROOVY-10713:
------------------------------------
[~paulk] [~emilles] reading all these comments made me feel like I'll be
satisfied if we just note this "gotcha(?)" in ClassCodeExpressionTransformer's
javadoc and/or [the
doc|https://groovy-lang.org/metaprogramming.html#_classcodeexpressiontransformer].
Since this behaviour is super, super old, I'm worried that the fix may result
in the same expression being visited/transformed twice for any subclasses (in
Groovy or user's codebase) that have already applied their own workaround/fix
to deal with this behaviour.
> ClassCodeExpressionTransformer ignoring Expressions within
> ClosureExpression.code
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-10713
> URL: https://issues.apache.org/jira/browse/GROOVY-10713
> Project: Groovy
> Issue Type: Bug
> Reporter: Yih Tsern
> Assignee: Eric Milles
> Priority: Minor
>
> E.g.
> {code:java}
> class SomeClass {
> def someClosureField = {
> // Expressions are NOT visited by
> ClassCodeExpressionTransformer.transform(Expression)
> }
>
> def someMethod() {
> // Expressions are visited by
> ClassCodeExpressionTransformer.transform(Expression)
> 3.times {
> // Expressions are NOT visited by
> ClassCodeExpressionTransformer.transform(Expression)
> }
> def someClosureVar = {
> // Expressions are NOT visited by
> ClassCodeExpressionTransformer.transform(Expression)
> }
> }
> }
> {code}
> Is this current behaviour by design or is it a bug? If it is by design, it
> seems to be quite a gotcha (also caused GROOVY-6932 & GROOVY-6434) - probably
> should be noted in [the
> doc|https://groovy-lang.org/metaprogramming.html#_classcodeexpressiontransformer]?
>
> Below is my current workaround(??) - is this the expected way to work with
> ClassCodeExpressionTransformer?
> {code:java}
> class MyAstTransformer extends ClassCodeExpressionTransformer {
> Expression transform(Expression expression) {
> // Some code to deal with specific expression classes...
> ...
>
> if (expression instanceof ClosureExpression) {
> expression.visit(this)
> }
> super.transform(expression);
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)