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

groovy compiler ignores import * for static nested classes in java sources

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.3
    • 4.0.0-alpha-1, 3.0.5, 2.5.17
    • Compiler
    • None

    Description

      (using Groovy 1.8.3, JVM 1.6.0_23 OpenJDK)

      Given this class:

      Foo.java
      package org.test;
      
      public class Foo {
          public static class Bar {
              String message;
              
              public Bar(String message) {
                  this.message = message;
              }
          }
          public static class Cat {
              Integer amount;
      
              public Cat(Integer amount) {
                  this.amount = amount;
              }
          }
      }
      

      Groovy code can import both of these static nested classes like this:

      import static org.test.Foo.*
      

      However, in Java they are imported like this:

      import org.test.Foo.*;
      

      Using the Groovy compiler to compile any Java files which do the above will result in the following error if any of the static nested classes are used:

      App.java: 9: unable to resolve class Bar 
       @ line 9, column 13.
         		Bar bar = new Bar("Hello");
      

      Is this expected? If so, is there a known workaround (or maybe I'm just doing it wrong...)?

      Attachments

        Activity

          People

            emilles Eric Milles
            clarkdave Dave Clark
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h