use of com.contrastsecurity.sarif.Message in project bsl-language-server by 1c-syntax.
the class SarifReporter method createResult.
private static Result createResult(FileInfo fileInfo, Diagnostic diagnostic) {
var uri = Absolute.uri(fileInfo.getPath().toUri()).toString();
var message = new Message().withText(diagnostic.getMessage());
var ruleId = DiagnosticCode.getStringValue(diagnostic.getCode());
var level = severityToResultLevel.get(diagnostic.getSeverity());
var analysisTarget = new ArtifactLocation().withUri(uri);
var locations = List.of(createLocation(diagnostic.getMessage(), uri, diagnostic.getRange()));
var relatedLocations = Optional.ofNullable(diagnostic.getRelatedInformation()).stream().flatMap(Collection::stream).skip(1).map(relatedInformation -> createLocation(relatedInformation.getMessage(), relatedInformation.getLocation().getUri(), relatedInformation.getLocation().getRange())).collect(Collectors.toSet());
return new Result().withMessage(message).withRuleId(ruleId).withLevel(level).withAnalysisTarget(analysisTarget).withLocations(locations).withRelatedLocations(relatedLocations);
}
use of com.contrastsecurity.sarif.Message in project bsl-language-server by 1c-syntax.
the class SarifReporter method createLocation.
private static Location createLocation(String messageString, String uri, Range range) {
var message = new Message().withText(messageString);
var artifactLocation = new ArtifactLocation().withUri(uri);
var region = new Region().withStartLine(range.getStart().getLine() + 1).withStartColumn(range.getStart().getCharacter() + 1).withEndLine(range.getEnd().getLine() + 1).withEndColumn(range.getEnd().getCharacter() + 1);
var physicalLocation = new PhysicalLocation().withArtifactLocation(artifactLocation).withRegion(region);
return new Location().withMessage(message).withPhysicalLocation(physicalLocation);
}
Aggregations