Search in sources :

Example 1 with ProjectSymbolData

use of org.sonar.php.symbols.ProjectSymbolData in project sonar-php by SonarSource.

the class SymbolScanner method scanFile.

@Override
void scanFile(InputFile file) {
    PhpFileImpl phpFile = new PhpFileImpl(file);
    try {
        Tree ast = statistics.time("ProjectSymbolParsing", () -> parser.parse(phpFile.contents()));
        SymbolTableImpl symbolTable = statistics.time("ProjectSymbolTable", () -> SymbolTableImpl.create((CompilationUnitTree) ast, new ProjectSymbolData(), phpFile));
        symbolTable.classSymbolDatas().forEach(projectSymbolData::add);
        symbolTable.functionSymbolDatas().forEach(projectSymbolData::add);
    } catch (RecognitionException e) {
        LOG.debug("Parsing error in " + file);
    }
}
Also used : CompilationUnitTree(org.sonar.plugins.php.api.tree.CompilationUnitTree) ProjectSymbolData(org.sonar.php.symbols.ProjectSymbolData) PhpFileImpl(org.sonar.php.compat.PhpFileImpl) SymbolTableImpl(org.sonar.php.tree.symbols.SymbolTableImpl) CompilationUnitTree(org.sonar.plugins.php.api.tree.CompilationUnitTree) Tree(org.sonar.plugins.php.api.tree.Tree) RecognitionException(com.sonar.sslr.api.RecognitionException)

Example 2 with ProjectSymbolData

use of org.sonar.php.symbols.ProjectSymbolData 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 ProjectSymbolData

use of org.sonar.php.symbols.ProjectSymbolData in project sonar-php by SonarSource.

the class PHPSensor method execute.

@Override
public void execute(SensorContext context) {
    DurationStatistics statistics = new DurationStatistics(context.config());
    FileSystem fileSystem = context.fileSystem();
    FilePredicate phpFilePredicate = fileSystem.predicates().hasLanguage(Php.KEY);
    List<InputFile> inputFiles = new ArrayList<>();
    fileSystem.inputFiles(phpFilePredicate).forEach(inputFiles::add);
    SymbolScanner symbolScanner = new SymbolScanner(context, statistics);
    try {
        symbolScanner.execute(inputFiles);
        ProjectSymbolData projectSymbolData = symbolScanner.getProjectSymbolData();
        new AnalysisScanner(context, projectSymbolData, statistics).execute(inputFiles);
        if (!inSonarLint(context)) {
            processTestsAndCoverage(context);
        }
    } catch (CancellationException e) {
        LOG.info(e.getMessage());
    }
    statistics.log();
}
Also used : ProjectSymbolData(org.sonar.php.symbols.ProjectSymbolData) FilePredicate(org.sonar.api.batch.fs.FilePredicate) DurationStatistics(org.sonar.DurationStatistics) FileSystem(org.sonar.api.batch.fs.FileSystem) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

ProjectSymbolData (org.sonar.php.symbols.ProjectSymbolData)3 SymbolTableImpl (org.sonar.php.tree.symbols.SymbolTableImpl)2 CompilationUnitTree (org.sonar.plugins.php.api.tree.CompilationUnitTree)2 RecognitionException (com.sonar.sslr.api.RecognitionException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DurationStatistics (org.sonar.DurationStatistics)1 FilePredicate (org.sonar.api.batch.fs.FilePredicate)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 InputFile (org.sonar.api.batch.fs.InputFile)1 PhpFileImpl (org.sonar.php.compat.PhpFileImpl)1 Tree (org.sonar.plugins.php.api.tree.Tree)1 PhpFile (org.sonar.plugins.php.api.visitors.PhpFile)1 MultiFileVerifier (org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier)1