Bug 498498 - [1.8][search][call hierarchy] No usage for lambdas
Summary: [1.8][search][call hierarchy] No usage for lambdas
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5.2   Edit
Hardware: All All
: P3 normal with 11 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-07-26 10:47 EDT by Marek Stanulewicz CLA
Modified: 2023-03-14 06:19 EDT (History)
7 users (show)

See Also:


Attachments
call hierarchy (7.74 KB, image/png)
2016-07-26 10:47 EDT, Marek Stanulewicz CLA
no flags Details
Call hierarchy with reproduction snippet in Eclipse 4.27. (56.20 KB, image/png)
2023-03-14 06:19 EDT, Simeon Andreev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Stanulewicz CLA 2016-07-26 10:47:57 EDT
Created attachment 263316 [details]
call hierarchy

import java.util.Arrays;
import java.util.List;

public class EclipseLambdaProblem {

	private void bar() {
		System.out.println(this);
	}

	public static void main(String[] args) {
		List<EclipseLambdaProblem> problems = Arrays.asList(new EclipseLambdaProblem());
		problems.forEach(p -> p.bar());
	}

}

Call hierarchy on bar method correctly shows usage in accept, and for accept there is no usage shown.
This issue was already present in mars.
Comment 1 Stephan Herrmann CLA 2016-07-26 15:40:46 EDT
Thanks, I can reproduce.

Interestingly, when placing the cursor on the arrow (->) Call Hierarchy correctly shows lots of callers of accept().

From this it seems not to be a search issue per se, but a matter of what seed you use for search. Moving to JDT/UI for investigation / comments.
Comment 2 Noopur Gupta CLA 2016-07-27 06:54:37 EDT
org.eclipse.jdt.internal.corext.callhierarchy.CallerMethodWrapper.findChildren(IProgressMonitor progressMonitor) invokes SearchEngine to find the children of the current IMember.

In case of comment #0, the IMember is LambdaMethod:
accept(EclipseLambdaProblem) (not open) [in <lambda #1> [in main(String[]) [in EclipseLambdaProblem...

The case where call hierarchy is invoked on "->" (comment #1) is different, where the IMember is ResolvedBinaryMethod (obtained from text selection via ICodeAssist.codeSelect):
void accept(T) {key=Ljava/util/function/Consumer<LEclipseLambdaProblem;>;.accept(LEclipseLambdaProblem;)V} [in Consumer [in Consumer.class...

Seeding with LambdaMethod, which is obtained as the caller of #bar in the first step from SearchMatch.getElement() in MethodReferencesSearchRequestor, looks fine.

The SearchEngine does not return any result for accept(EclipseLambdaProblem) when LambdaMethod is used.

The problem could be with the details in LambdaMethod (compared to ResolvedBinaryMethod), or while creating the SearchPattern with LambdaMethod in SearchPattern#createPattern, or later in SearchEngine#search while using that SearchPattern.

Moving back to JDT/Core for further comments.
Comment 3 Sam Davis CLA 2018-04-10 16:06:25 EDT
I'm more concerned with the fact that there's no way to get from bar to main in the call hierarchy. When dealing with lambdas I almost always want to know who calls the method that contains the lambda (just like anonymous classes), not what other callers of the lambda exist.
Comment 4 Stephan Herrmann CLA 2018-04-12 04:43:06 EDT
(In reply to Sam Davis from comment #3)
> I'm more concerned with the fact that there's no way to get from bar to main
> in the call hierarchy. When dealing with lambdas I almost always want to
> know who calls the method that contains the lambda (just like anonymous
> classes), not what other callers of the lambda exist.

That would be a separate request. "containing" a lambda expression doesn't count as a call, strictly speaking.

What you are looking for seems to be an analogy to the constructor invocations node of an anonymous class.
Comment 5 Sam Davis CLA 2018-04-12 11:28:28 EDT
Yes, that is what I want. Since lambdas are basically just syntactic sugar for anonymous classes I expected this would work. Not having this makes the call hierarchy much less useful for Java 8 code. Should I open a separate bug?
Comment 6 Stephan Herrmann CLA 2018-04-12 16:08:02 EDT
(In reply to Sam Davis from comment #5)
> Should I open a separate bug?

I'd say so. Yes, please.
Comment 7 Sam Davis CLA 2018-04-12 16:26:20 EDT
See bug 533524.
Comment 8 Manoj N Palat CLA 2018-08-16 00:06:59 EDT
Bulk move out of 4.9
Comment 10 Simeon Andreev CLA 2023-03-14 06:19:25 EDT
Created attachment 288998 [details]
Call hierarchy with reproduction snippet in Eclipse 4.27.
Comment 11 Simeon Andreev CLA 2023-03-14 06:19:58 EDT
Seems to work with Eclipse 4.27.