4

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?

Rob
  • 4,927
  • 12
  • 49
  • 54
cipher
  • 129
  • 1
  • 8

2 Answers2

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
allprog
  • 16,540
  • 9
  • 56
  • 97
Ali Arslan
  • 1,027
  • 10
  • 24
  • That is the solution for Eclipse JDT .. but I need to do it in Eclipse CDT because I'm working on a plugin for C projects, and I can not find an equivalent "CallHierarchy" class in Eclipse CDT. – cipher Jul 21 '12 at 23:07
0

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.

Mike Kucera
  • 2,003
  • 1
  • 14
  • 18