/* (non-Javadoc)
   * @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
   */
  public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    IJavaScriptStackFrame frame = getFrame();
    if (frame != null) {
      IDocument document = textViewer.getDocument();
      if (document != null) {
        try {
          String variableName = document.get(hoverRegion.getOffset(), hoverRegion.getLength());
          IVariable var = findLocalVariable(frame, variableName);
          if (var != null) {
            return var;
          }

          // might be in 'this'
          var = frame.getThisObject();
          try {
            IValue val = var == null ? null : var.getValue();
            if (val != null) {
              IVariable[] vars = val.getVariables();
              for (int i = 0; i < vars.length; i++) {
                if (vars[i].getName().equals(variableName)) {
                  return vars[i];
                }
              }
            }
          } catch (DebugException de) {
            return null;
          }

        } catch (BadLocationException e) {
          return null;
        }
      }
    }
    return null;
  }
 /**
  * Returns a local variable in the given frame based on the the given name or <code>null</code> if
  * none.
  *
  * @return local variable or <code>null</code>
  */
 private IVariable findLocalVariable(IJavaScriptStackFrame frame, String variableName) {
   if (frame != null) {
     try {
       IVariable[] vars = frame.getVariables();
       for (int i = 0; i < vars.length; i++) {
         if (vars[i].getName().equals(variableName)) {
           return vars[i];
         }
       }
     } catch (DebugException x) {
       JavaScriptDebugUIPlugin.log(x);
     }
   }
   return null;
 }