Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
1.5.6
-
None
-
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
- is duplicated by
-
GROOVY-3278 Using referenced String constant as value of Annotation causes compile error
- Closed