简体   繁体   中英

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 
    -->  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.

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