Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-10124: "refers to the missing type" error in Greclipse (not Groovy) #1300

Closed
mauromol opened this issue Sep 29, 2021 · 7 comments
Closed
Assignees
Milestone

Comments

@mauromol
Copy link

mauromol commented Sep 29, 2021

Consider the attached project.
If you run ./gradlew jar it will compile fine.
However, if you open it in Greclipse and open the class test.test.TestGreclipseError, you'll see an error:

The method getResult() from the type BaseResponse<Result> refers to the missing type Result

Of course, the mentioned type is not missing.

This is quite annoying because Eclipse seems not to perform a clean build for this. I suspect the problem lies in test.api.io.BaseResponse<T>, which has a field result of the generic type T.

If the fix is hard, a suggestion for a workaround would be much appreciated.

TestGroovyGradle.zip

Tested with Greclipse 4.3.0.v202109281919-e2009.

@eric-milles
Copy link
Member

I believe this is related to GROOVY-10124. Groovy and Java have different scope rules for the header of a class (annotations, generics, extends, implements).

Adding a qualifier to the inner class type argument will fix resolution for JDT.

class Response extends WithResultOperationResponse<Response.Result> {
//                                                 ^^^^^^^^^
	static class Result ...
}

@mauromol
Copy link
Author

mauromol commented Sep 29, 2021

Good catch... using Response.Result in the class declaration "extends" clause seems to fix #1301 as well...

Can anything be done on Greclipse side as a workaround until Groovy bug is fixed? Indeed, this and #1301 were quite hard to deal with and drove me crazy today.

@eric-milles
Copy link
Member

If GROOVY-10124 was fixed, you would get an error in the groovy source as well. This could be done in greclipse ahead of groovy proper. I am unsure of doing that as pure groovy can still work as before.

@mauromol
Copy link
Author

Having an error in the Groovy source is fine for me, at least you know what you should fix.

I understand your concern of doing that in Greclipse before it's done in Groovy, but if the current behaviour prevents correct compilation under Eclipse, I think that having an error in the IDE even if it would be legitimate with plain groovyc is better than having an incomprehensible build error in the IDE anywhere else in the code...

@eric-milles
Copy link
Member

I will put out 4.3.0 release tomorrow. Then I will take a look at fixing the scope issue so you get a helpful error for 4.4.0.

@eric-milles eric-milles added this to the v4.4.0 milestone Sep 30, 2021
@eric-milles eric-milles changed the title Wrong "refers to the missing type" error in Greclipse parser (not Groovy) GROOVY-10124: "refers to the missing type" error in Greclipse (not Groovy) Sep 30, 2021
@eric-milles eric-milles self-assigned this Sep 30, 2021
@eric-milles
Copy link
Member

package p
class Outer extends X<Inner> {
  static class Inner {}
}

I have a bit of code worked up for #256 / GROOVY-8063 that represents the example above as the following in the Java model:

package p;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.net.*;
import groovy.lang.*;
import groovy.util.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import p.Outer.*;
public class Outer extends X<Inner> {
  public static class Inner {
    ...
  }
  ...
}

The extra on-demand import at the end is enough help JDT find the inner class reference. This should deliver a more seamless experience in the IDE.

@eric-milles
Copy link
Member

This solution will only help top-level types. If you make this kind of reference, it will still fail:

class Outer {
  @Tag(Deeper.VALUE)
  class Inner {
    static class Deeper {
      public final VALUE = ...
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants