com.intellij.execution.filters.Filter Java Examples

The following examples show how to use com.intellij.execution.filters.Filter. 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: FlutterLogEntry.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public FlutterLogEntry(long timestamp,
                       @NotNull String category,
                       int level,
                       @Nullable String message,
                       @NotNull Kind kind,
                       @NotNull List<StyledText> styledText,
                       @NotNull List<Filter> filters,
                       @Nullable SimpleTextAttributes inheritedStyle) {
  this.timestamp = timestamp;
  this.category = category;
  this.level = level;
  this.message = StringUtil.notNullize(message);
  this.kind = kind;
  this.styledText = styledText;
  this.filters = filters;
  this.inheritedStyle = inheritedStyle;
}
 
Example #2
Source File: FlutterLogEntry.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public FlutterLogEntry(long timestamp,
                       @NotNull String category,
                       int level,
                       @Nullable String message,
                       @NotNull Kind kind,
                       @NotNull List<StyledText> styledText,
                       @NotNull List<Filter> filters,
                       @Nullable SimpleTextAttributes inheritedStyle) {
  this.timestamp = timestamp;
  this.category = category;
  this.level = level;
  this.message = StringUtil.notNullize(message);
  this.kind = kind;
  this.styledText = styledText;
  this.filters = filters;
  this.inheritedStyle = inheritedStyle;
}
 
Example #3
Source File: ConsoleViewUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static List<Filter> computeConsoleFilters(@Nonnull Project project, @Nullable ConsoleView consoleView, @Nonnull GlobalSearchScope searchScope) {
  List<Filter> result = new ArrayList<>();
  for (ConsoleFilterProvider eachProvider : ConsoleFilterProvider.FILTER_PROVIDERS.getExtensions()) {
    Filter[] filters;
    if (consoleView != null && eachProvider instanceof ConsoleDependentFilterProvider) {
      filters = ((ConsoleDependentFilterProvider)eachProvider).getDefaultFilters(consoleView, project, searchScope);
    }
    else if (eachProvider instanceof ConsoleFilterProviderEx) {
      filters = ((ConsoleFilterProviderEx)eachProvider).getDefaultFilters(project, searchScope);
    }
    else {
      filters = eachProvider.getDefaultFilters(project);
    }
    ContainerUtil.addAll(result, filters);
  }
  return result;
}
 
Example #4
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 6 votes vote down vote up
void highlightHyperlinks(@Nonnull Project project, @Nonnull Filter customFilter, final int startLine, final int endLine) {
  if (endLine < 0) return;

  myQueue.offer(new HighlighterJob(project, customFilter, startLine, endLine, myEditor.getDocument()));
  if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
    runTasks();
    highlightAvailableResults();
    return;
  }

  Promise<?> promise = ReadAction.nonBlocking(this::runTasks).submit(ourExecutor);

  if (isQuick(promise)) {
    highlightAvailableResults();
  }
  else {
    promise.onSuccess(__ -> {
      if (hasResults()) {
        ApplicationManager.getApplication().invokeLater(this::highlightAvailableResults, ModalityState.any());
      }
    });
  }
}
 
Example #5
Source File: ConsoleBuilder.java    From CppTools with Apache License 2.0 6 votes vote down vote up
public ConsoleBuilder(String _title,
               BuildState _buildState,
               Project _project,
               Filter _filter,
               Runnable _showOptionsCallBack,
               Runnable _toRerunAction,
               Runnable _onEndAction
               ) {
  buildState = _buildState;
  title = _title;
  project = _project;
  filter = _filter;
  showOptionsCallBack = _showOptionsCallBack;
  onEndAction = _onEndAction;
  toRerunAction = _toRerunAction;
}
 
Example #6
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 #7
Source File: BlazeCommandGenericRunConfigurationRunner.java    From intellij with Apache License 2.0 6 votes vote down vote up
public BlazeCommandRunProfileState(ExecutionEnvironment environment) {
  super(environment);
  this.configuration = getConfiguration(environment);
  this.handlerState =
      (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
  Project project = environment.getProject();
  this.consoleFilters =
      ImmutableList.<Filter>builder()
          .add(
              new BlazeTargetFilter(true),
              new UrlFilter(),
              new IssueOutputFilter(
                  project,
                  WorkspaceRoot.fromProject(project),
                  BlazeInvocationContext.ContextType.RunConfiguration,
                  false))
          .build();
}
 
Example #8
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 #9
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Deprecated
public void highlightHyperlinks(@Nonnull Filter customFilter, final Filter predefinedMessageFilter, final int line1, final int endLine) {
  highlightHyperlinks((line, entireLength) -> {
    Filter.Result result = customFilter.applyFilter(line, entireLength);
    return result != null ? result : predefinedMessageFilter.applyFilter(line, entireLength);
  }, line1, endLine);
}
 
Example #10
Source File: BlazeConsoleView.java    From intellij with Apache License 2.0 5 votes vote down vote up
private Filter[] getFilters(GlobalSearchScope scope, ConsoleFilterProvider provider) {
  if (provider instanceof ConsoleDependentFilterProvider) {
    return ((ConsoleDependentFilterProvider) provider)
        .getDefaultFilters(consoleView, project, scope);
  }
  if (provider instanceof ConsoleFilterProviderEx) {
    return ((ConsoleFilterProviderEx) provider).getDefaultFilters(project, scope);
  }
  return provider.getDefaultFilters(project);
}
 
Example #11
Source File: AsyncFilterRunner.java    From consulo with Apache License 2.0 5 votes vote down vote up
HighlighterJob(@Nonnull Project project, @Nonnull Filter filter, int startLine, int endLine, @Nonnull Document document) {
  myProject = project;
  this.startLine = new AtomicInteger(startLine);
  this.endLine = endLine;
  this.filter = filter;

  delta = new DeltaTracker(document, document.getLineEndOffset(endLine));

  snapshot = ((DocumentImpl)document).freeze();
}
 
Example #12
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 #13
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 #14
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 #15
Source File: LineInfo.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LineInfo(@NotNull String line,
                @NotNull List<StyledText> styledText,
                FlutterLogEntry.Kind kind,
                @NotNull String category,
                @NotNull List<Filter> filters,
                @Nullable SimpleTextAttributes inheritedStyle) {
  this.line = line;
  this.styledText = styledText;
  this.kind = kind;
  this.category = category;
  this.filters = filters;
  this.inheritedStyle = inheritedStyle;
}
 
Example #16
Source File: BlazeCidrLauncher.java    From intellij with Apache License 2.0 5 votes vote down vote up
private ImmutableList<Filter> getConsoleFilters() {
  return ImmutableList.of(
      new BlazeTargetFilter(true),
      new UrlFilter(),
      new IssueOutputFilter(
          project,
          WorkspaceRoot.fromProject(project),
          BlazeInvocationContext.ContextType.RunConfiguration,
          false));
}
 
Example #17
Source File: LineInfo.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LineInfo(@NotNull String line,
                @NotNull List<StyledText> styledText,
                FlutterLogEntry.Kind kind,
                @NotNull String category,
                @NotNull List<Filter> filters,
                @Nullable SimpleTextAttributes inheritedStyle) {
  this.line = line;
  this.styledText = styledText;
  this.kind = kind;
  this.category = category;
  this.filters = filters;
  this.inheritedStyle = inheritedStyle;
}
 
Example #18
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 #19
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 #20
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 #21
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 #22
Source File: FlutterLogEntryParser.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
static List<Filter> createMessageFilters(@NotNull Project project, @Nullable Module module) {
  final List<Filter> filters = new ArrayList<>();
  if (module != null) {
    filters.add(new FlutterConsoleFilter(module));
  }
  filters.addAll(Arrays.asList(
    new DartConsoleFilter(project, project.getBaseDir()),
    new UrlFilter()
  ));
  return filters;
}
 
Example #23
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 #24
Source File: TestProxyPrinterProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public Printer getPrinterByType(@Nonnull String nodeType, @Nonnull String nodeName, @Nullable String nodeArguments) {
  Filter filter = myFilterProvider.getFilter(nodeType, nodeName, nodeArguments);
  if (filter != null && !Disposer.isDisposed(myTestOutputConsoleView)) {
    return new HyperlinkPrinter(myTestOutputConsoleView, HyperlinkPrinter.ERROR_CONTENT_TYPE, filter);
  }
  return null;
}
 
Example #25
Source File: BlazeConsoleScope.java    From intellij with Apache License 2.0 5 votes vote down vote up
private BlazeConsoleScope(
    Project project,
    @Nullable ProgressIndicator progressIndicator,
    FocusBehavior popupBehavior,
    boolean clearPreviousState,
    ImmutableList<Filter> customFilters) {
  this.blazeConsoleService = BlazeConsoleService.getInstance(project);
  this.progressIndicator = progressIndicator;
  this.popupBehavior = popupBehavior;
  this.clearPreviousState = clearPreviousState;
  this.customFilters = customFilters;
}
 
Example #26
Source File: TestLogFilter.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public Filter[] getDefaultFilters(Project project) {
  return Blaze.isBlazeProject(project)
      ? new Filter[] {new TestLogFilter(project)}
      : new Filter[0];
}
 
Example #27
Source File: BlazeCppPathConsoleFilter.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public Filter[] getDefaultFilters(Project project) {
  return Blaze.isBlazeProject(project)
      ? new Filter[] {new BlazeCppPathConsoleFilter(project)}
      : new Filter[0];
}
 
Example #28
Source File: SMTRunnerConsoleProperties.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addStackTraceFilter(final Filter filter) {
  myCustomFilter.addFilter(filter);
}
 
Example #29
Source File: BlazePyRunConfigurationRunner.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static ImmutableList<Filter> getFilters() {
  return ImmutableList.<Filter>builder()
      .add(new BlazeTargetFilter(true))
      .add(new UrlFilter())
      .build();
}
 
Example #30
Source File: BlazePyTracebackFilter.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public Filter[] getDefaultFilters(Project project) {
  return Blaze.isBlazeProject(project)
      ? new Filter[] {new BlazePyTracebackFilter(project)}
      : new Filter[0];
}