Java Code Examples for com.intellij.execution.filters.Filter#ResultItem

The following examples show how to use com.intellij.execution.filters.Filter#ResultItem . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestProxyPrinterProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void printLine(@Nonnull String line, @Nonnull ConsoleViewContentType contentType) {
  Filter.Result result;
  try {
    result = myFilter.applyFilter(line, line.length());
  }
  catch (Throwable t) {
    throw new RuntimeException("Error while applying " + myFilter + " to '" + line + "'", t);
  }
  if (result != null) {
    List<Filter.ResultItem> items = sort(result.getResultItems());
    int lastOffset = 0;
    for (Filter.ResultItem item : items) {
      defaultPrint(line.substring(lastOffset, item.getHighlightStartOffset()), contentType);
      String linkText = line.substring(item.getHighlightStartOffset(), item.getHighlightEndOffset());
      printHyperlink(linkText, item.getHyperlinkInfo());
      lastOffset = item.getHighlightEndOffset();
    }
    defaultPrint(line.substring(lastOffset), contentType);
  }
  else {
    defaultPrint(line, contentType);
  }
}
 
Example 2
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
void highlightHyperlinks(@Nonnull Filter.Result result, int offsetDelta) {
  Document document = myEditor.getDocument();
  for (Filter.ResultItem resultItem : result.getResultItems()) {
    int start = resultItem.getHighlightStartOffset() + offsetDelta;
    int end = resultItem.getHighlightEndOffset() + offsetDelta;
    if (start < 0 || end < start || end > document.getTextLength()) {
      continue;
    }

    TextAttributes attributes = resultItem.getHighlightAttributes();
    if (resultItem.getHyperlinkInfo() != null) {
      createHyperlink(start, end, attributes, resultItem.getHyperlinkInfo(), resultItem.getFollowedHyperlinkAttributes(), resultItem.getHighlighterLayer());
    }
    else if (attributes != null) {
      addHighlighter(start, end, attributes, resultItem.getHighlighterLayer());
    }
  }
}
 
Example 3
Source File: LineParser.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void parse(@NotNull String str) {
  if (str.isEmpty()) {
    return;
  }

  final List<Filter.ResultItem> resultItems = new ArrayList<>();
  for (Filter filter : filters) {
    final Filter.Result result = filter.applyFilter(str, str.length());
    if (result == null) {
      continue;
    }
    resultItems.addAll(result.getResultItems());
  }
  resultItems.sort(Comparator.comparingInt(Filter.ResultItem::getHighlightStartOffset));

  int cursor = 0;
  for (Filter.ResultItem item : resultItems) {
    final HyperlinkInfo hyperlinkInfo = item.getHyperlinkInfo();
    if (hyperlinkInfo != null) {
      final int start = item.getHighlightStartOffset();
      final int end = item.getHighlightEndOffset();
      // Leading text.
      if (cursor < start) {
        parseChunk(str.substring(cursor, start));
      }
      write(str.substring(start, end), SimpleTextAttributes.LINK_ATTRIBUTES, hyperlinkInfo);
      cursor = end;
    }
  }

  // Trailing text
  if (cursor < str.length()) {
    parseChunk(str.substring(cursor));
  }
}
 
Example 4
Source File: LineParser.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void parse(@NotNull String str) {
  if (str.isEmpty()) {
    return;
  }

  final List<Filter.ResultItem> resultItems = new ArrayList<>();
  for (Filter filter : filters) {
    final Filter.Result result = filter.applyFilter(str, str.length());
    if (result == null) {
      continue;
    }
    resultItems.addAll(result.getResultItems());
  }
  resultItems.sort(Comparator.comparingInt(Filter.ResultItem::getHighlightStartOffset));

  int cursor = 0;
  for (Filter.ResultItem item : resultItems) {
    final HyperlinkInfo hyperlinkInfo = item.getHyperlinkInfo();
    if (hyperlinkInfo != null) {
      final int start = item.getHighlightStartOffset();
      final int end = item.getHighlightEndOffset();
      // Leading text.
      if (cursor < start) {
        parseChunk(str.substring(cursor, start));
      }
      write(str.substring(start, end), SimpleTextAttributes.LINK_ATTRIBUTES, hyperlinkInfo);
      cursor = end;
    }
  }

  // Trailing text
  if (cursor < str.length()) {
    parseChunk(str.substring(cursor));
  }
}
 
Example 5
Source File: TestProxyPrinterProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<Filter.ResultItem> sort(@Nonnull List<Filter.ResultItem> items) {
  if (items.size() <= 1) {
    return items;
  }
  List<Filter.ResultItem> copy = new ArrayList<>(items);
  Collections.sort(copy, Comparator.comparingInt(Filter.ResultItem::getHighlightStartOffset));
  return copy;
}
 
Example 6
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Filter.Result checkRange(Filter filter, int endOffset, Filter.Result result) {
  if (result != null) {
    for (Filter.ResultItem resultItem : result.getResultItems()) {
      int start = resultItem.getHighlightStartOffset();
      int end = resultItem.getHighlightEndOffset();
      if (end < start || end > endOffset) {
        LOG.error("Filter returned wrong range: start=" + start + "; end=" + end + "; max=" + endOffset + "; filter=" + filter);
      }
    }
  }
  return result;
}