来自现有的代码库。 A类的实例变量A.toBeCalled为“ToBeCalled”类型。 如何找到它的所有用法/参考A.toBeCall来自代码库的整个调用图? e.g。
要求:
代码示例
Class A {
ToBeCalled toBeCalled = new ToBeCalled();
getToBecalled() { return toBeCalled;}
}
Class B {
main() {
A a = new A();
ToBeCalled toBeCalledInB = a.getToBecalled();
toBeCalledInB.doXXX();
C c = new C();
c.setToBeCalled(toBeCalledInB);
D d = new D();
d.start(c);
}
}
Class C {
ToBeCalled toBeCalledInC;
setToBeCalled(ToBeCalled theToBeCalled){
toBeCalledInC = theToBeCalled;
}
getToBeCalled() {
return toBeCalledInC;
}
}
Class D {
start(C c) {
ToBeCalled toBeCalledInD = c.getToBeCalled();
toBeCalledInD.doYYY();
}
}
调用A.toBeCalled的列表方法
我调查了几个工具作为起点,然而,它们有点粗糙
非常感谢您的帮助。
答案 0 :(得分:0)
如果我理解你的问题,那你就是在谈论interfaces
。
假设你有几个方法接口MyItf
:
public interface MyItf {
public ToBeCalled getToBeCalled();
public void doXXX();
public void doYYY();
}
使用interface
ToBeCalled
类必须覆盖所有方法。
public class ToBeCalled implements MyItf{
@Override
public ToBeCalled getToBeCalled() {
// TODO Auto-generated method stub
return null;
}
@Override
public void doXXX() {
// TODO Auto-generated method stub
}
@Override
public void doYYY() {
// TODO Auto-generated method stub
}
}
其他课程:
public class ToBeCalled2 implements MyItf{
@Override
public ToBeCalled getToBeCalled() {
// TODO Auto-generated method stub
return null;
}
@Override
public void doXXX() {
// TODO Auto-generated method stub
}
@Override
public void doYYY() {
// TODO Auto-generated method stub
}
}
最后:
public class Launcher {
public static void main(String[] args) {
MyItf my = new ToBeCalled();
my.getToBeCalled();
my.doXXX();
my.doYYY();
my = new ToBeCalled2();
my.getToBeCalled();
my.doXXX();
my.doYYY();
}
}