簡體   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