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);
}
}
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;
}
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();
}
Aggregations