Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7155

Java stub generation fails on statically imported field used as annotation parameter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.7
    • None
    • None

    Description

      groovyc fails to generate compiling Java stub for Groovy classes which use statically imported field as an annotation parameter. E.g.

      import static stub.Constants.CONST1
      
      class GroovyToStub {
          @GroovyAnn(CONST1)  //fails
          void methodToStub() {
          }
      }
      
      /tmp/groovy-java-stubs/stub/GroovyToStub.java:21: error: cannot find symbol
      @stub.GroovyAnn(value=CONST1) public  void methodToStub() { }
                            ^
        symbol:   variable CONST1
        location: class GroovyToStub
      1 error
      startup failed:
      Compilation failed; see the compiler error output for details.
      
      1 error
      

      A simple workaround is to use Constants.CONST1 with normal import, but in some cases it can reduce original code readability.

      Looking briefly at the code there could be missing "printing" static imports in JavaStubGenerator.printImports().

      Sample project reproducing problem:
      https://github.com/szpak/code-examples-and-poc/tree/master/groovy-joint-compilation-issue

      Attachments

        Activity

          People

            emilles Eric Milles
            szpak Marcin Zajaczkowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: