use of org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier in project sonar-php by SonarSource.
the class PHPCheckVerifier method addPreciseIssue.
private static MultiFileVerifier.Issue addPreciseIssue(MultiFileVerifier verifier, PreciseIssue preciseIssue, PhpFile file) {
IssueLocation location = preciseIssue.primaryLocation();
String message = location.message();
Preconditions.checkNotNull(message, "Primary location message should never be null.");
MultiFileVerifier.Issue issueBuilder = verifier.reportIssue(path(file), message).onRange(location.startLine(), location.startLineOffset() + 1, location.endLine(), location.endLineOffset());
for (IssueLocation secondary : preciseIssue.secondaryLocations()) {
String filePath = secondary.filePath();
Path path = filePath == null ? path(file) : (new File(filePath)).toPath();
issueBuilder.addSecondary(path, secondary.startLine(), secondary.startLineOffset() + 1, secondary.endLine(), secondary.endLineOffset(), secondary.message());
}
return issueBuilder;
}
use of org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier in project sonar-php by SonarSource.
the class PHPCheckVerifier method createVerifier.
/**
* Internal use only. Subject to changes.
*/
protected MultiFileVerifier createVerifier(List<File> files, PHPCheck check) {
MultiFileVerifier verifier = MultiFileVerifier.create(files.get(0).toPath(), UTF_8);
ProjectSymbolData projectSymbolData = new ProjectSymbolData();
Map<File, CompilationUnitTree> astByFile = new HashMap<>();
for (File file : files) {
PhpTestFile phpFile = new PhpTestFile(file);
CompilationUnitTree ast = (CompilationUnitTree) parser.parse(phpFile.contents());
astByFile.put(file, ast);
SymbolTableImpl symbolTable = SymbolTableImpl.create(ast, new ProjectSymbolData(), phpFile);
symbolTable.classSymbolDatas().forEach(projectSymbolData::add);
symbolTable.functionSymbolDatas().forEach(projectSymbolData::add);
}
for (File file : files) {
addFile(check, verifier, astByFile.get(file), new PhpTestFile(file), projectSymbolData);
}
return verifier;
}
use of org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier in project sonar-python by SonarSource.
the class PythonCheckVerifier method createVerifier.
private static MultiFileVerifier createVerifier(List<File> files, PythonCheck check, ProjectLevelSymbolTable projectLevelSymbolTable, @Nullable File baseDir) {
MultiFileVerifier multiFileVerifier = MultiFileVerifier.create(files.get(0).toPath(), UTF_8);
for (File file : files) {
PythonVisitorContext context = baseDir != null ? TestPythonVisitorRunner.createContext(file, null, pythonPackageName(file, baseDir.getAbsolutePath()), projectLevelSymbolTable) : TestPythonVisitorRunner.createContext(file);
addFileIssues(check, multiFileVerifier, file, context);
}
return multiFileVerifier;
}
use of org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier in project sonar-python by SonarSource.
the class PythonCheckVerifier method addPreciseIssue.
private static MultiFileVerifier.Issue addPreciseIssue(Path path, MultiFileVerifier verifier, PreciseIssue preciseIssue) {
IssueLocation location = preciseIssue.primaryLocation();
String message = location.message();
Preconditions.checkNotNull(message, "Primary location message should never be null.");
if (location.startLine() == IssueLocation.UNDEFINED_LINE) {
return verifier.reportIssue(path, message).onFile();
}
if (location.startLineOffset() == IssueLocation.UNDEFINED_OFFSET) {
return verifier.reportIssue(path, message).onLine(location.startLine());
}
MultiFileVerifier.Issue issueBuilder = verifier.reportIssue(path, message).onRange(location.startLine(), location.startLineOffset() + 1, location.endLine(), location.endLineOffset());
for (IssueLocation secondary : preciseIssue.secondaryLocations()) {
issueBuilder.addSecondary(path, secondary.startLine(), secondary.startLineOffset() + 1, secondary.endLine(), secondary.endLineOffset(), secondary.message());
}
return issueBuilder;
}
Aggregations