Eclipse content assist not working for Java objects within Groovy files

后端 未结 1 1603
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 21:28

I found this question Eclipse Groovy and autocompletion and am experiencing the same issue, however, it is almost three years hence and I am using the current version of the

相关标签:
1条回答
  • 2021-01-13 22:21

    I was continuing to think about this, and had a thought which I just tested out which allows content-assist to work, albeit under less-Groovy conditions:

    It appears that the root of the problem is that Groovy Eclipse can't do auto-complete on Java objects if they are declared in a Groovy way using def, i.e.:

    def fooJava = [2, "baz"] as FooJava
    def fooJava2 = new FooJava(3, "bar")
    

    even though in both of these cases, the type is known at compile time. I suspect it has something to do with the fact that def is essentially an alias for Object, and even though the type is technically known, it is probably treated as Object, and so that's the type on which the content-assist operates.

    If I declare it in the traditional Java way, i.e.:

    FooJava fooJava3 = new FooJava(4, "foo")
    

    Content assist then allows me to find the members, methods, etc. of the FooJava object.

    So, I can certainly do this in the future to work around the issue, but I do wonder if there is any way to essentially have my cake and eat it too.

    i.e. Has anyone found a way to get content assist to work on Java objects declared via the def syntax, so long as the type is known?

    0 讨论(0)
提交回复
热议问题