繁体   English   中英

在Eclipse CDT中获取调用层次结构

[英]Obtaining call hierarchy in Eclipse CDT

我正在为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

这是CDT中用于填充调用层次结构视图的代码的链接: http//git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/core/org.eclipse.cdt。 UI / SRC /组织/蚀/ CDT /内部/ UI / callhierarchy / CHQueries.java

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM