Announcement Announcement Module
Collapse
No announcement yet.
Annotations with closure causes error message in Groovy editor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annotations with closure causes error message in Groovy editor

    Hi!

    I am using gcontracts in my grails projects for asserting method parameters. e.g.

    @Requires({ groupId })
    def List getFormatSelection(def groupId) {
    //impl
    }


    This causes the error message: "Groovy:Only classes can be used for attribute 'value' in @org.gcontracts.annotations.Requires" (see screenshot attachment)

    Any idea why this is displayed?

    Otherwise, the annotation is working as expected running associated unit tests within STS and from Grails command line.

    Jira Bug: https://issuetracker.springsource.com/browse/STS-1154

    Much appreciated,

    Andreas

  • #2
    Hi,

    As I mentioned on the bug report, this feature to use closures inside of annotations is only available in Groovy 1.8, which is not supported by Groovy-Eclipse yet.

    Comment


    • #3
      Hi Andrew!

      Thanks so much for looking into it.

      Strange thing though, my classes containing these annotations compile (grails compile) just fine (outside STS) and at runtime it works as expected. I am using Grails version 1.3.2 which comes with Groovy 1.7.3.

      Any idea when Groovy-Eclipse will be updated to 1.8?

      Thanks,

      Andreas

      Comment


      • #4
        Groovy 1.8 is still in beta and not quite stable enough yet. When it becomes stable enough to use in production, we will start the integration work for Groovy-Eclipse.

        Also, I am surprised that the code you include works on the command line or in Grails. In the bug report, for STS-1154, I tried on the command line and received a syntax error. I also just tried on the groovy web console (http://groovyconsole.appspot.com/) and got a syntax error.

        Comment


        • #5
          Hi Andrew!

          Indeed strange that it is working as expected in a Grails environment. I haven't tried it with pure groovy e.g. groovy web console.

          As per the author of gcontracts, the grails plugin, it only requires Groovy 1.7.

          Thanks,

          Andreas

          Comment


          • #6
            Ahh...I see now. gcontracts uses an ast transform to allow this syntax. So, yes, this should work in STS.

            Just a question, though. The error that you see is it an error that appears in the editor only, or does it show up in the Problems view as well?

            In order to help ensure that reconciling works (ie- eager parsing in the editor), we have had to disable certain kinds of AST transforms in the editor (although they are supported by the compiler).

            Comment


            • #7
              Good question and something I found a bit strange too: Error appears only in the groovy editor and does not show up in the Problems view.

              Much appreciated!

              Andreas

              Comment


              • #8
                That confirms my suspicion that the problem is related to reconciling and not the compiler. I believe that your code should run fine.

                I reopened the jira issue and we will have a deeper look at it.

                Comment

                Working...
                X