Eclipse content does not work for Java objects in Groovy files

I found this Eclipse Groovy question and autocomplete , and I am experiencing the same problem, however after almost three years I am using the current version of the Groovy Eclipse plugin and there seems to be no syntax errors that could mislead ANTLR.

I also tried using the Groovy / Grails Tool Suite and got the same results.

I mocked a simple test case in which assistive content support works for Groovy objects methods, as well as for static elements of Java objects, but not for Java objects.

Groovy Class:

package test_groovy

import test_groovy.FooJava

class FooGroovy
{
    def fooJava = [2, "baz"] as FooJava

    def x = 4

    def FooGroovy()
    {
        // empty constructor    
    }

    def useFooJava()
    {
        // only displays Groovy methods, not the java ones
        def str = fooJava.getStr()
        println "str: ${str}"

        // static members like this *can* be found via content assist
        def str2 = FooJava.FOO_STR
        println "str2: ${str2}"

        // This is also not found via content assist
        def str3 = fooJava.dumpToStr()
        println "str3: ${str3}"
    }

    def fooBar()
    {
        return x + 3
    }

    static void main(def args)
    {
        def fooGroovy = [] as FooGroovy

        // Groovy object methods can be found via content assist
        def res = fooGroovy.fooBar()
        println "res: ${res}"

        fooGroovy.useFooJava()
    }
}

Java class:

package test_groovy;

public class FooJava
{
    private long bar;
    private String str;

    public static final String FOO_STR = "foo";

    public FooJava(long bar, String str)
    {
        super();
        this.bar = bar;
        this.str = str;
    }

    public long getBar()
    {
        return bar;
    }

    public void setBar(long bar)
    {
        this.bar = bar;
    }

    public String getStr()
    {
        return str;
    }

    public void setStr(String str)
    {
        this.str = str;
    }

    public String dumpToStr()
    {
        return new String("Str: " + str + ", bar: " + bar);
    }

}

I am using the Eclipse Kepler Service Release 2, the Groovy compiler 2.0.7, and the Groovy plugin Eclipse version 2.8.0.xx-20130703-1600-e43-RELEASE.

Java > p > > , Java Groovy (Java Non-Type, Java, Java).

, , , , , Java. .

+4
1

, , , Groovy:

, , Groovy Eclipse Java, Groovy, def, :

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

. , , def Object, , , , Object, , -assist .

Java, :

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

, .. FooJava.

, , , , , , - .

. - Java, def, ?

+4

Source: https://habr.com/ru/post/1538508/


All Articles