Search in sources :

Example 1 with ComplexityVisitor

use of org.sonar.plugins.web.analyzers.ComplexityVisitor in project sonar-web by SonarSource.

the class TestHelper method scan.

public static WebSourceCode scan(File file, DefaultNodeVisitor visitor) {
    FileReader fileReader;
    try {
        fileReader = new FileReader(file);
    } catch (FileNotFoundException e) {
        throw Throwables.propagate(e);
    }
    WebSourceCode result = new WebSourceCode(new DefaultInputFile("key", file.getPath()).setLanguage(WebConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()));
    HtmlAstScanner walker = new HtmlAstScanner(ImmutableList.of(new PageCountLines(), new ComplexityVisitor()));
    walker.addVisitor(visitor);
    walker.scan(new PageLexer().parse(fileReader), result, Charsets.UTF_8);
    return result;
}
Also used : PageLexer(org.sonar.plugins.web.lex.PageLexer) ComplexityVisitor(org.sonar.plugins.web.analyzers.ComplexityVisitor) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) FileNotFoundException(java.io.FileNotFoundException) WebSourceCode(org.sonar.plugins.web.visitor.WebSourceCode) PageCountLines(org.sonar.plugins.web.analyzers.PageCountLines) FileReader(java.io.FileReader) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) HtmlAstScanner(org.sonar.plugins.web.visitor.HtmlAstScanner)

Example 2 with ComplexityVisitor

use of org.sonar.plugins.web.analyzers.ComplexityVisitor in project sonar-web by SonarSource.

the class WebSensor method setupScanner.

/**
 * Create PageScanner with Visitors.
 */
private HtmlAstScanner setupScanner(SensorContext context) {
    HtmlAstScanner scanner = new HtmlAstScanner(ImmutableList.of(new WebTokensVisitor(context), new PageCountLines(), new ComplexityVisitor(), new NoSonarScanner(noSonarFilter)));
    for (Object check : checks.all()) {
        ((AbstractPageCheck) check).setRuleKey(checks.ruleKey(check));
        scanner.addVisitor((AbstractPageCheck) check);
    }
    return scanner;
}
Also used : ComplexityVisitor(org.sonar.plugins.web.analyzers.ComplexityVisitor) PageCountLines(org.sonar.plugins.web.analyzers.PageCountLines) NoSonarScanner(org.sonar.plugins.web.visitor.NoSonarScanner) AbstractPageCheck(org.sonar.plugins.web.checks.AbstractPageCheck) HtmlAstScanner(org.sonar.plugins.web.visitor.HtmlAstScanner)

Aggregations

ComplexityVisitor (org.sonar.plugins.web.analyzers.ComplexityVisitor)2 PageCountLines (org.sonar.plugins.web.analyzers.PageCountLines)2 HtmlAstScanner (org.sonar.plugins.web.visitor.HtmlAstScanner)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 AbstractPageCheck (org.sonar.plugins.web.checks.AbstractPageCheck)1 PageLexer (org.sonar.plugins.web.lex.PageLexer)1 NoSonarScanner (org.sonar.plugins.web.visitor.NoSonarScanner)1 WebSourceCode (org.sonar.plugins.web.visitor.WebSourceCode)1