Search in sources :

Example 1 with MultiFileVerifier

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;
}
Also used : Path(java.nio.file.Path) MultiFileVerifier(org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier) PhpFile(org.sonar.plugins.php.api.visitors.PhpFile) File(java.io.File) IssueLocation(org.sonar.plugins.php.api.visitors.IssueLocation)

Example 2 with MultiFileVerifier

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;
}
Also used : CompilationUnitTree(org.sonar.plugins.php.api.tree.CompilationUnitTree) ProjectSymbolData(org.sonar.php.symbols.ProjectSymbolData) HashMap(java.util.HashMap) SymbolTableImpl(org.sonar.php.tree.symbols.SymbolTableImpl) MultiFileVerifier(org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier) PhpFile(org.sonar.plugins.php.api.visitors.PhpFile) File(java.io.File)

Example 3 with MultiFileVerifier

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;
}
Also used : PythonVisitorContext(org.sonar.plugins.python.api.PythonVisitorContext) MultiFileVerifier(org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier) File(java.io.File)

Example 4 with 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;
}
Also used : MultiFileVerifier(org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier) IssueLocation(org.sonar.plugins.python.api.IssueLocation)

Aggregations

MultiFileVerifier (org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier)4 File (java.io.File)3 PhpFile (org.sonar.plugins.php.api.visitors.PhpFile)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 ProjectSymbolData (org.sonar.php.symbols.ProjectSymbolData)1 SymbolTableImpl (org.sonar.php.tree.symbols.SymbolTableImpl)1 CompilationUnitTree (org.sonar.plugins.php.api.tree.CompilationUnitTree)1 IssueLocation (org.sonar.plugins.php.api.visitors.IssueLocation)1 IssueLocation (org.sonar.plugins.python.api.IssueLocation)1 PythonVisitorContext (org.sonar.plugins.python.api.PythonVisitorContext)1