IIndexManager.ADD_DEPENDENCIES |
IIndexManager.ADD_DEPENDENT |
IIndexManager.ADD_EXTENSION_FRAGMENTS_NAVIGATION);
index.acquireReadLock();
try{
IASTTranslationUnit ast = src.getAST(index,
ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT |
ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
IASTNodeSelector selector = ast.getNodeSelector(null);
IASTName name = selector.findEnclosingName(offset, length);
if (name != null){
IBinding binding = name.resolveBinding();
int flags = IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES;
if (context == FIND_CONTEXT){
if (!name.isDeclaration() && !name.isDefinition()){
flags |= IIndex.FIND_DEFINITIONS;
} else {
// if on the declaration, search for the definition and vice verca
flags |= (name.isDefinition() ?
IIndex.FIND_DECLARATIONS : IIndex.FIND_DEFINITIONS);
}
} else if (context == CSearchQuery.FIND_ALL_OCCURRENCES){
flags |= IIndex.FIND_ALL_OCCURRENCES;
} else if (context == CSearchQuery.FIND_REFERENCES){
flags |= IIndex.FIND_REFERENCES;
} else if (context == CSearchQuery.FIND_DECLARATIONS_DEFINITIONS) {
flags |= IIndex.FIND_DECLARATIONS_DEFINITIONS;
} else if (context == CSearchQuery.FIND_DECLARATIONS) {
flags |= IIndex.FIND_DECLARATIONS;
} else if (context == CSearchQuery.FIND_DEFINITIONS) {
flags |= IIndex.FIND_DEFINITIONS;
}
CollectionUtils.addAll(names, index.findNames(binding, flags));
// kind of hacky. if we issued a context search and found no
// definitions, we'll try a declarations search (useful for system
// library references).
if (names.size() == 0 &&
context == FIND_CONTEXT &&
(flags & IIndex.FIND_DEFINITIONS) != 0)
{
CollectionUtils.addAll(names, index.findNames(
binding,
IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES |
IIndex.FIND_DECLARATIONS));
}
if (names.size() == 0){
// alternate search that finds some things that index.findNames may
// not.
if ((flags & IIndex.FIND_DECLARATIONS) != 0){
CollectionUtils.addAll(names, ast.getDeclarations(binding));
}
if ((flags & IIndex.FIND_DEFINITIONS) != 0){
CollectionUtils.addAll(names, ast.getDefinitions(binding));
}
if ((flags & IIndex.FIND_REFERENCES) != 0){
CollectionUtils.addAll(names, ast.getReferences(binding));
}
if ((flags & IIndex.FIND_DECLARATIONS) != 0 ||
(flags & IIndex.FIND_DEFINITIONS) != 0)
{
// also try to find macros (now required for stdlib EXIT_SUCCESS)
// gleaned from navigationFallBack in
// org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationJob
IndexFilter filter = IndexFilter.getDeclaredBindingFilter(
ast.getLinkage().getLinkageID(), false);
IIndexMacro[] macros = index.findMacros(
binding.getName().toCharArray(),
filter,
new NullProgressMonitor());
for (IIndexMacro macro : macros) {