[
https://issues.apache.org/jira/browse/GROOVY-10713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17580275#comment-17580275
]
ASF GitHub Bot commented on GROOVY-10713:
-----------------------------------------
paulk-asert merged PR #1762:
URL: https://github.com/apache/groovy/pull/1762
> 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)