繁体   English   中英

如何在Java方法中收集调用的方法

[英]How to collect invoked methods within a java method

我想收集由特定方法显式和隐式调用的方法,例如:

Class A {
@Autowired 
C c;

foo() {
    B b = new B();
    b.print("abc");
    if (somecondition) {
        c.anotherPrint("def");
    }
}

Class B {
    print(String arg) {
    }
}

Class C {
    @Autowired
    B b;
    anotherPrint(String arg) {
        b.print(arg);
    }
}

从上面的代码中,我想收集信息,即类A的方法foo使用参数“ abc”和“ def”调用B的print()方法。类似于调用图

A::foo 
    -->  B::print("abc")
    -->  C::anotherPrint("def")
            --> B::print("def")

我没有看到如何为此目的使用其他方法,但是您可以添加一些标记来指示该方法已被调用。 例如,它可能是记录器,或者仅仅是一些字段countOfInvokes ,您将在方法内部增加该字段。

暂无
暂无

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

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