groovy
  1. groovy
  2. GROOVY-4683 static import collection task
  3. GROOVY-4287

CLONE - import of static nested classes in external groovy files is broken

    Details

    • Type: Sub-task Sub-task
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.7.3
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Splitting off problematic but critical case of resolving static nested and inner classes in external groovy files from GROOVY-4267. Copying Roshan's example from that issue:

      Test.groovy
      import static Outer.*
      // import static Outer.Inner // also fails
      // import Outer.Inner        // also fails
      
      assert Inner.class.name != null
      
      Outer.groovy
      class Outer {
          static class Inner {}
      }
      

      Output:

      Caught: groovy.lang.MissingPropertyException: No such property: Inner for class: Test
              at Test.run(Test.groovy:4)
      

      Error message is slightly different for non-static import:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Test.groovy: 2: unable to resolve class Outer.Inner
       @ line 2, column 1.
         import Outer.Inner
         ^
      1 error
      

        Activity

        Paul King made changes -
        Field Original Value New Value
        Assignee Paul King [ paulk ]
        Fix Version/s 1.8-beta-1 [ 16013 ]
        Fix Version/s 1.7.4 [ 16563 ]
        Description Given this Java class (note the _static_ inner class):
        {code}
        package pkg;

        public class Outer {
            public static class Inner {}
        }
        {code}
        The inner class can be printed from Java using this:
        {code}
        import pkg.Outer.Inner;
        //import static pkg.Outer.Inner;

        public class Main {
            public static void main(String[] args) {
                System.out.println(Inner.class.getName());
            }
        }
        {code}
        Note that both the non-static or static version (shown commented out) will work.

        For Groovy, the non-static version works:
        {code}
        import pkg.Outer.Inner

        println Inner.class.name
        {code}

        but the static version doesn't:
        {code}
        import static pkg.Outer.Inner

        println Inner.class.name
        {code}
        instead, it fails with:
        {noformat}
        Caught: groovy.lang.MissingPropertyException: No such property: Inner for class: TestStaticImport
        {noformat}
        Splitting off problematic but critical case of resolving static nested and inner classes in external groovy files from GROOVY-4267. Copying Roshan's example from that issue:

        {code:title=Test.groovy}
        import static Outer.*
        // import static Outer.Inner // also fails
        // import Outer.Inner // also fails

        assert Inner.class.name != null
        {code}

        {code:title=Outer.groovy}
        class Outer {
            static class Inner {}
        }
        {code}

        Output:
        {noformat}
        Caught: groovy.lang.MissingPropertyException: No such property: Inner for class: Test
                at Test.run(Test.groovy:4)
        {noformat}
        Error message is slightly different for non-static import:
        {noformat}
        org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        Test.groovy: 2: unable to resolve class Outer.Inner
         @ line 2, column 1.
           import Outer.Inner
           ^
        1 error
        {noformat}
        Component/s Compiler [ 13529 ]
        Paul King made changes -
        Summary CLONE - Unable to import static for static nested classes in external groovy files CLONE - import of static nested classes in external groovy files is broken
        blackdrag blackdrag made changes -
        Parent GROOVY-4683 [ 122027 ]
        Issue Type Bug [ 1 ] Sub-task [ 7 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul King
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: