private DeclarationLocation getDeclarationLocation(
      PythonParserResult info, IndexedElement candidate, Set<? extends IndexedElement> methods) {
    BaseDocument doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false);
    if (doc == null) {
      return DeclarationLocation.NONE;
    }

    if (candidate != null) {
      FileObject fileObject = candidate.getFileObject();
      if (fileObject == null) {
        return DeclarationLocation.NONE;
      }

      PythonTree node = candidate.getNode();
      int nodeOffset = 0;
      if (node != null) {
        nodeOffset = PythonAstUtils.getNameRange(info, node).getStart();
      }

      DeclarationLocation loc = new DeclarationLocation(fileObject, nodeOffset, candidate);

      if (PythonUtils.isRstFile(fileObject)) {
        loc.setInvalidMessage(
            NbBundle.getMessage(
                PythonDeclarationFinder.class, "BuiltinPython", candidate.getName()));
        return loc;
      }

      if (methods.size() > 1) {
        // Could the :nodoc: alternatives: if there is only one nodoc'ed alternative
        // don't ask user!
        int not_nodoced = 0;
        for (final IndexedElement mtd : methods) {
          if (!mtd.isNoDoc()) {
            not_nodoced++;
          }
        }
        if (not_nodoced >= 2) {
          for (final IndexedElement mtd : methods) {
            loc.addAlternative(new PythonAltLocation(mtd, mtd == candidate));
          }
        }
      }

      return loc;
    }

    return DeclarationLocation.NONE;
  }
  private DeclarationLocation findImport(
      PythonParserResult info, String moduleName, String symbol) {
    PythonIndex index = PythonIndex.get(info.getSnapshot().getSource().getFileObject());

    Set<IndexedElement> elements = null;

    if (moduleName != null && symbol != null) {
      elements =
          index.getImportedElements(
              symbol, QuerySupport.Kind.EXACT, Collections.<String>singleton(moduleName), null);
    }

    if (symbol != null && (elements == null || elements.size() == 0)) {
      elements = index.getInheritedElements(null, symbol, QuerySupport.Kind.EXACT);
    }

    if (elements == null || elements.size() == 0) {
      elements = index.getModules(moduleName, QuerySupport.Kind.EXACT);
    }

    if (elements != null && elements.size() > 0) {
      AstPath path = null;
      PythonTree node = null;
      int astOffset = -1;
      int lexOffset = -1;
      return getDeclaration(info, null /*name*/, elements, path, node, index, astOffset, lexOffset);
    }

    // This never gets executed, right? Delete after EA
    for (IndexedElement candidate : elements) {
      // TODO - pick the best of the alternatives here?
      FileObject fileObject = candidate.getFileObject();
      if (fileObject == null) {
        return DeclarationLocation.NONE;
      }

      PythonTree node = candidate.getNode();
      int nodeOffset = node != null ? node.getCharStartIndex() : 0;

      DeclarationLocation loc = new DeclarationLocation(fileObject, nodeOffset, candidate);

      if (elements.size() > 1) {
        // Could the :nodoc: alternatives: if there is only one nodoc'ed alternative
        // don't ask user!
        int not_nodoced = 0;
        for (final IndexedElement mtd : elements) {
          if (!mtd.isNoDoc()) {
            not_nodoced++;
          }
        }
        if (not_nodoced >= 2) {
          for (final IndexedElement mtd : elements) {
            loc.addAlternative(new PythonAltLocation(mtd, mtd == candidate));
          }
        }
      }

      return loc;
    }

    return DeclarationLocation.NONE;
  }