我正在为 Eclipse CDT 开发一个插件,我想生成一个函数的调用层次结构。

是否可以不必自己遍历每个文件的语法树?

最佳答案

CallHierarchy hierarchy = new CallHierarchy();
IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
hierarchy.setSearchScope(searchScope);
ArrayList<MethodCall> methodCalls = new ArrayList<MethodCall>();

MethodWrapper[] callerWrapper = hierarchy.getCallerRoots(methods);
ArrayList<MethodWrapper> callsWrapper = new ArrayList<MethodWrapper>();
for (int i = 0; i < callerWrapper.length; i++) {
    callsWrapper.addAll(Arrays.asList(callerWrapper[i]
            .getCalls(new NullProgressMonitor())));
}

for (int i = 0; i < callsWrapper.size(); i++)
    methodCalls.add(callsWrapper.get(i).getMethodCall());
// Now you will get method calls in methodCalls list.
IMember member = methodCalls.get(0).getMember();// you will get one of
                                                // caller method in
                                                // member by this method

关于java - 在 Eclipse CDT 中获取调用层次结构,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11559540/

10-09 03:13