I am developing a plugin for Eclipse CDT and I want to generate the call hierarchy of a function.
Is it possible without having to traverse the Syntax Tree of every file myself?
I am developing a plugin for Eclipse CDT and I want to generate the call hierarchy of a function.
Is it possible without having to traverse the Syntax Tree of every file myself?
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
Here's a link to the code in CDT that is used to populate the Call Hierarchy View: 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
Looks pretty complicated, and its all internal (meaning its not public API). Have fun.