简体   繁体   English

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

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

I wanna collect the methods invoked by a specific method both explicitly and implicitly.For example: 我想收集由特定方法显式和隐式调用的方法,例如:

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);
    }
}

From the code above I wanna collect the information that Class A's method foo invoke B's print() method with the argument "abc" and "def".Something like a call graph 从上面的代码中,我想收集信息,即类A的方法foo使用参数“ abc”和“ def”调用B的print()方法。类似于调用图

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

I don't see how to use different method for this purpose, but you can just add some markers that will indicate that method was invoked. 我没有看到如何为此目的使用其他方法,但是您可以添加一些标记来指示该方法已被调用。 For example it might be logger or simply some field countOfInvokes which you will increase inside the method. 例如,它可能是记录器,或者仅仅是一些字段countOfInvokes ,您将在方法内部增加该字段。

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

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