コード例 #1
0
  private static void highlightTodos(
      @NotNull PsiFile file,
      @NotNull CharSequence text,
      int startOffset,
      int endOffset,
      @NotNull ProgressIndicator progress,
      @NotNull ProperTextRange priorityRange,
      @NotNull Collection<HighlightInfo> result,
      @NotNull Collection<HighlightInfo> outsideResult) {
    PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
    TodoItem[] todoItems = helper.findTodoItems(file, startOffset, endOffset);
    if (todoItems.length == 0) return;

    for (TodoItem todoItem : todoItems) {
      progress.checkCanceled();
      TextRange range = todoItem.getTextRange();
      String description =
          text.subSequence(range.getStartOffset(), range.getEndOffset()).toString();
      TextAttributes attributes = todoItem.getPattern().getAttributes().getTextAttributes();
      HighlightInfo info =
          HighlightInfo.createHighlightInfo(
              HighlightInfoType.TODO, range, description, description, attributes);
      assert info != null;
      if (priorityRange.containsRange(info.getStartOffset(), info.getEndOffset())) {
        result.add(info);
      } else {
        outsideResult.add(info);
      }
    }
  }
コード例 #2
0
 /**
  * Renders the highlights.
  *
  * @param g the graphics context
  */
 public void paint(Graphics g) {
   // PENDING(prinz) - should cull ranges not visible
   int len = highlights.size();
   for (int i = 0; i < len; i++) {
     HighlightInfo info = highlights.elementAt(i);
     if (!(info instanceof LayeredHighlightInfo)) {
       // Avoid allocing unless we need it.
       Rectangle a = component.getBounds();
       Insets insets = component.getInsets();
       a.x = insets.left;
       a.y = insets.top;
       a.width -= insets.left + insets.right;
       a.height -= insets.top + insets.bottom;
       for (; i < len; i++) {
         info = highlights.elementAt(i);
         if (!(info instanceof LayeredHighlightInfo)) {
           Highlighter.HighlightPainter p = info.getPainter();
           p.paint(g, info.getStartOffset(), info.getEndOffset(), a, component);
         }
       }
     }
   }
 }