[
https://issues.apache.org/jira/browse/GROOVY-7975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16674366#comment-16674366
]
ASF GitHub Bot commented on GROOVY-7975:
----------------------------------------
GitHub user paulk-asert opened a pull request:
https://github.com/apache/groovy/pull/819
GROOVY-7975/GROOVY-3278/GROOVY-7854: improved accessing of constants …
…for annotation attributes
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paulk-asert/groovy annotationConstantFixes
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/819.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #819
----
commit 236e4d5c06cec60840209e0b3c83512a90badfda
Author: Paul King <paulk@...>
Date: 2018-11-04T10:10:43Z
GROOVY-7975/GROOVY-3278/GROOVY-7854: improved accessing of constants for
annotation attributes
----
> Use of static final field in an annotation element causes compile errors
> ------------------------------------------------------------------------
>
> Key: GROOVY-7975
> URL: https://issues.apache.org/jira/browse/GROOVY-7975
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.4.7
> Reporter: Eric Milles
> Priority: Major
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> Using a class constant (static final field) in an annotation causes compile
> errors. This works in Java and the fix is pretty small.
> Ex:
> {code}
> class C {
> public static final String VALUE = 'rawtypes'
> @SuppressWarnings(VALUE)
> def method() {
> }
> }
> {code}
> This is a bit contrived to be concise. But we have examples in our code
> where Callable impls are tagged with a name, which is defined as a static
> constant on each class.
> The fix appears to be pretty minor. In
> ResolveVisitor.transformInlineConstants, a case for VariableExpression does
> the trick for me.
> {code}
> } else if (exp instanceof VariableExpression) {
> VariableExpression ve = (VariableExpression) exp;
> if (ve.getAccessedVariable() instanceof FieldNode) {
> FieldNode fn = (FieldNode) ve.getAccessedVariable();
> if (!fn.isEnum() && fn.isStatic() && fn.isFinal() &&
> fn.getInitialValueExpression() instanceof
> ConstantExpression) {
> return fn.getInitialValueExpression();
> }
> }
> ....
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)