/**
   * Get the element associated with the selected portion of the given input element.
   *
   * @param editor the editor
   * @param caret the caret position in the editor
   * @return the associated element
   */
  public static Element getElementAtOffset(DartEditor editor, int caret) {
    AstNode node = getNodeAtOffset(editor, caret);
    if (node == null) {
      return null;
    }

    return ElementLocator.locateWithOffset(node, caret);
  }
  /**
   * Get the element associated with the selected portion of the given input element.
   *
   * @param editor the editor
   * @param offset the beginning of the selection
   * @param length the length of the selection
   * @return the associated element
   */
  public static Element getElementAtOffset(DartEditor editor, int offset, int length) {

    CompilationUnit cu = editor.getInputUnit();

    AstNode node = new NodeLocator(offset, offset + length).searchWithin(cu);
    if (node == null) {
      return null;
    }

    return ElementLocator.locateWithOffset(node, offset);
  }