Search in sources :

Example 1 with JavaCheck

use of org.sonar.plugins.java.api.JavaCheck in project JavaForFun by gumartinm.

the class CustomRulesCheckRegistrarTest method whenCreatingCustomJavaCheckRegistrarThenGenerateClassWithSuccess.

@Test
public void whenCreatingCustomJavaCheckRegistrarThenGenerateClassWithSuccess() {
    CustomRulesCheckRegistrar registrar = new CustomRulesCheckRegistrar();
    RegistrarContext registrarContext = new CheckRegistrar.RegistrarContext();
    registrar.register(registrarContext);
    List<Class<? extends JavaCheck>> checkClasses = Lists.newArrayList(registrarContext.checkClasses());
    List<Class<? extends JavaCheck>> testCheckClasses = Lists.newArrayList(registrarContext.testCheckClasses());
    assertThat(checkClasses.size(), is(2));
    assertThat(testCheckClasses.size(), is(0));
    assertThat(registrarContext.repositoryKey(), is(CheckList.REPOSITORY_KEY));
}
Also used : JavaCheck(org.sonar.plugins.java.api.JavaCheck) RegistrarContext(org.sonar.plugins.java.api.CheckRegistrar.RegistrarContext) Test(org.junit.Test)

Example 2 with JavaCheck

use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.

the class JavaSquidSensor method execute.

@Override
public void execute(SensorContext context) {
    javaResourceLocator.setSensorContext(context);
    sonarComponents.setSensorContext(context);
    sonarComponents.setRuleRepositoryKey(CheckList.REPOSITORY_KEY);
    List<Class<? extends JavaCheck>> checks = ImmutableList.<Class<? extends JavaCheck>>builder().addAll(CheckList.getJavaChecks()).addAll(CheckList.getDebugChecks()).build();
    sonarComponents.registerCheckClasses(CheckList.REPOSITORY_KEY, checks);
    sonarComponents.registerTestCheckClasses(CheckList.REPOSITORY_KEY, CheckList.getJavaTestChecks());
    Measurer measurer = new Measurer(fs, context, noSonarFilter);
    JavaSquid squid = new JavaSquid(getJavaVersion(), isXFileEnabled(), sonarComponents, measurer, javaResourceLocator, postAnalysisIssueFilter, sonarComponents.checkClasses());
    squid.scan(getSourceFiles(), getTestFiles());
    sonarComponents.saveAnalysisErrors();
}
Also used : Measurer(org.sonar.java.Measurer) JavaCheck(org.sonar.plugins.java.api.JavaCheck) JavaSquid(org.sonar.java.JavaSquid)

Example 3 with JavaCheck

use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.

the class AnalyzerMessageTest method testAnalyzerMessageOnFile2.

@Test
public void testAnalyzerMessageOnFile2() {
    JavaCheck javaCheck = mock(JavaCheck.class);
    File file = new File("a");
    String message = "analyzer message";
    int cost = 3;
    AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, -5, message, cost);
    assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
    assertThat(analyzerMessage.getFile()).isEqualTo(file);
    assertThat(analyzerMessage.getLine()).isEqualTo(null);
    assertThat(analyzerMessage.getMessage()).isEqualTo(message);
    assertThat(analyzerMessage.getCost()).isEqualTo(cost);
    assertThat(analyzerMessage.primaryLocation()).isNull();
}
Also used : JavaCheck(org.sonar.plugins.java.api.JavaCheck) File(java.io.File) Test(org.junit.Test)

Example 4 with JavaCheck

use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.

the class AnalyzerMessageTest method testAnalyzerMessageWithoutCost.

@Test
public void testAnalyzerMessageWithoutCost() {
    JavaCheck javaCheck = mock(JavaCheck.class);
    File file = new File("a");
    String message = "analyzer message";
    int cost = 0;
    AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, null, message, cost);
    assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
    assertThat(analyzerMessage.getFile()).isEqualTo(file);
    assertThat(analyzerMessage.getLine()).isEqualTo(null);
    assertThat(analyzerMessage.getMessage()).isEqualTo(message);
    assertThat(analyzerMessage.getCost()).isNull();
    assertThat(analyzerMessage.primaryLocation()).isNull();
}
Also used : JavaCheck(org.sonar.plugins.java.api.JavaCheck) File(java.io.File) Test(org.junit.Test)

Example 5 with JavaCheck

use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.

the class AnalyzerMessageTest method testAnalyzerMessage.

@Test
public void testAnalyzerMessage() {
    JavaCheck javaCheck = mock(JavaCheck.class);
    File file = new File("a");
    int line = 5;
    String message = "analyzer message";
    int cost = 3;
    AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, line, message, cost);
    assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
    assertThat(analyzerMessage.getFile()).isEqualTo(file);
    assertThat(analyzerMessage.getLine()).isEqualTo(line);
    assertThat(analyzerMessage.getMessage()).isEqualTo(message);
    assertThat(analyzerMessage.getCost()).isEqualTo(cost);
    AnalyzerMessage.TextSpan location = analyzerMessage.primaryLocation();
    assertThat(location.startLine).isEqualTo(line);
    assertThat(location.startCharacter).isEqualTo(-1);
    assertThat(location.endLine).isEqualTo(line);
    assertThat(location.endCharacter).isEqualTo(-1);
    assertThat(location.isEmpty()).isTrue();
    assertThat(location.toString()).isEqualTo("(5:-1)-(5:-1)");
}
Also used : JavaCheck(org.sonar.plugins.java.api.JavaCheck) File(java.io.File) TextSpan(org.sonar.java.AnalyzerMessage.TextSpan) Test(org.junit.Test)

Aggregations

JavaCheck (org.sonar.plugins.java.api.JavaCheck)21 File (java.io.File)16 Test (org.junit.Test)14 InputFile (org.sonar.api.batch.fs.InputFile)8 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)7 CheckRegistrar (org.sonar.plugins.java.api.CheckRegistrar)7 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)6 RuleKey (org.sonar.api.rule.RuleKey)6 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)4 ImmutableList (com.google.common.collect.ImmutableList)2 RecognitionException (com.sonar.sslr.api.RecognitionException)2 LexerException (com.sonar.sslr.impl.LexerException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NewHighlighting (org.sonar.api.batch.sensor.highlighting.NewHighlighting)2 NewSymbolTable (org.sonar.api.batch.sensor.symbol.NewSymbolTable)2 Issuable (org.sonar.api.issue.Issuable)2 Issue (org.sonar.api.issue.Issue)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2