@Override
 public void run(Result result, SchedulerEvent event) {
   try {
     ALGParserResult sjResult = (ALGParserResult) result;
     List<ParseException> syntaxErrors = sjResult.getJavaParser().syntaxErrors;
     Document document = result.getSnapshot().getSource().getDocument(false);
     List<ErrorDescription> errors = new ArrayList<ErrorDescription>();
     for (ParseException syntaxError : syntaxErrors) {
       Token token = syntaxError.currentToken;
       int start =
           NbDocument.findLineOffset((StyledDocument) document, token.beginLine - 1)
               + token.beginColumn
               - 1;
       int end =
           NbDocument.findLineOffset((StyledDocument) document, token.endLine - 1)
               + token.endColumn;
       ErrorDescription errorDescription =
           ErrorDescriptionFactory.createErrorDescription(
               Severity.ERROR,
               syntaxError.getMessage(),
               document,
               document.createPosition(start),
               document.createPosition(end));
       errors.add(errorDescription);
     }
     HintsController.setErrors(document, "simple-java", errors);
   } catch (BadLocationException ex1) {
     Exceptions.printStackTrace(ex1);
   } catch (org.netbeans.modules.parsing.spi.ParseException ex1) {
     Exceptions.printStackTrace(ex1);
   }
 }
 /** *** Annotation Stuff ******* */
 static void processAnnotations(
     NbEditorDocument doc,
     List<PPLine> lineList) { // XXX needs to be split for errors and warnings
   final ArrayList<ErrorDescription> errs = new ArrayList();
   DataObject dob = NbEditorUtilities.getDataObject(doc);
   FileObject fo = dob == null ? null : dob.getPrimaryFile();
   for (PPLine line : lineList) {
     for (PPLine.Error err : line.getErrors()) {
       PPToken tok = err.token;
       int shift =
           (tok.getType() == LineParserTokens.END_OF_FILE
                   || tok.getType() == LineParserTokens.END_OF_LINE
                   || tok.getType() == LineParserTokens.OTHER_TEXT)
               ? Math.max(1, tok.getPadding().length())
               : 0;
       int loff = NbDocument.findLineOffset(doc, line.getLineNumber() - 1);
       errs.add(
           ErrorDescriptionFactory.createErrorDescription(
               err.warning ? Severity.WARNING : Severity.ERROR,
               err.message,
               fo,
               loff + tok.getColumn() - shift,
               loff + tok.getColumn() + tok.getText().length()));
     }
     ArrayList<Fix> fixes = new ArrayList();
     int start = Utilities.getRowStartFromLineOffset(doc, line.getLineNumber() - 1);
     if (line.getTokens().size() > 1
         && "//#include".equals(line.getTokens().get(0).getText())) { // NOI18N
       fixes.add(
           new InlineIncludeHint(
               (NbEditorDocument) doc, start, line.getTokens().get(1).getText()));
     } else if (line.getType() == PPLine.OLDIF || line.getType() == PPLine.OLDENDIF) {
       PPBlockInfo b = line.getBlock();
       while (b != null && b.getType() != PPLine.OLDIF) {
         b = b.getParent();
       }
       if (b != null) fixes.add(new ReplaceOldSyntaxHint(doc, lineList, b));
     }
     if (line.getType() == PPLine.UNKNOWN)
       fixes.add(new DisableHint((NbEditorDocument) doc, start));
     if (fixes.size() > 0)
       errs.add(
           ErrorDescriptionFactory.createErrorDescription(
               Severity.HINT,
               NbBundle.getMessage(DocumentPreprocessor.class, "LBL_PreprocessorHint"),
               fixes,
               doc,
               line.getLineNumber())); // NOI18N
   }
   HintsController.setErrors(doc, "preprocessor-errors", errs); // NOI18N
 }
  /**
   * Locates AnnotateLine associated with given line. The line is translated to Element that is used
   * as map lookup key. The map is initially filled up with Elements sampled on annotate() method.
   *
   * <p>Key trick is that Element's identity is maintained until line removal (and is restored on
   * undo).
   *
   * @param line
   * @return found AnnotateLine or <code>null</code>
   */
  private AnnotateLine getAnnotateLine(int line) {
    StyledDocument sd = (StyledDocument) doc;
    int lineOffset = NbDocument.findLineOffset(sd, line);
    Element element = sd.getParagraphElement(lineOffset);
    AnnotateLine al = elementAnnotations.get(element);

    if (al != null) {
      int startOffset = element.getStartOffset();
      int endOffset = element.getEndOffset();
      try {
        int len = endOffset - startOffset;
        String text = doc.getText(startOffset, len - 1);
        String content = al.getContent();
        if (text.equals(content)) {
          return al;
        }
      } catch (BadLocationException e) {
        Mercurial.LOG.log(Level.INFO, "HG.AB: can not locate line annotation."); // NOI18N
      }
    }

    return null;
  }
 public void run() {
   if (lp == null || ec == null) return;
   StyledDocument doc;
   try {
     doc = ec.openDocument();
   } catch (IOException ex) {
     return;
   }
   JEditorPane ep = EditorContextDispatcher.getDefault().getCurrentEditor();
   if (ep == null) return;
   int offset;
   String expression =
       getIdentifier(
           doc,
           ep,
           offset = NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn());
   if (expression == null) return;
   DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager().getCurrentEngine();
   if (currentEngine == null) return;
   JPDADebugger d = currentEngine.lookupFirst(null, JPDADebugger.class);
   if (d == null) return;
   JPDAThread t = d.getCurrentThread();
   if (t == null || !t.isSuspended()) return;
   String toolTipText = null;
   try {
     Variable v = null;
     List<Operation> operations = t.getLastOperations();
     if (operations != null) {
       for (Operation operation : operations) {
         if (!expression.endsWith(operation.getMethodName())) {
           continue;
         }
         if (operation.getMethodStartPosition().getOffset() <= offset
             && offset <= operation.getMethodEndPosition().getOffset()) {
           v = operation.getReturnValue();
         }
       }
     }
     if (v == null) {
       v = d.evaluate(expression);
     }
     String type = v.getType();
     if (v instanceof ObjectVariable)
       try {
         String toString = null;
         try {
           java.lang.reflect.Method toStringMethod =
               v.getClass()
                   .getMethod(
                       "getToStringValue", // NOI18N
                       new Class[] {Integer.TYPE});
           toStringMethod.setAccessible(true);
           toString = (String) toStringMethod.invoke(v, TO_STRING_LENGTH_LIMIT);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
         if (toString == null) {
           toString = ((ObjectVariable) v).getToStringValue();
         }
         toolTipText =
             expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + toString;
       } catch (InvalidExpressionException ex) {
         toolTipText =
             expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + v.getValue();
       }
     else
       toolTipText =
           expression + " = " + (type.length() == 0 ? "" : "(" + type + ") ") + v.getValue();
   } catch (InvalidExpressionException e) {
     toolTipText = expression + " = >" + e.getMessage() + "<";
   }
   firePropertyChange(PROP_SHORT_DESCRIPTION, null, toolTipText);
 }