Skip to content
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

Static class literal in annotation value shows false compilation error #256

Closed
atrepczik opened this issue Jan 20, 2017 · 6 comments
Closed

Comments

@atrepczik
Copy link

When using the shortened Groovy syntax for class literals as values in Annotations like in the code below

package issue

@Issue(InnerClass)
class IssueMain {

    static class InnerClass {
    }

    static main(args) {
        println 'It works!'
    }
}

@interface Issue {
    Class value()
}

Groovy-Eclipse shows a compilation error in line 3 (InnerClass cannot be resolved or is not a field), despite this being valid Groovy code that compiles and runs fine. When adding a.class suffix to InnerClass, the error disappears.

I used the the following to demonstrate the issue:
Spring Tool Suite

Version: 3.8.3.RELEASE
Build Id: 201612191351
Platform: Eclipse Neon.2 (4.6.2)

Groovy-Eclipse Feature 2.9.2.xx-201701200229-e46

@eric-milles
Copy link
Member

What version of Groovy? This case should work and is tested for.

@atrepczik
Copy link
Author

I tried it with version 2.4.7 and 2.4.8. Both versions show said error in the IDE window.

@eric-milles
Copy link
Member

Can you also look in the installation details dialog and say what version the plug-in org.eclipse.jdt.core is at? And if you run Help > Check for Updates and freshen Groovy-Eclipse, does the problem remain?

@atrepczik
Copy link
Author

The plugin org.eclipse.jdt.core is at 3.12.2.xx-201701232340-e46. I updated Groovy-Eclipse through Help > Check for Updates but the problem still remains. I was also able to reproduce the problem with a fresh Eclipse Neon.2 installation downloaded from eclipse.org and installing nothing but the Groovy-Eclipse plugin.

@eric-milles
Copy link
Member

I did not notice the inner class the first time through. That seems to be the source of the problem. You can replace @Issue(InnerClass) with @Issue(IssueMain.InnerClass) as a temporary workaround until I can get this fixed.

@eric-milles
Copy link
Member

I did some additional testing and found that Java does not support this kind of resolution in a type annotation for fields or inner classes. I filed this bug against groovy core: https://issues.apache.org/jira/browse/GROOVY-8063

I did find a way to make the inner class resolution succeed, but I am hesitant to enable it since there is a viable workaround using a qualifier or an import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants