【问题标题】:How to collect invoked methods within a java method如何在 java 方法中收集调用的方法
【发布时间】:2017-10-21 14:12:33
【问题描述】:

我想收集特定方法显式和隐式调用的方法。例如:

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")

【问题讨论】:

标签: java code-analysis call-graph


【解决方案1】:

我不知道如何为此目的使用不同的方法,但您可以添加一些标记来指示该方法已被调用。例如,它可能是记录器或只是一些字段countOfInvokes,您将在方法内增加。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    相关资源
    最近更新 更多