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

The following examples show how to use com.intellij.execution.filters.Filter#Result . 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: 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 2
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 3
Source File: BashLineErrorFilterTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidation() throws Exception {
    VirtualFile targetFile = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
        @Override
        public VirtualFile compute() {
            try {
                VirtualFile srcDir = myFixture.getTempDirFixture().findOrCreateDir("src");
                return srcDir.createChildData(this, "test.sh");
            } catch (IOException e) {
                return null;
            }
        }
    });

    PsiFile targetPsiFile = PsiManager.getInstance(getProject()).findFile(targetFile);
    Assert.assertNotNull(targetPsiFile);
    BashLineErrorFilter filter = new BashLineErrorFilter(getProject());

    String line = String.format("%s: line 13: notHere: command not found", targetFile.getCanonicalPath());
    Filter.Result result = filter.applyFilter(line, line.length());

    Assert.assertNotNull(result);

    HyperlinkInfo hyperlinkInfo = result.getFirstHyperlinkInfo();
    Assert.assertNotNull("Expected a hyperlink on the filename", hyperlinkInfo);

    hyperlinkInfo.navigate(getProject());

    VirtualFile[] openFiles = FileEditorManager.getInstance(getProject()).getOpenFiles();
    Assert.assertEquals("Expected just ony open file", 1, openFiles.length);
    Assert.assertEquals("Expected that navigation opened the target file", targetFile, openFiles[0]);
}
 
Example 4
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Filter.Result analyzeLine(int line) {
  int lineStart = snapshot.getLineStartOffset(line);
  if (lineStart + delta.getOffsetDelta() < 0) return null;

  String lineText = EditorHyperlinkSupport.getLineText(snapshot, line, true);
  int endOffset = lineStart + lineText.length();
  return checkRange(filter, endOffset, filter.applyFilter(lineText, endOffset));
}
 
Example 5
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private AsyncFilterRunner.FilterResult analyzeNextLine() {
  int line = startLine.get();
  Filter.Result result = analyzeLine(line);
  LOG.assertTrue(line == startLine.getAndIncrement());
  return result == null ? null : new FilterResult(delta, result);
}
 
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;
}
 
Example 7
Source File: ErrorFilterTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Test
public void testLink() {
  // This tests whether hyperlinks (Filter.Result) are created properly,
  // not whether error parsing or filters work.

  String expression = "ERR: CoordinatesDetectionTest.hx:22(by.rovar.iso.model.CoordinatesDetectionTest.test2x2) - expected true but was false";
  ErrorFilter filter = createFilter();
  String fileName = "by/rovar/iso/model/CoordinatesDetectionTest.hx";
  Filter.Result result = filter.applyFilter(expression, expression.length());
  assertEquals("ERR: ".length(), result.highlightStartOffset);
  assertEquals("ERR: CoordinatesDetectionTest.hx:22".length(), result.highlightEndOffset);
  HLInfo info = (HLInfo) result.hyperlinkInfo;
  info.checkInfo(fileName, 22);
}
 
Example 8
Source File: PantsMakeBeforeRun.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private void showPantsMakeTaskMessage(String message, ConsoleViewContentType type, Project project) {
  ConsoleView executionConsole = PantsConsoleManager.getConsole(project);
  // Create a filter that monitors console outputs, and turns them into a hyperlink if applicable.
  Filter filter = (line, entireLength) -> {
    Optional<ParseResult> result = ParseResult.parseErrorLocation(line, ERROR_TAG);
    if (result.isPresent()) {

      OpenFileHyperlinkInfo linkInfo = new OpenFileHyperlinkInfo(
        project,
        result.get().getFile(),
        result.get().getLineNumber() - 1, // line number needs to be 0 indexed
        result.get().getColumnNumber() - 1 // column number needs to be 0 indexed
      );
      int startHyperlink = entireLength - line.length() + line.indexOf(ERROR_TAG);

      return new Filter.Result(
        startHyperlink,
        entireLength,
        linkInfo,
        null // TextAttributes, going with default hence null
      );
    }
    return null;
  };

  ApplicationManager.getApplication().invokeLater(() -> {
    executionConsole.addMessageFilter(filter);
    executionConsole.print(message, type);
  }, ModalityState.NON_MODAL);
}
 
Example 9
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 10
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 11
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(timeout=1000)
public void checkBadErrorMessage() throws Exception {
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(backtracker, backtracker.length());
  assertNull(link);
}
 
Example 12
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkErrorMessage() {
  final String line = "test/widget_test.dart:23:18: Error: Expected ';' after this.";
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, line.length());
  assertNotNull(link);
}
 
Example 13
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkLaunchingLink() {
  String line = "Launching test/widget_test.dart on Android SDK built for x86 in debug mode...\n";
  Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, line.length());
  assertNotNull(link);
}
 
Example 14
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkTestFileUrlLink() {
  final String line = "#4      main.<anonymous closure> (file://" + appDir + "/widget_test.dart:23:18)\n";
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, 659);
  assertNotNull(link);
}
 
Example 15
Source File: SMTRunnerConsoleProperties.java    From consulo with Apache License 2.0 4 votes vote down vote up
@javax.annotation.Nullable
@Override
public Navigatable getErrorNavigatable(@Nonnull final Project project, final @Nonnull String stacktrace) {
  if (myCustomFilter.isEmpty()) {
    return null;
  }

  // iterate stacktrace lines find first navigatable line using
  // stacktrace filters
  final int stacktraceLength = stacktrace.length();
  final String[] lines = StringUtil.splitByLines(stacktrace);
  for (String line : lines) {
    Filter.Result result;
    try {
      result = myCustomFilter.applyFilter(line, stacktraceLength);
    }
    catch (Throwable t) {
      throw new RuntimeException("Error while applying " + myCustomFilter + " to '" + line + "'", t);
    }
    final HyperlinkInfo info = result != null ? result.getFirstHyperlinkInfo() : null;
    if (info != null) {

      // covers 99% use existing cases
      if (info instanceof FileHyperlinkInfo) {
        return ((FileHyperlinkInfo)info).getDescriptor();
      }

      // otherwise
      return new Navigatable() {
        @Override
        public void navigate(boolean requestFocus) {
          info.navigate(project);
        }

        @Override
        public boolean canNavigate() {
          return true;
        }

        @Override
        public boolean canNavigateToSource() {
          return true;
        }
      };
    }
  }
  return null;
}
 
Example 16
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(timeout=1000)
public void checkBadErrorMessage() throws Exception {
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(backtracker, backtracker.length());
  assertNull(link);
}
 
Example 17
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkErrorMessage() {
  final String line = "test/widget_test.dart:23:18: Error: Expected ';' after this.";
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, line.length());
  assertNotNull(link);
}
 
Example 18
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 4 votes vote down vote up
FilterResult(DeltaTracker delta, Filter.Result result) {
  myDelta = delta;
  myResult = result;
}
 
Example 19
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkLaunchingLink() {
  String line = "Launching test/widget_test.dart on Android SDK built for x86 in debug mode...\n";
  Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, line.length());
  assertNotNull(link);
}
 
Example 20
Source File: FlutterConsoleFilterTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void checkTestFileUrlLink() {
  final String line = "#4      main.<anonymous closure> (file://" + appDir + "/widget_test.dart:23:18)\n";
  final Filter.Result link = new FlutterConsoleFilter(fixture.getModule()).applyFilter(line, 659);
  assertNotNull(link);
}