You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2016/10/25 21:57:58 UTC
[jira] [Updated] (GROOVY-7975) Use of static final field in an
annotation element causes compile errors
[ https://issues.apache.org/jira/browse/GROOVY-7975?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-7975:
--------------------------------
Description:
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.
} 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();
}
}
was:
Using a class constant (static final field) in an annotation causes compile errors. This works in Java and the fix is pretty small.
Ex:
class C {
public static final String VALUE = 'rawtypes'
@SuppressWarnings(VALUE)
def method() {
}
}
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.
```java
} 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();
}
}
```
> 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
> 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.
> } 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();
> }
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)