Bug 497423 - [content assist] A static method from generic type added to the favorites is not shown
Summary: [content assist] A static method from generic type added to the favorites is ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-06 16:33 EDT by NoDataFound - CLA
Modified: 2022-12-13 17:25 EST (History)
4 users (show)

See Also:


Attachments
A sample project with a class that fails (5.68 KB, application/zip)
2016-07-06 16:33 EDT, NoDataFound - CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description NoDataFound - CLA 2016-07-06 16:33:21 EDT
Created attachment 262952 [details]
A sample project with a class that fails

Hello,

I am using Eclipse Neon on Windows 7x64 + JDK 1.8u92. This bug also appear on Eclipse Luna.

When I add a static import in Editor > Content Assist > Favorites whether it is a member import or a "all" (*) import, it is never proposed when using the method.

I've attached a zip containing two class for which the favorites content assist fails: please use the class fr.nodatafound.ide.p2.StaticImportFail to test for yourself:

class fr.nodatafound.ide.ClassWithGenericsAndStaticMethod<A> {
  public static <A> ClassWithGenericsAndStaticMethod<A> newGenericClassWithGenericMethod(A) {...}
  public static <A> ClassWithGenericsAndStaticMethod<A> newGenericClassWithObjectMethod(Object) {...}
}
class fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod {
  public static <A> ClassWithoutGenericsAndStaticMethod newClassWithGenericMethod(A) {...}
  public static <A> ClassWithoutGenericsAndStaticMethod newClassWithObjectMethod(Object) {...}
}


In the four cases, the static import fails either by no proposing the class, either by going completely wrong:

    final String value = null;
    // with type favorite: fr.nodatafound.ide.ClassWithGenericsAndStaticMethod.*
    // with type favorite: fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.*

    // OK proposed fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithGenericMethod;
    newClassWithGenericMethod("a");

    // OK proposed fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithObjectMethod;
    newClassWithObjectMethod("b");

    // FAIL (propose to create private method)
    newGenericClassWithGenericMethod("c");

    // FAIL (propose to create private method)
    newGenericClassWithObjectMethod("d");

    // now remove the previous favorites and add to member favorites:
    // fr.nodatafound.ide.ClassWithGenericsAndStaticMethod.newGenericClassWithGenericMethod
    // fr.nodatafound.ide.ClassWithGenericsAndStaticMethod.newGenericClassWithObjectMethod
    // fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithGenericMethod
    // fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithObjectMethod

    // FAIL (propose to add fr.nodatafound.ide.newGenericClassWithGenericMethod;)
    newGenericClassWithGenericMethod("c");

    // FAIL (propose to add fr.nodatafound.ide.newGenericClassWithObjectMethod)
    newGenericClassWithObjectMethod("d");

    // OK proposed fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithGenericMethod
    newClassWithGenericMethod("a");

    // OK proposed  fr.nodatafound.ide.ClassWithoutGenericsAndStaticMethod.newClassWithObjectMethod;
    newClassWithObjectMethod("b");

    // with type favorite: java.util.Optional.*
    // with type favorite: java.util.OptionalInt.*

    // FAIL proposed to create private method
    ofNullable(null);

    // FAIL proposed java.util.OptionalInt.of
    of(value);

    // FAIL proposed java.util.OptionalInt.of
    of("A");

    // OK proposed java.util.OptionalInt.of
    of(1);

As you can see, it also fails with java.util.Optional, com.google.common.collect.ImmutableList and other classes of Guava.

The problem seems to appear when the class use generics: this is true at least for my test case, for Optional and ImmutableList.

The case with member favorites is very strange, because the parent class is completely removed.

Note: I have much more static import that the list I gave here. I don't think it conflicts ... and because there is no option to only export that list (I know the import/export preferences does it, but you can't select only these).

Is there a way to debug Eclipse (perhaps some logs) in determine what the algorithm is NOT doing ?
Comment 1 Noopur Gupta CLA 2016-07-13 07:02:52 EDT
Reproducible with Eclipse Neon. 

See also bug 339789. 

Smaller example to reproduce the issue - Add "p.Test" as "New Type" in Favorites:

------------------------------------------------
package p;

public class Test2 {
	void m1() {
		doSome
	}
}

------------------------------------------------
package p;

public class Test<T> {
	public static void doSomething(String abc) {
	}
}

------------------------------------------------

Content assist works again when "<T>" is deleted in class "Test".
Comment 2 Jay Arthanareeswaran CLA 2016-07-25 21:57:41 EDT
Not sure I can take this up during Oxygen, but will keep it on my radar.
Comment 3 Manoj N Palat CLA 2018-05-21 06:06:59 EDT
Bulk move out of 4.8
Comment 4 Eclipse Genie CLA 2020-08-29 08:05:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Eclipse Genie CLA 2022-09-12 16:13:51 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Plamen Tanov CLA 2022-11-21 09:20:21 EST
The problem is still present in Eclipse IDE for Enterprise Java and Web Developers, version 2022-09 (4.25.0), build id 20220908-1902.

I saw another related problem - if I add `new member` as favourite, e.g. java.util.Optional.empty and apply Quick Fix (Ctrl+1) on top of `empty()` - the suggestion is to add `import static java.util.empty` instead of `import static java.util.Optional.empty`
Comment 7 NoDataFound - CLA 2022-12-13 17:25:29 EST
I am pretty sure this problem is still there even with recent version of Eclipse.

As far as I understand it: to determine semantic information, Eclipse performs a partial compilation of the unit.

If the java syntax is invalid => the completion is not able to help, even for template. For example, if you want to complete "sysout" using Ctrl + Space, which should rewrite to "System.out.println();" (notice the ';'), you won't be able due to the missing ';' before var 

void foobar() {
  sysout  
  var x = 1L;
}

(I got this one today).

If the java syntax is valid => I think that, if you are using Java < 9 versus Java >= 9, the problems are not the same. 

- In Java 8, I think the Optional problem is mainly due to generics.
- In Java > 8, the modules add another layer of problems.

This also affect:

- The Hyperlinks; in my code, I can't go to method when the variable is declared as "var", as in var node = mapper.readValueAs(Foobar.class); --> readValueAs is not a "link"
- The Completion: Eclipse is unable to get type information, and it seems to also affect the prefix completion (eg: sysout, syserr and any template)
- Quick fixes

I think the whole "compile then complete" is one (major) difference between IntelliJ and Eclipse.