4

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

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

4

2 回答 2

3
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
于 2012-07-21T09:57:28.713 回答
0

这是 CDT 中用于填充调用层次结构视图的代码的链接:http: //git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/core/org.eclipse.cdt。 ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java

看起来很复杂,而且都是内部的(意味着它不是公共 API)。玩得开心。

于 2012-08-29T20:00:03.037 回答