/**
  * Get the {@link AstNode} associated with the selected portion of the given editor.
  *
  * @param editor the editor
  * @param caret the caret position in the editor
  * @return the associated {@link AstNode}
  */
 public static AstNode getNodeAtOffset(DartEditor editor, int caret) {
   CompilationUnit cu = editor.getInputUnit();
   if (cu == null) {
     return null;
   }
   return new NodeLocator(caret).searchWithin(cu);
 }
  /**
   * 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);
  }