String file = commandLine.getValue(Options.FILE_OPTION);
boolean callees = commandLine.hasOption(CALLEES_OPTION);
int offset = getOffset(commandLine);
int length = commandLine.getIntValue(Options.LENGTH_OPTION);
ICProject cproject = CUtils.getCProject(projectName);
CUIPlugin cuiPlugin = CUIPlugin.getDefault();
ITranslationUnit src = CUtils.getTranslationUnit(cproject, file);
CCorePlugin.getIndexManager().update(
new ICElement[]{src}, IIndexManager.UPDATE_ALL);
CCorePlugin.getIndexManager().joinIndexer(3000, new NullProgressMonitor());
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{