GRECLIPSE
  1. GRECLIPSE
  2. GRECLIPSE-983

Inner classes created in Groovy cause compile errors when referenced from Java

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1Release
    • Fix Version/s: 2.5.2.Release
    • Component/s: Compiler Integration
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Inner classes compiled in groovy cause compile errors in java in eclipse. The errors go away when doing a full project clean but come right back as soon as the java file that is referencing the inner class is changed (rebuilt). This basically makes it impossible to use inner classes in joint java/groovy projects

      See the following example:

      //groovy code
      class Outer {
        static class Inner {}
      }
      
      //java code
      public class Client {
        { new Outer.Inner(); }
      }
      

      As I said if I do a project clean everything compiles. As soon as I edit and save Client.java eclipse gives me the following error:

      Outer.Inner cannot be resolved to a type	Client.java	/GroovyTest/src/main/java	line 3	Java Problem
      

        Activity

        Hide
        Andrew Eisenberg added a comment -

        Still a problem, or at least the original comment is still a problem.

        Travis, have you been able to narrow down the problem described in your comment? I have not been able to reproduce.

        Show
        Andrew Eisenberg added a comment - Still a problem, or at least the original comment is still a problem. Travis, have you been able to narrow down the problem described in your comment? I have not been able to reproduce.
        Hide
        Travis added a comment -

        I have not had a chance to give this a test. Most of our team has switched to using Intellij so I haven't heard any complaints of this lately... We do plan on using the eclipse compiler via maven at that point so this could affect us then.

        The original issue had to do with the core groovy compiler not compiling static inner classes correctly. Now it seems that is fixed but maybe there is a problem with multiple static inner classes. Could this be a problem in the core groovy compiler too? I'm not sure how greclipse uses the groovy compiler....

        Show
        Travis added a comment - I have not had a chance to give this a test. Most of our team has switched to using Intellij so I haven't heard any complaints of this lately... We do plan on using the eclipse compiler via maven at that point so this could affect us then. The original issue had to do with the core groovy compiler not compiling static inner classes correctly. Now it seems that is fixed but maybe there is a problem with multiple static inner classes. Could this be a problem in the core groovy compiler too? I'm not sure how greclipse uses the groovy compiler....
        Hide
        Andy Clement added a comment -

        The "The constructor Outer.Inner() is undefined" is also a groovy 'bug'. I just raised http://jira.codehaus.org/browse/GROOVY-5080 - groovy incorrectly tags the generated constructor as synthetic.

        You won't see it on the command line if you compile the java and groovy together in one step, you need to do a two part compile, the groovy and then java. That more closely mirrors the eclipse incremental build that shows the problem. An eclipse full build won't show the problem.

        As for this:

        class Outer {
          static class Inner1 { }
          static class Inner2 { }
        }
        

        Can't get it to fail for me, maybe we've picked up some fix in 1.8.3 that addressed something in this area. please open a new bug if you see something in this area.

        Oh, and I've committed the fix for the groovy bug 5080 into our copy of groovyc, so that under greclipse we won't tag the constructors incorrectly.

        Show
        Andy Clement added a comment - The "The constructor Outer.Inner() is undefined" is also a groovy 'bug'. I just raised http://jira.codehaus.org/browse/GROOVY-5080 - groovy incorrectly tags the generated constructor as synthetic. You won't see it on the command line if you compile the java and groovy together in one step, you need to do a two part compile, the groovy and then java. That more closely mirrors the eclipse incremental build that shows the problem. An eclipse full build won't show the problem. As for this: class Outer { static class Inner1 { } static class Inner2 { } } Can't get it to fail for me, maybe we've picked up some fix in 1.8.3 that addressed something in this area. please open a new bug if you see something in this area. Oh, and I've committed the fix for the groovy bug 5080 into our copy of groovyc, so that under greclipse we won't tag the constructors incorrectly.
        Hide
        Peter Butler added a comment - - edited

        This fails for me with the following code (all code in .groovy files):

         
        package com.company.somepackage
        public interface SomeInterface {
            SomeGroovyObject doSomething(SomeOtherGroovyObject param)
        }
        
        package com.company.somepackage
        class SomeTestClass {
            void setup() {
                testObject.someProperty = new SomeInterface() {
                    return new SomeGroovyObject()
                }
            }
        }
        

        The compiler gives an error like:

         
        SomeTestClass.groovy (at line 1)
        	package com.company.somepackage
        	^
        The type com.company.somepackage.SomeInterface$1 cannot be resolved. It is indirectly referenced from required .class files
        

        I've tried this from Maven on both 2.5.2-01 and 2.6.0-SNAPSHOT of groovy-eclipse-compiler. I've also checked out groovy-eclipse-compiler from svn and built but it fails with the same error.

        Show
        Peter Butler added a comment - - edited This fails for me with the following code (all code in .groovy files): package com.company.somepackage public interface SomeInterface { SomeGroovyObject doSomething(SomeOtherGroovyObject param) } package com.company.somepackage class SomeTestClass { void setup() { testObject.someProperty = new SomeInterface() { return new SomeGroovyObject() } } } The compiler gives an error like: SomeTestClass.groovy (at line 1) package com.company.somepackage ^ The type com.company.somepackage.SomeInterface$1 cannot be resolved. It is indirectly referenced from required .class files I've tried this from Maven on both 2.5.2-01 and 2.6.0-SNAPSHOT of groovy-eclipse-compiler. I've also checked out groovy-eclipse-compiler from svn and built but it fails with the same error.
        Hide
        Andy Clement added a comment -

        Hi Peter,

        Can you maybe give me a complete failing project that shows this problem? The code above is missing SomeOtherGroovyObject and SomeGroovyObject - but even when I supply stub implementations of them, the setup() method shows a problem:

        org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        SomeTestClass.groovy: 13: unexpected token: return @ line 13, column 5.
           				return new SomeGroovyObject()
        
        

        I dont get as far as a resolution error.

        Show
        Andy Clement added a comment - Hi Peter, Can you maybe give me a complete failing project that shows this problem? The code above is missing SomeOtherGroovyObject and SomeGroovyObject - but even when I supply stub implementations of them, the setup() method shows a problem: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: SomeTestClass.groovy: 13: unexpected token: return @ line 13, column 5. return new SomeGroovyObject() I dont get as far as a resolution error.

          People

          • Assignee:
            Andy Clement
            Reporter:
            Travis
          • Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: