2017-10-21 88 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,您将在该方法内增加该字段。