Q:

Obtaining call hierarchy in Eclipse CDT

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?

A:

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

