Skip to main content

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

It's hard to say what is going on without debugging the issue. You can set conditional breakpoints in places where the problematic binding and its names are written to PDOM and compare that with what findNames is doing.


On Sat, Nov 2, 2013 at 6:16 AM, Simon Taddiken <simon.taddiken@xxxxxxxxxxxxxx> wrote:
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,
    if (names.length > 1) {
      return null;
    for (IIndexName iname : names) {
      final IASTTranslationUnit ast = getASTForIndexName(iname,
      final IASTName name = IndexToASTNameHelper.findMatchingASTName(
          ast, iname, index);

      return name ;
  } catch (CoreException 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.
cdt-dev mailing list

Back to the top