Пример #1
0
 public IIndexBinding[] findBindings(
     char[] name, boolean filescope, IndexFilter filter, IProgressMonitor monitor)
     throws CoreException {
   if (SPECIALCASE_SINGLES && fFragments.length == 1) {
     return fFragments[0].findBindings(name, filescope, filter, monitor);
   } else {
     List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
     ILinkage[] linkages = Linkage.getIndexerLinkages();
     for (ILinkage linkage : linkages) {
       if (filter.acceptLinkage(linkage)) {
         IIndexFragmentBinding[][] fragmentBindings =
             new IIndexFragmentBinding[fPrimaryFragmentCount][];
         for (int i = 0; i < fPrimaryFragmentCount; i++) {
           try {
             IBinding[] part =
                 fFragments[i].findBindings(
                     name, filescope, retargetFilter(linkage, filter), monitor);
             fragmentBindings[i] = new IIndexFragmentBinding[part.length];
             System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
           } catch (CoreException e) {
             CCorePlugin.log(e);
             fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
           }
         }
         ICompositesFactory factory = getCompositesFactory(linkage.getLinkageID());
         result.add(factory.getCompositeBindings(fragmentBindings));
       }
     }
     return flatten(result);
   }
 }
Пример #2
0
  public static IBinding[] getBindingsViaCache(
      IPDOMCPPClassType ct, final char[] name, IndexFilter filter) throws CoreException {
    CharArrayObjectMap<List<PDOMBinding>> map = getBindingMap(ct);
    List<PDOMBinding> cached = map.get(name);
    if (cached == null) return IBinding.EMPTY_BINDING_ARRAY;

    int i = 0;
    IBinding[] result = new IBinding[cached.size()];
    for (IBinding binding : cached) {
      if (filter.acceptBinding(binding)) {
        result[i++] = binding;
      }
    }
    if (i == result.length) return result;

    final IBinding[] bresult = new IBinding[i];
    System.arraycopy(result, 0, bresult, 0, i);
    return bresult;
  }
Пример #3
0
  private boolean navigationFallBack(IASTTranslationUnit ast, IASTName sourceName, NameKind kind) {
    // Bug 102643, as a fall-back we look up the selected word in the index.
    if (fSelectedText != null && fSelectedText.length() > 0) {
      try {
        final ICProject project = fTranslationUnit.getCProject();
        final char[] name = fSelectedText.toCharArray();
        List<ICElement> elems = new ArrayList<ICElement>();

        // Bug 252549, search for names in the AST first.
        Set<IBinding> primaryBindings = new HashSet<IBinding>();
        ASTNameCollector nc = new ASTNameCollector(fSelectedText);
        ast.accept(nc);
        IASTName[] candidates = nc.getNames();
        for (IASTName astName : candidates) {
          try {
            IBinding b = astName.resolveBinding();
            if (b != null && !(b instanceof IProblemBinding)) {
              primaryBindings.add(b);
            }
          } catch (RuntimeException e) {
            CUIPlugin.log(e);
          }
        }

        // Search the index, also.
        final IndexFilter filter =
            IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false);
        final IIndexBinding[] idxBindings = fIndex.findBindings(name, false, filter, fMonitor);
        for (IIndexBinding idxBinding : idxBindings) {
          primaryBindings.add(idxBinding);
        }

        // Search for a macro in the index.
        IIndexMacro[] macros = fIndex.findMacros(name, filter, fMonitor);
        for (IIndexMacro macro : macros) {
          ICElement elem = IndexUI.getCElementForMacro(project, fIndex, macro);
          if (elem != null) {
            elems.add(elem);
          }
        }

        Collection<IBinding> secondaryBindings;
        if (ast instanceof ICPPASTTranslationUnit) {
          secondaryBindings = cppRemoveSecondaryBindings(primaryBindings, sourceName);
        } else {
          secondaryBindings = defaultRemoveSecondaryBindings(primaryBindings, sourceName);
        }

        // Convert bindings to CElements.
        Collection<IBinding> bs = primaryBindings;
        for (int k = 0; k < 2; k++) {
          for (IBinding binding : bs) {
            IName[] names = findNames(fIndex, ast, kind, binding);
            // Exclude names of the same kind.
            for (int i = 0; i < names.length; i++) {
              if (getNameKind(names[i]) == kind) {
                names[i] = null;
              }
            }
            names = (IName[]) ArrayUtil.removeNulls(IName.class, names);
            convertToCElements(project, fIndex, names, elems);
          }
          // In case we did not find anything, consider the secondary bindings.
          if (!elems.isEmpty()) break;
          bs = secondaryBindings;
        }
        if (navigateCElements(elems)) {
          return true;
        }
        if (sourceName != null && sourceName.isDeclaration()) {
          // Select the name at the current location as the last resort.
          return navigateToName(sourceName);
        }
      } catch (CoreException e) {
        CUIPlugin.log(e);
      }
    }
    return false;
  }