Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10713

ClassCodeExpressionTransformer ignoring Expressions within ClosureExpression.code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Information Provided
    • None
    • None
    • None
    • None

    Description

      E.g.

      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)
          }
        }
      }
      

      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?

       

      Below is my current workaround(??) - is this the expected way to work with ClassCodeExpressionTransformer?

      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);
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              yihtserns Yih Tsern
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: