@Test public void simple_file() { InputFile inputFile = createInputFile("file1.slang", "" + "fun main(int x) {\nprint (1 == 1); print(\"abc\"); }\nclass A {}"); context.fileSystem().add(inputFile); sensor(checkFactory()).execute(context); assertThat(context.highlightingTypeAt(inputFile.key(), 1, 0)).containsExactly(TypeOfText.KEYWORD); assertThat(context.highlightingTypeAt(inputFile.key(), 1, 3)).isEmpty(); assertThat(context.measure(inputFile.key(), CoreMetrics.NCLOC).value()).isEqualTo(3); assertThat(context.measure(inputFile.key(), CoreMetrics.COMMENT_LINES).value()).isEqualTo(0); assertThat(context.measure(inputFile.key(), CoreMetrics.FUNCTIONS).value()).isEqualTo(1); assertThat(context.measure(inputFile.key(), CoreMetrics.CLASSES).value()).isEqualTo(1); assertThat(context.cpdTokens(inputFile.key()).get(1).getValue()).isEqualTo("print(1==1);print(LITERAL);}"); assertThat(context.measure(inputFile.key(), CoreMetrics.COMPLEXITY).value()).isEqualTo(1); assertThat(context.measure(inputFile.key(), CoreMetrics.STATEMENTS).value()).isEqualTo(2); assertThat(logTester.logs()).contains("1 source files to be analyzed"); }
@Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext sensorContext); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext sensorContext);  }