Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 510101 - [1.8][code assist][lambda] code assist does not work in specific situation with lamdas
Summary: [1.8][code assist][lambda] code assist does not work in specific situation wi...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Mac OS X
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-09 07:40 EST by Johannes Berg CLA
Modified: 2018-08-06 05:54 EDT (History)
2 users (show)

See Also:


Attachments
Code assist failing example (552 bytes, application/octet-stream)
2017-01-09 07:40 EST, Johannes Berg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Berg CLA 2017-01-09 07:40:24 EST
Created attachment 266187 [details]
Code assist failing example

Code assist ("Open implementation" / command-click) does not work on methods in a specific situation, see attached example.

public class Lambda <T> {
	
	Lambda<String> sc = new Lambda<>();
	
	public Lambda<String> get(Lambda<String> sc) {
		return new Lambda<>();
	}
		
	public void foo(String s) {
		sc.get(Lambda.of("")).consume((String ss) -> {
			System.out.println("");
		}, (Throwable failure) -> {
			System.out.println("");
		});
	}
		
	public static Lambda<String> of(String s) {
		return new Lambda<>();
	}
	
	public void consume(Consumer<T> t, Consumer<Throwable> f) {
	}
}

In eclipse 4.6.2 "Open implementation" does not work on the "get" and "of" methods in the "foo" method. If I add System.out.println("") first thing in the method it works, if I remove the System.out.println("") in both lambda blocks it also works.

Code compiles fine so this is just for the code assist and for a quite specific case.
Comment 1 Jay Arthanareeswaran CLA 2017-01-10 02:53:25 EST
Noopur, I don't get the offer to "Open implementations", if the syso statements are present. Perhaps the AST UI gets is broken. Can you throw some light on what's going on? Thanks!
Comment 2 Noopur Gupta CLA 2017-01-10 03:19:11 EST
org.eclipse.jdt.core.ICodeAssist.codeSelect(int offset, int length) does not return any result in this case. It is invoked in JavaElementHyperlinkDetector.detectHyperlinks(..).
Comment 3 Johannes Berg CLA 2017-08-02 03:14:11 EDT
This is still an issue in Oxygen Release (4.7.0) Build id: 20170620-1800 and is starting to get a bit frustrating. Another example likely hitting the same bug:

import java.util.concurrent.CompletableFuture;

public class OpenDeclarationDoesNotWork {
	
	public void foo() {
		bar().whenComplete((obj, throwable) -> {
			System.out.println("foobar");
		});
	}

	public CompletableFuture<Object> bar() {
		return null;
	}
}

Open declaration does not work for bar() in the foo() method. Any ideas on how to bring this forward and get it fixed?
Comment 4 Johannes Berg CLA 2018-08-06 05:54:01 EDT
This seems to be resolved in Photon Release (4.8.0)
Build id: 20180619-1200

This has been haunting me for the past one and a half year so good to see it finally becoming resolved, I almost lost hope.