private static void assertSecondary(Issue actualIssue, TestIssue expectedIssue) { List<Location> expectedLocations = expectedIssue.secondaryLocations(); List<IssueLocation> actualLocations = actualIssue instanceof PreciseIssue ? ((PreciseIssue) actualIssue).secondaryLocations() : new ArrayList<>(); String format = "Bad secondary location at line %s (issue at line %s): %s"; for (Location expected : expectedLocations) { IssueLocation actual = secondary(expected.line(), actualLocations); if (actual != null) { if (expected.message() != null) { assertThat(actual.message()).as(String.format(format, expected.line(), line(actualIssue), "bad message")).isEqualTo(expected.message()); } if (expected.startColumn() != null) { assertThat(actual.startLineOffset() + 1).as(String.format(format, expected.line(), line(actualIssue), "bad start column")).isEqualTo(expected.startColumn()); assertThat(actual.endLineOffset() + 1).as(String.format(format, expected.line(), line(actualIssue), "bad end column")).isEqualTo(expected.endColumn()); } actualLocations.remove(actual); } else { throw new AssertionError("Missing secondary location at line " + expected.line() + " for issue at line " + expectedIssue.line()); } } if (!actualLocations.isEmpty()) { IssueLocation location = actualLocations.get(0); throw new AssertionError("Unexpected secondary location at line " + location.startLine() + " for issue at line " + line(actualIssue)); } }
private static void savePreciseIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); newIssue .forRule(ruleKey) .at(newLocation(inputFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.gap(issue.cost()); } for (IssueLocation secondary : issue.secondaryLocations()) { newIssue.addLocation(newLocation(inputFile, newIssue, secondary)); } newIssue.save(); }
private static void savePreciseIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); newIssue .forRule(ruleKey) .at(newLocation(inputFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.gap(issue.cost()); } for (IssueLocation secondary : issue.secondaryLocations()) { newIssue.addLocation(newLocation(inputFile, newIssue, secondary)); } newIssue.save(); }
public static void save(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, PreciseIssue issue) { NewIssue newIssue = sensorContext.newIssue(); newIssue .forRule(ruleKey) .at(newLocation(inputFile, newIssue, issue.primaryLocation())); if (issue.cost() != null) { newIssue.effortToFix(issue.cost()); } for (IssueLocation secondary : issue.secondaryLocations()) { newIssue.addLocation(newLocation(inputFile, newIssue, secondary)); } newIssue.save(); }