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

org.codehaus.groovy.ast.expr.PropertyExpression when using external constants in annotations

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.5.6
    • None
    • ast builder
    • None

    Description

      On annotation attributes, when assigning a constant with a "." in its name (as is the case when the constant is defined in a different class than the one being compiled), groovy generates org.codehaus.groovy.ast.expr.PropertyExpression.

      See simple test case below.

      — Tag.java

      package pkg;
      
      import java.lang.annotation.Target;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      
      
      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.METHOD,ElementType.FIELD})
      public @interface Tag {
              String value() default "";
      }
      

      — TagType.java

      package pkg;
      
      import org.apache.log4j.Logger;
      
      public class TagType {
              private final static Logger theLogger = Logger.getLogger(TagType.class);
              public static final String TAG_1 = "tag_1";
              public static final String TAG_2 = "tag_2";
      }
      

      — GroovyClassWithAnnotationsAndConstants.groovy

      package pkg;
      
      import pkg.Tag;
      import pkg.TagType
      
      class GroovyClassWithAnnotationsAndConstants {
      
              int myIntField;
      
              @Tag( value = TagType.TAG_1) // this will not compile and generate org.codehaus.groovy.ast.expr.PropertyExpression
              //@Tag( value = "tag_1") //the commented version, which uses a string literal does compile
              public int getIntField() {
                      return myIntField;
              }
      
              public void setIntField(int value) {
                      myIntField = value;
              }
      }
      

      Attachments

        Issue Links

          Activity

            People

              guillaume Guillaume Sauthier
              xsautejeau Xavier Sautejeau
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: