Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Reasons why Index can't resolve Declaration/Definition

Hi Guys,

I'm currently encountering a strange behavior of the IIndex instance obtained from a CRefactoringContext. For my refactoring I have the user to select a member declaration of a class. The resulting ICPPMember binding of the selected member's name is then used to find the ASTName of the declaration/definition using:

public static IASTName findName(CRefactoringContext context,
        IBinding binding) {
  try {
    final IIndex index = context.getIndex();
    final IIndexName[] names = index.findNames(binding,
        IIndex.FIND_DECLARATIONS_DEFINITIONS);
    if (names.length > 1) {
      return null;
    }
    for (IIndexName iname : names) {
      final IASTTranslationUnit ast = getASTForIndexName(iname,
          context);
      final IASTName name = IndexToASTNameHelper.findMatchingASTName(
          ast, iname, index);

      return name ;
    }
  } catch (CoreException e) {
      CUIPlugin.log(e);
  }
  return null;
}

Now I have cases in which the names Array returned by index.findNames(...) is empty, even though the binding passed in has a declaration or definition within the current project. Sometimes but not always it even makes a difference whether the member is declared within a .cpp or a .h file. And sometimes it just works perfectly fine which is the main reason why I'm this confused.

Maybe there is something strange going on in my own code but I really would like to understand what exactly is going on here.
--
Regards,
Simon


Back to the top