简体   繁体   English

Eclipse 调用层次结构 lambda

[英]Eclipse call hierarchy lambda

I think 5 years has passed since Lambda has been released for Java.我认为自 Lambda 为 Java 发布以来已经过去了 5 年。

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.当我在inner1方法上按CTRL-ALT-H -(打开调用层次结构)时,我希望看到从inner1main方法的整个堆栈跟踪。 Instead, my staktrace is trimmed on inner method.相反,我的 staktrace 是在inner方法上修剪的。 I've just downloaded the newest Eclipse, I think it 2018-12, previously I was using Mars.我刚刚下载了最新的 Eclipse,我认为是 2018-12 年,之前我使用的是 Mars。

在此处输入图片说明 Intellij can show me the expected call-hierarchy, and I don't really understand why Eclipse still can't do it. Intellij 可以向我展示预期的调用层次结构,我真的不明白为什么 Eclipse 仍然不能做到这一点。 Not sure if anyone else is using Eclipse in 2019, but maybe you can advise a plugin or something.不确定是否还有其他人在 2019 年使用 Eclipse,但也许您可以建议一个插件或其他东西。

Switching to Intellij is not an option, I tried couple of times, but the habit is hard to overcome.切换到 Intellij 不是一种选择,我尝试了几次,但这个习惯很难克服。

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.在运行时,对 lambda 表达式的求值类似于对类实例创建表达式的求值,因为正常完成会生成对对象的引用。 Evaluation of a lambda expression is distinct from execution of the lambda body.对 lambda 表达式的评估与 lambda 主体的执行不同。

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, eg, Runnable.run() - but that doesn't question the general usefulness of call hierarchies through lambdas.请注意,对于实现诸如 Consumer 之类的库类型的 lambda,工作区中进入 accept(T) 的调用者数量可能很容易变得无法管理,类似于通过例如 Runnable.run() 的任何调用层次结构 - 但这并没有问题通过 lambda 调用层次结构的一般用途。

I don't really care about lambda internals, somehow other IDE is able to show expected stacktrace我并不真正关心 lambda 内部,不知何故其他 IDE 能够显示预期的堆栈跟踪

There's an existing old bug for eclipse, reported in 2016, still in NEW status 2016年报道的eclipse存在旧的bug ,仍然处于NEW状态

Bug 498498 - [1.8][search][call hierarchy] No usage for lambdas 错误498498 - [1.8] [搜索] [调用层次结构] lambda没有用法

Call hierarchy on bar method correctly shows usage in accept, and for accept there is no usage shown. bar方法上的调用层次结构正确显示了accept中的用法,而对于accept,则没有显示用法。 This issue was already present in mars. 这个问题已经存在于火星中。

There are 3 votes to fix it, you can vote too 有3票可以解决它,你也可以投票

From your edit's links there's another relevant old bug in NEW status 从您的编辑链接中,还有另一个处于NEW状态的相关旧错误

Bug 468561 - [search]Call Hierarchy stops searching in doubly-nested lambda chain 错误468561 - [搜索]调用层次结构停止在双重嵌套的lambda链中搜索

with 3 votes too... 还有3票......

Eclipse 4.22 (Q4 2021) should help: Eclipse 4.22(2021 年第四季度)应该有助于:

Improved lambda support in the Call Hierarchy view 改进了调用层次结构视图中的 lambda 支持

The Call Hierarchy view is enhanced with showing not only the callers of the lambda function, but the callers of the declaring function too. Call Hierarchy 视图得到了增强,不仅显示了 lambda 函数的调用者,还显示了声明函数的调用者。

For the following code:对于以下代码:

示例代码

Checking the callers of the function() will show this:检查 function() 的调用者将显示:

CallHierarchy 结果

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.树中的[declaration]节点是新添加的,它显示了definer()函数的调用definer() ,在这种情况下,只有main()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM