简体   繁体   中英

Eclipse - `open call hierarchy` stop searching in lambda chain

Here is my sample java code:

public class Test {

    public static void main(String[] args) {
        methodDepth0(
            ()->
                methodDepth1(
                    ()->
                        methodDepth2()
                )
        );
    }

    static Object methodDepth2() {
        return null;
    }

    interface MyIF {
        void call();
    }

    static void methodDepth0(MyIF myIf){
        myIf.call();
    }

    interface MyIF2 {
        void call();
    }

    static void methodDepth1(MyIF2 myIf2){
        myIf2.call();
    }
}

When I open call hierarchy of method methodDepth2() from Eclipse(4.4), open call hierarchy stop searching next caller: 打开调用层次结构停止搜索下一个调用方法

What I expect is like opening call hierarchy of method methodDepth1() which show until the main method. 打开方法<code> methodDepth1()</ code>的调用层次结构,直到<code> main </ code>方法显示

From what I can tell the lack of call hierarchy depth is due to (re)evaluation of code at runtime. It is explained in 15.27.4 Run-Time Evaluation of Lambda Expressions in the Java Language Specification.

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.

As the second picture clearly shows, Eclipse is able to trace the call hierarchy through the method call myIf.call() inside methodDepth0 . This is correct, because the (outer) lambda implements method MyIF.call() .

The fact that the same pattern does not work in the next nesting level looks like a bug. Please consider filing a bug for JDT/UI. TIA.

Just note, that for lambdas implementing library types like Consumer<T> , 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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