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)); } }
public static IssueEntry from(Issue issue, File file) { if (issue instanceof PreciseIssue) { final PreciseIssue preciseIssue = (PreciseIssue) issue; final IssueLocation primaryLocation = preciseIssue.primaryLocation(); String locationBlurb = "P[" + primaryLocation.startLine() + "/" + primaryLocation.startLineOffset() + "," + primaryLocation.endLine() + "/" + primaryLocation.endLineOffset() + "]"; return new IssueEntry(primaryLocation.startLine(), primaryLocation.endLine(), primaryLocation.message(), locationBlurb, file); } if (issue instanceof LineIssue) { final LineIssue lineIssue = (LineIssue) issue; return new IssueEntry(lineIssue.line(), lineIssue.line(), lineIssue.message(), "L[" + lineIssue.line() + "]", file); } if (issue instanceof FileIssue) { final FileIssue fileIssue = (FileIssue) issue; return new IssueEntry(0, 0, fileIssue.message(), "F", file); } throw new IllegalArgumentException("Unsupported issue type : " + issue.getClass()); }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange( location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange( location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange( location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static void verifyIssue(TestIssue expected, Issue actual) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\""); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo((double) expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (!expected.secondaryLocations().isEmpty()) { assertSecondary(actual, expected); } }