Groovy
  1. Groovy
  2. GROOVY-2827

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.5.6
    • Fix Version/s: None
    • Component/s: ast builder
    • Labels:
      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;
              }
      }
      

        Issue Links

          Activity

          Xavier Sautejeau created issue -
          Guillaume Delcroix made changes -
          Field Original Value New Value
          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;
                  }
          }
          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
          {code}
          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 "";
          }
          {code}
          --- TagType.java
          {code}
          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";
          }
          {code}
          --- GroovyClassWithAnnotationsAndConstants.groovy
          {code}
          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;
                  }
          }
          {code}
          Paul King made changes -
          Link This issue is duplicated by GROOVY-3278 [ GROOVY-3278 ]
          Paul King made changes -
          Resolution Duplicate [ 3 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12731847 ] Default workflow, editable Closed status [ 12743762 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12973421 ] Default workflow, editable Closed status [ 12980648 ]

            People

            • Assignee:
              Guillaume Delcroix
              Reporter:
              Xavier Sautejeau
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development