@Test void shouldParseRegularExpressionsIssue17225() { Report tasks = new TaskScannerBuilder() .setHighTasks("^.*(TODO(?:[0-9]*))(.*)$") .setCaseMode(CaseMode.CASE_SENSITIVE) .setMatcherMode(MatcherMode.REGEXP_MATCH) .build() .scanTasks(read("regexp.txt"), ISSUE_BUILDER); assertThat(tasks).hasSize(5); assertThat(tasks.get(0)).hasSeverity(Severity.WARNING_HIGH) .hasType("TODO1") .hasLineStart(1) .hasMessage("erstes"); assertThat(tasks.get(1)).hasSeverity(Severity.WARNING_HIGH) .hasType("TODO2") .hasLineStart(2) .hasMessage("zweites"); assertThat(tasks.get(2)).hasSeverity(Severity.WARNING_HIGH) .hasType("TODO3") .hasLineStart(3) .hasMessage("drittes"); assertThat(tasks.get(3)).hasSeverity(Severity.WARNING_HIGH) .hasType("TODO4") .hasLineStart(4) .hasMessage("viertes"); assertThat(tasks.get(4)).hasSeverity(Severity.WARNING_HIGH) .hasType("TODO20") .hasLineStart(5) .hasMessage("zwanzigstes"); }
Report scanTasks(final Iterator<String> lines, final IssueBuilder builder) { Report report = new Report(); if (isPatternInvalid) { report.logError("%s", errors.toString()); return report; } for (int lineNumber = 1; lines.hasNext(); lineNumber++) { String line = lines.next(); for (Severity severity : Severity.getPredefinedValues()) { if (patterns.containsKey(severity)) { Matcher matcher = patterns.get(severity).matcher(line); if (matcher.matches() && matcher.groupCount() == 2) { String message = matcher.group(2).trim(); builder.setMessage(StringUtils.removeStart(message, ":").trim()); String tag = matcher.group(1); if (isUppercase) { builder.setType(StringUtils.upperCase(tag)); } else { builder.setType(tag); } report.add(builder.setSeverity(severity).setLineStart(lineNumber).build()); } } } } return report; }
TaskScanner { Report scanTasks(final Iterator<String> lines, final IssueBuilder builder) { Report report = new Report(); if (isPatternInvalid) { report.logError("%s", errors.toString()); return report; } for (int lineNumber = 1; lines.hasNext(); lineNumber++) { String line = lines.next(); for (Severity severity : Severity.getPredefinedValues()) { if (patterns.containsKey(severity)) { Matcher matcher = patterns.get(severity).matcher(line); if (matcher.matches() && matcher.groupCount() == 2) { String message = matcher.group(2).trim(); builder.setMessage(StringUtils.removeStart(message, ":").trim()); String tag = matcher.group(1); if (isUppercase) { builder.setType(StringUtils.upperCase(tag)); } else { builder.setType(tag); } report.add(builder.setSeverity(severity).setLineStart(lineNumber).build()); } } } } return report; } }
TaskScanner { Report scanTasks(final Iterator<String> lines, final IssueBuilder builder) { Report report = new Report(); if (isPatternInvalid) { report.logError("%s", errors.toString()); return report; } for (int lineNumber = 1; lines.hasNext(); lineNumber++) { String line = lines.next(); for (Severity severity : Severity.getPredefinedValues()) { if (patterns.containsKey(severity)) { Matcher matcher = patterns.get(severity).matcher(line); if (matcher.matches() && matcher.groupCount() == 2) { String message = matcher.group(2).trim(); builder.setMessage(StringUtils.removeStart(message, ":").trim()); String tag = matcher.group(1); if (isUppercase) { builder.setType(StringUtils.upperCase(tag)); } else { builder.setType(tag); } report.add(builder.setSeverity(severity).setLineStart(lineNumber).build()); } } } } return report; } TaskScanner(final @CheckForNull String highTags, final @CheckForNull String normalTags,
            final @CheckForNull String lowTags,
            final CaseMode caseMode, final MatcherMode matcherMode); }
TaskScanner { Report scanTasks(final Iterator<String> lines, final IssueBuilder builder) { Report report = new Report(); if (isPatternInvalid) { report.logError("%s", errors.toString()); return report; } for (int lineNumber = 1; lines.hasNext(); lineNumber++) { String line = lines.next(); for (Severity severity : Severity.getPredefinedValues()) { if (patterns.containsKey(severity)) { Matcher matcher = patterns.get(severity).matcher(line); if (matcher.matches() && matcher.groupCount() == 2) { String message = matcher.group(2).trim(); builder.setMessage(StringUtils.removeStart(message, ":").trim()); String tag = matcher.group(1); if (isUppercase) { builder.setType(StringUtils.upperCase(tag)); } else { builder.setType(tag); } report.add(builder.setSeverity(severity).setLineStart(lineNumber).build()); } } } } return report; } TaskScanner(final @CheckForNull String highTags, final @CheckForNull String normalTags,
            final @CheckForNull String lowTags,
            final CaseMode caseMode, final MatcherMode matcherMode); String getErrors(); Report scan(final Path file, final Charset charset); }
TaskScanner { Report scanTasks(final Iterator<String> lines, final IssueBuilder builder) { Report report = new Report(); if (isPatternInvalid) { report.logError("%s", errors.toString()); return report; } for (int lineNumber = 1; lines.hasNext(); lineNumber++) { String line = lines.next(); for (Severity severity : Severity.getPredefinedValues()) { if (patterns.containsKey(severity)) { Matcher matcher = patterns.get(severity).matcher(line); if (matcher.matches() && matcher.groupCount() == 2) { String message = matcher.group(2).trim(); builder.setMessage(StringUtils.removeStart(message, ":").trim()); String tag = matcher.group(1); if (isUppercase) { builder.setType(StringUtils.upperCase(tag)); } else { builder.setType(tag); } report.add(builder.setSeverity(severity).setLineStart(lineNumber).build()); } } } } return report; } TaskScanner(final @CheckForNull String highTags, final @CheckForNull String normalTags,
            final @CheckForNull String lowTags,
            final CaseMode caseMode, final MatcherMode matcherMode); String getErrors(); Report scan(final Path file, final Charset charset);  }