2017-10-21 127 views
0

我想通過收集特定的方法都明確和implicitly.For例如調用的方法:如何收集Java方法中調用的方法

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

從上面的代碼,我想收集到的信息,一個類的方法富調用B的print()方法與參數「ABC」和「DEF」 .Something像調用圖

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

作爲一個恐懼問題,我想你應該先研究一些現有的解決方案,比如https://github.com/gousiosg/java-callgraph。另請參閱https://stackoverflow.com/questions/4951517/static-analysis-of-java-call-graph – fvu

回答

0

我不知道如何使用不同的方法用於此目的,但你可以添加一些將指示該方法被調用的標記。例如,它可能是記錄器,或者只是一些字段countOfInvokes,您將在該方法內增加該字段。