private IPath getLabel(IIndexFileLocation ifl) {
   String fullPath = ifl.getFullPath();
   if (fullPath != null) {
     return new Path(fullPath);
   }
   IPath path = IndexLocationFactory.getAbsolutePath(ifl);
   if (path != null) {
     return path;
   }
   URI uri = ifl.getURI();
   return new Path(EFSExtensionManager.getDefault().getPathFromURI(uri));
 }
 public String getFileName() {
   try {
     IIndexFile file = getFile();
     if (file == null) {
       return null;
     }
     // We need to specify what this method can return to know
     // how to implement this. Existing implementations return
     // the absolute path, so here we attempt to do the same.
     IPath location = IndexLocationFactory.getAbsolutePath(file.getLocation());
     return location != null ? location.toOSString() : null;
   } catch (CoreException e) {
     CCorePlugin.log(e);
   }
   return null;
 }
  /** Performs heuristic header substitution. */
  public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) {
    Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet();
    String symbolName = request.getBinding().getName();
    ArrayDeque<IIndexFile> front = new ArrayDeque<IIndexFile>();
    HashSet<IIndexFile> processed = new HashSet<IIndexFile>();

    try {
      // Look for headers without an extension and a matching name.
      if (fContext.isCXXLanguage()) {
        front.addAll(indexFiles);
        processed.addAll(indexFiles);

        while (!front.isEmpty()) {
          IIndexFile file = front.remove();

          String path = IncludeUtil.getPath(file);

          if (!hasExtension(path) && getFilename(path).equalsIgnoreCase(symbolName)) {
            // A C++ header without an extension and with a name which matches the name
            // of the symbol which should be declared is a perfect candidate for inclusion.
            return IndexLocationFactory.getAbsolutePath(file.getLocation());
          }

          // Process the next level of the include hierarchy.
          IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
          for (IIndexInclude include : includes) {
            IIndexFile includer = include.getIncludedBy();
            if (!processed.contains(includer)) {
              front.add(includer);
              processed.add(includer);
            }
          }
        }
      }

      // Repeat the process, this time only looking for headers without an extension.
      front.clear();
      front.addAll(indexFiles);
      processed.clear();
      processed.addAll(indexFiles);

      while (!front.isEmpty()) {
        IIndexFile file = front.remove();

        String path = IncludeUtil.getPath(file);

        if (fContext.isCXXLanguage() && !hasExtension(path)) {
          // A C++ header without an extension is still a very good candidate for inclusion.
          return IndexLocationFactory.getAbsolutePath(file.getLocation());
        }

        // Process the next level of the include hierarchy.
        IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
        for (IIndexInclude include : includes) {
          IIndexFile includer = include.getIncludedBy();
          if (!processed.contains(includer)) {
            URI uri = includer.getLocation().getURI();
            if (IncludeUtil.isSource(includer, fContext.getProject()) || isWorkspaceFile(uri)) {
              return IndexLocationFactory.getAbsolutePath(file.getLocation());
            }
            front.add(includer);
            processed.add(includer);
          }
        }
      }
    } catch (CoreException e) {
      CUIPlugin.log(e);
    }

    return request.getCandidatePaths().iterator().next();
  }