src = src.getWorkingCopy();
IEditorInput input = new FileEditorInput((IFile)src.getResource());
// hack... there has to be a better way
WorkingCopyManager manager = (WorkingCopyManager)
cuiPlugin.getWorkingCopyManager();
manager.connect(input);
manager.setWorkingCopy(input, (IWorkingCopy)src);
HashMap<String,Object> result = new HashMap<String,Object>();
try{
// more hacks to got get around gui dependency
ASTProvider provider = ASTProvider.getASTProvider();
Field astCache = ASTProvider.class.getDeclaredField("fCache");
astCache.setAccessible(true);
((ASTCache)astCache.get(provider)).setActiveElement(src);
TextSelection selection = new TextSelection(offset, length);
Method findDefinitions = CallHierarchyUI.class.getDeclaredMethod(
"findDefinitions",
ICProject.class, IEditorInput.class, ITextSelection.class);
findDefinitions.setAccessible(true);
ICElement[] elements = (ICElement[])findDefinitions.invoke(
null, cproject, input, selection);
if (elements != null && elements.length > 0) {
ICElement element = elements[0];
Set<ICElement> seen = new HashSet<ICElement>();
ICProject project = element.getCProject();
ICProject[] scope = getScope(SCOPE_PROJECT, project);
IIndex index = CCorePlugin.getIndexManager().getIndex(
scope, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
index.acquireReadLock();
try{
IIndexName name = IndexUI.elementToName(index, element);
result = formatElement(index, new Call(name, element), seen, callees);
}finally{
index.releaseReadLock();
}
}
}finally{
manager.removeWorkingCopy(input);
manager.disconnect(input);
}
return result;
}