-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aliases can not be used in annotaions #260
Comments
It is this bit from MemberValuePair private Expression repairClassLiteralReference(Expression exp, BlockScope scope, TypeBinding[] valueType) {
TypeBinding vtb = null;
if (exp instanceof SingleNameReference) {
vtb = exp.resolveType(scope);
SingleNameReference ref = (SingleNameReference) exp;
if (vtb != null && Arrays.equals(ref.token, vtb.sourceName())) {
return new ClassLiteralAccess(ref.sourceEnd, new SingleTypeReference(ref.token, ((long) ref.sourceStart) << 32 | ref.sourceEnd));
}
|
Checked this one, it fixed all cases, but my test example is still failing: package test
import test.TestClass // comment this and everything will be fine
import test.TestClass as ALIAS
class Test {
@TestAnnotation(value = [ALIAS])
static main(args) {
println 'hello groovy'
}
} If both imports are present, then ALIAS is still not a class. If only aliased import here - everything working fine. I do not know if it as a valid case, but looks like it is. |
The repeated use of TestClass in your example is a general issue with imports. If you import a type and alias it in a compilation unit, you will get the resolution errors if the 2nd is used in annotations, extends, implements, throws, generics, method params/return type and fields. That is, any place a type reference is copied into the Java model, this will occur. |
Thanks for the explanation. In this case, this can be considered as done. |
I am trying out a possible solution to the import issue. The commit will be linked here if I come up with a fix. |
If your annotation is expecting class value and you aliased it, using alias will raise an error, while using original class name - not. It was working perfectly fine in the past.
I am using groovy eclipse: 2.9.2.xx-201701250356-e46
Here is an example:
Groovy eclipse will complain about using alias, but using original class name will work fine. But in both cases code will run fine.
The text was updated successfully, but these errors were encountered: