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

Problem With Stub Generator And Static Import Aliases

    XMLWordPrintableJSON

Details

    Description

      The attached staticimportalias.zip contains the following:

      src/main/groovy/demo/helper/SomeHelper.java
      package demo.helper;
      
      public class SomeHelper {
          public static final int ANSWER = 42;
      }
      
      src/main/groovy/demo/SomeClass.groovy
      package demo
      
      import static demo.helper.SomeHelper.ANSWER as MAGIC_NUMBER
      
      class SomeClass {
      
          static int getMagicNumber() {
              MAGIC_NUMBER
          }
      }
      
      src/main/groovy/demo/SomeJavaClass.java
      package demo;
      
      public class SomeJavaClass {
          SomeClass sc;
      }
      

      The code will not compile with Groovy 2.4.4:

      $ ./gradlew clean cG
      :clean
      :compileJava UP-TO-DATE
      :compileGroovy
      /Users/jeff/staticimportalias/build/tmp/groovy-java-stubs/demo/SomeClass.java:9: error: cannot find symbol
      import static demo.helper.SomeHelper.MAGIC_NUMBER;
      ^
        symbol:   static MAGIC_NUMBER
        location: class
      1 error
      startup failed:
      Compilation failed; see the compiler error output for details.
      
      1 error
      
      :compileGroovy FAILED
      
      FAILURE: Build failed with an exception.
      
      * What went wrong:
      Execution failed for task ':compileGroovy'.
      > Compilation failed; see the compiler error output for details.
      
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
      
      BUILD FAILED
      
      Total time: 4.467 secs
      

      If I edit the top level build.gradle to use Groovy 2.4.3, the code compiles.

      Attachments

        1. staticimportalias.zip
          50 kB
          Jeff Scott Brown

        Issue Links

          Activity

            People

              keegan Keegan Witt
              jeffscottbrown Jeff Scott Brown
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: