@Test public void test_rule_with_gap() { InputFile inputFile = createInputFile("file1.slang", "" + "fun f() { print(\"string literal\"); print(\"string literal\"); print(\"string literal\"); }"); context.fileSystem().add(inputFile); CheckFactory checkFactory = checkFactory("S1192"); sensor(checkFactory).execute(context); Collection<Issue> issues = context.allIssues(); assertThat(issues).hasSize(1); Issue issue = issues.iterator().next(); assertThat(issue.ruleKey().rule()).isEqualTo("S1192"); IssueLocation location = issue.primaryLocation(); assertThat(location.inputComponent()).isEqualTo(inputFile); assertThat(location.message()).isEqualTo("Define a constant instead of duplicating this literal \"string literal\" 3 times."); assertTextRange(location.textRange()).hasRange(1, 16, 1, 32); assertThat(issue.gap()).isEqualTo(2.0); }
@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);  }