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

Can't define a target not including TYPE for annotation definitions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-2
    • 1.6-rc-1, 1.7-beta-1
    • None
    • None

    Description

      Currently, in 1.6 and 1.7, it is not possible to define annotations whose target elements don't include ElementType.TYPE.
      So the following example will not compile, saying that it's not allowed on TYPE.

      @Retention(RUNTIME)
      @Target([METHOD, FIELD])
      @interface MyAnnotation { }
      

      The check of target is done on the annotation definition itself, although it should apply only to the elements which are annotated themselves.

      Another example of annotation definition that couldn't compile in Groovy 1.6/1.7 is the @OneToMany annotation of JPA:

      import java.lang.annotation.*
      import static java.lang.annotation.RetentionPolicy.*
      import static java.lang.annotation.ElementType.*
      
      enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH }
      
      @Retention(RUNTIME)
      @Target([METHOD, FIELD])
      @interface OneToMany {
          CascadeType[] cascade()
          // ... etc ...
      }
      

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: