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

Missing code assist in map-style constructor #286

Closed
mauromol opened this issue May 4, 2017 · 5 comments
Closed

Missing code assist in map-style constructor #286

mauromol opened this issue May 4, 2017 · 5 comments
Assignees

Comments

@mauromol
Copy link

mauromol commented May 4, 2017

From a code snippet in the old GRECLIPSE-1800.

Consider the following:

package c 
class C { 
    class MyBean { 
        String foo 
        int bar 
    } 
    class AnotherClass { 
        int createInt() { 
            return 1 
        } 
        String createString() { 
            return 'foo' 
        } 
    } 

    void doSomething() { 
        def a = new AnotherClass() 
        def b = new MyBean( foo: a.cre| ) 
    } 
}

Trying to invoke code assist at | brings no suggestions. I would expect to see c.C.AnotherClass.createString() (since MyBean.foo is of type String) suggested first, then c.C.AnotherClass.createInt() next.

@eric-milles
Copy link
Member

Can you try again with the latest snapshot? I am getting the proper completion proposals in this scenario.

@mauromol
Copy link
Author

mauromol commented May 7, 2017

I'm trying with Greclipse 2.9.2.xx-201705070120-e46, but I can't understand if I'm doing anything wrong, because I still get no suggestions at all in the above scenario...

@eric-milles
Copy link
Member

Sorry, I tried something that I thought was the equivalent. There are a couple things going on in your example. 1. The completion is within a map-entry expression (pretty normal). 2. Your inner classes are not static. This combination results in a variant of a constructor call expression that is not properly traversed by the type inferencing engine.

So, I will get this fixed. Should not take too long. But if you do not need to refer to any parts of class C from either MyBean or AnotherClass, you can add a static modifier to them and the constructors will no longer expect a reference to C as the first (hidden) parameter and foo will get highlighted as a string and a.cre should give you completions.

@mauromol
Copy link
Author

mauromol commented May 8, 2017

With 2.9.2.xx-201705080332-e46 it seems to work now! However, if I add @CompileStatic Groovy gives a compilation error. But I think this is a Groovy compiler error, not Greclipse fault. Using new C.MyBean(...) makes the error go away and code assist in Greclipse still works. Thank you!

@mauromol
Copy link
Author

mauromol commented May 8, 2017

I opened https://issues.apache.org/jira/browse/GROOVY-8179 for the compiler problem.

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