groovy
  1. groovy
  2. GROOVY-3481

Groovy Support for annotations on local variable declarations

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7-beta-1
    • Fix Version/s: 1.7.0
    • Component/s: ast builder
    • Labels:
      None
    • Environment:
      All
    • Number of attachments :
      1

      Description

      Groovy should support annotations on local variable declarations. It is syntactically legal to annotate a local variable, but the AST produced does not carry that annotation.

      My use case with the AST builder. Either we'd like to annotate a local variable, like this:

      @AstSource(CompilePhase.CONVERSION)
      def source = { println "compiled on: ${new Date()}" }
      

      Or annotate a property within a closure (which is a DeclarationExpression), like this:

      def result = new AstBuilder().build {
                 phase = CompilePhase.CONVERSION
                 @AstSource
                 source = { println "compiled on: ${new Date()}" }
       }
      

      A getAnnotations() method should probably be added to DeclarationExpression to support this.

        Issue Links

          Activity

          Hide
          Guillaume Laforge added a comment -

          Can it be closed?

          Show
          Guillaume Laforge added a comment - Can it be closed?
          Hide
          Paul King added a comment -

          I haven't done anything yet to make local AST transforms in Scripts work.
          So if you have, e.g.:

          @ClassScope foo
          

          in a script, then ClassScope won't have been resolved at the time the script is processed and will be basically ignored. I probably won't get time to look at this until after I get back from SpringOne2GX.

          Show
          Paul King added a comment - I haven't done anything yet to make local AST transforms in Scripts work. So if you have, e.g.: @ClassScope foo in a script, then ClassScope won't have been resolved at the time the script is processed and will be basically ignored. I probably won't get time to look at this until after I get back from SpringOne2GX.
          Hide
          Hamlet D'Arcy added a comment -

          This change still requires a lot of the Expression subclasses to extend AnnotatedNode so that the annotations can be retrieved during a transformation.

          Show
          Hamlet D'Arcy added a comment - This change still requires a lot of the Expression subclasses to extend AnnotatedNode so that the annotations can be retrieved during a transformation.
          Hide
          Paul King added a comment -

          Split remaining work into its own issue.

          Show
          Paul King added a comment - Split remaining work into its own issue.
          Hide
          Paul King added a comment -

          Initial part of this issue has been completed.

          Show
          Paul King added a comment - Initial part of this issue has been completed.

            People

            • Assignee:
              Paul King
              Reporter:
              Hamlet D'Arcy
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: