[
https://issues.apache.org/jira/browse/GROOVY-10713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17574425#comment-17574425
]
Paul King commented on GROOVY-10713:
------------------------------------
[~yihtserns] The behavior you are observing is "as designed". It was before my
time but I think it was an assumption that the bulk of transforms won't need to
modify such code so as a performance optimization, let most transforms skip
over such code and ones that do need to transform such code would need the
extra manual code like you showed. But I have no idea whether any performance
benchmarks were done at the time or whether they would still hold now.
[~emilles] If we do make changes here, we should keep track of performance to
make sure it isn't impacted too much. There will be other places in the
codebase which, although shouldn't be broken, could be simplified. Like the
issues you linked (at least). We can create new issues to progress any changes
like that.
> 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)