2012-07-19 104 views

回答

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 
+0

这是Eclipse JDT的解决方案..但我需要在Eclipse CDT中完成它,因为我正在为C项目开发插件,并且在Eclipse CDT中找不到等效的“CallHierarchy”类。 – cipher 2012-07-21 23:07:02

相关问题