SonarComponents { public List<JavaCheck> jspCodeVisitors() { return allChecks.stream() .flatMap(javaChecks -> javaChecks.all().stream()) .filter(check -> check instanceof JspCodeVisitor) .collect(Collectors.toList()); } SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath,
                         CheckFactory checkFactory, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable CheckRegistrar[] checkRegistrars, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable ProjectDefinition projectDefinition, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable CheckRegistrar[] checkRegistrars, @Nullable ProjectDefinition projectDefinition,
                         SonarJavaIssueFilter postAnalysisIssueFilter); void setSensorContext(SensorContext context); FileLinesContext fileLinesContextFor(InputFile inputFile); NewSymbolTable symbolizableFor(InputFile inputFile); NewHighlighting highlightableFor(InputFile inputFile); List<File> getJavaClasspath(); List<File> getJavaTestClasspath(); List<File> getJspClasspath(); void registerCheckClasses(String repositoryKey, Iterable<Class<? extends JavaCheck>> checkClasses); JavaCheck[] checkClasses(); Iterable<Checks<JavaCheck>> checks(); void registerTestCheckClasses(String repositoryKey, Iterable<Class<? extends JavaCheck>> checkClasses); Collection<JavaCheck> testCheckClasses(); List<JavaCheck> jspCodeVisitors(); RuleKey getRuleKey(JavaCheck check); void addIssue(InputComponent inputComponent, JavaCheck check, int line, String message, @Nullable Integer cost); void reportIssue(AnalyzerMessage analyzerMessage); boolean reportAnalysisError(RecognitionException re, InputFile inputFile); boolean isSonarLintContext(); List<String> fileLines(InputFile inputFile); String inputFileContents(InputFile inputFile); boolean analysisCancelled(); boolean shouldFailAnalysisOnException(); File workDir(); InputComponent project(); static final String FAIL_ON_EXCEPTION_KEY; }
@Test void should_return_generated_code_visitors() throws Exception { ActiveRules activeRules = new ActiveRulesBuilder() .addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("custom", "jsp")).build()) .build(); CheckFactory checkFactory = new CheckFactory(activeRules); JspCodeCheck check = new JspCodeCheck(); SonarComponents sonarComponents = new SonarComponents(null, null, null, null, checkFactory, new CheckRegistrar[]{getRegistrar(check)}, null); List<JavaCheck> checks = sonarComponents.jspCodeVisitors(); assertThat(checks) .isNotEmpty() .allMatch(JspCodeCheck.class::isInstance); sonarComponents = new SonarComponents(null, null, null, null, checkFactory, null); assertThat(sonarComponents.jspCodeVisitors()).isEmpty(); }