Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse call hierarchy lambda

I think 5 years has passed since Lambda has been released for Java.

public static void main(String[] args) {
    go();
}

private static void go() {
    Set<String> set = new HashSet<>();
    set.stream().forEach((s) -> {
        inner(s);
    });
}

private static void inner(String s) {
    inner1(s);
}

private static void inner1(String s) {

}

When I press CTRL-ALT-H - (open call hierarchy) on inner1 method, I expect to see a whole stack trace from in inner1 to main method. Instead, my staktrace is trimmed on inner method. I've just downloaded the newest Eclipse, I think it 2018-12, previously I was using Mars.

enter image description here Intellij can show me the expected call-hierarchy, and I don't really understand why Eclipse still can't do it. Not sure if anyone else is using Eclipse in 2019, but maybe you can advise a plugin or something.

Switching to Intellij is not an option, I tried couple of times, but the habit is hard to overcome.

UPDATE

There is similar - SO question

At run time, evaluation of a lambda expression is similar to evaluation of a class instance creation expression, insofar as normal completion produces a reference to an object. Evaluation of a lambda expression is distinct from execution of the lambda body.

and

Just note, that for lambdas implementing library types like Consumer, the number of callers into accept(T) in a workspace may easily become unmanageable, similar to any call hierarchy through, e.g, Runnable.run() - but that doesn't question the general usefulness of call hierarchies through lambdas.

I don't really care about lambda internals, somehow other IDE is able to show expected stacktrace

like image 497
Anton Avatar asked Mar 10 '19 11:03

Anton


2 Answers

There's an existing old bug for eclipse, reported in 2016, still in NEW status

Bug 498498 - [1.8][search][call hierarchy] No usage for lambdas

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.

There are 3 votes to fix it, you can vote too

From your edit's links there's another relevant old bug in NEW status

Bug 468561 - [search]Call Hierarchy stops searching in doubly-nested lambda chain

with 3 votes too...

like image 72
user7294900 Avatar answered Nov 14 '22 09:11

user7294900


Eclipse 4.22 (Q4 2021) should help:

Improved lambda support in the Call Hierarchy view

The Call Hierarchy view is enhanced with showing not only the callers of the lambda function, but the callers of the declaring function too.

For the following code:

Sample code

Checking the callers of the function() will show this:

CallHierarchy result

The [declaration] node in the tree is the new addition, which shows the callers of the definer() function, in this case, only the main() function.

like image 39
VonC Avatar answered Nov 14 '22 09:11

VonC