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

Unable to import static for static inner classes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.3
    • Fix Version/s: 1.7.4, 1.8-beta-1
    • Component/s: None
    • Labels:
      None

      Description

      This issue tracks partial implementation of this functionality. See note at end of description.


      Given this Java class (note the static inner class):

      package pkg;
      
      public class Outer {
          public static class Inner {}
      }
      

      The inner class can be printed from Java using this:

      import pkg.Outer.Inner;
      //import static pkg.Outer.Inner;
      
      public class Main {
          public static void main(String[] args) {
              System.out.println(Inner.class.getName());
          }
      }
      

      Note that both the non-static or static version (shown commented out) will work.

      For Groovy, the non-static version works:

      import pkg.Outer.Inner
      
      println Inner.class.name
      

      but the static version doesn't:

      import static pkg.Outer.Inner
      
      println Inner.class.name
      

      instead, it fails with:

      Caught: groovy.lang.MissingPropertyException: No such property: Inner for class: TestStaticImport
      

      NOTE: The initial implementation of functionality for this issue works for external jars/classes on the classpath and for classes included in the same file but doesn't work for the critical case of external groovy files. As that case also doesn't work for attempts to import using a non-static variation of import, I think it is worthy of its own issue and so GROOVY-4287 has been created to track remaining work.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              paulk Paul King
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: