use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class IssuableSubscriptionVisitorTest method test_custom_rules_report_issues.
@Test
void test_custom_rules_report_issues() throws Exception {
VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(Collections.singletonList(new CustomRule()), new ArrayList<>(), null, new JavaVersionImpl());
JavaAstScanner.scanSingleFileForTests(TestUtils.inputFile("src/test/resources/IssuableSubscriptionClass.java"), visitorsBridge);
Set<AnalyzerMessage> issues = visitorsBridge.lastCreatedTestContext().getIssues();
assertThat(issues).hasSize(7);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class SpringBeansShouldBeAccessibleCheck method addMessageToMap.
private void addMessageToMap(String classPackageName, IdentifierTree classNameTree) {
DefaultJavaFileScannerContext defaultContext = (DefaultJavaFileScannerContext) context;
AnalyzerMessage analyzerMessage = defaultContext.createAnalyzerMessage(this, classNameTree, String.format(MESSAGE_FORMAT, classNameTree.name()));
messagesPerPackage.computeIfAbsent(classPackageName, k -> new ArrayList<>()).add(analyzerMessage);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class CommentedOutCodeLineCheck method collectIssues.
public AnalyzerMessage collectIssues(List<AnalyzerMessage> issues, SyntaxTrivia syntaxTrivia, @Nullable AnalyzerMessage previousRelatedIssue) {
String[] lines = syntaxTrivia.comment().split("\r\n?|\n");
AnalyzerMessage issue = previousRelatedIssue;
for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) {
String line = lines[lineOffset];
if (!isJavadocLink(line) && codeRecognizer.isLineOfCode(line)) {
int startLine = syntaxTrivia.range().start().line() + lineOffset;
int startColumnOffset = (lineOffset == 0 ? syntaxTrivia.range().start().columnOffset() : 0);
if (issue != null) {
issue.flows.add(Collections.singletonList(createAnalyzerMessage(startLine, startColumnOffset, line, "Code")));
} else {
issue = createAnalyzerMessage(startLine, startColumnOffset, line, MESSAGE);
issues.add(issue);
}
}
}
return issue;
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class DefaultJavaFileScannerContext method reportIssue.
private void reportIssue(RegexCheck regexCheck, AnalyzerMessage.TextSpan mainLocation, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) {
List<List<RegexCheck.RegexIssueLocation>> secondariesAsFlows = new ArrayList<>();
secondaries.stream().flatMap(regexIssueLocation -> regexIssueLocation.toSingleLocationItems().stream()).map(Collections::singletonList).forEach(secondariesAsFlows::add);
AnalyzerMessage analyzerMessage = new AnalyzerMessage(regexCheck, inputFile, mainLocation, message, cost != null ? cost : 0);
completeAnalyzerMessageWithFlows(analyzerMessage, secondariesAsFlows, ril -> ril.locations().get(0), RegexCheck.RegexIssueLocation::message);
reportIssue(analyzerMessage);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class DefaultJavaFileScannerContext method createAnalyzerMessage.
protected static AnalyzerMessage createAnalyzerMessage(InputFile inputFile, JavaCheck javaCheck, Tree startTree, @Nullable Tree endTree, String message, Iterable<List<Location>> flows, @Nullable Integer cost) {
AnalyzerMessage.TextSpan location = endTree != null ? AnalyzerMessage.textSpanBetween(startTree, endTree) : AnalyzerMessage.textSpanFor(startTree);
AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, inputFile, location, message, cost != null ? cost : 0);
completeAnalyzerMessageWithFlows(analyzerMessage, flows, loc -> AnalyzerMessage.textSpanFor(loc.syntaxNode), loc -> loc.msg);
return analyzerMessage;
}
Aggregations