Search in sources :

Example 1 with Check

use of org.sonar.commonruleengine.checks.Check in project sonar-go by SonarSource.

the class Engine method visit.

private void visit(UastNode uast) {
    metricsVisitor.visitNode(uast);
    Set<Check> checks = uast.kinds.stream().flatMap(kind -> engineContext.registeredChecks(kind).stream()).collect(Collectors.toSet());
    for (Check check : checks) {
        check.visitNode(uast);
    }
    for (UastNode child : uast.children) {
        visit(child);
    }
    for (Check check : checks) {
        check.leaveNode(uast);
    }
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) List(java.util.List) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) UastNode(org.sonar.uast.UastNode) Collectors(java.util.stream.Collectors) Check(org.sonar.commonruleengine.checks.Check) Check(org.sonar.commonruleengine.checks.Check) UastNode(org.sonar.uast.UastNode)

Example 2 with Check

use of org.sonar.commonruleengine.checks.Check in project sonar-go by SonarSource.

the class GoSensorTest method getSensor.

private GoSensor getSensor(String... activeRuleArray) {
    Set<String> activeRuleSet = new HashSet<>(Arrays.asList(activeRuleArray));
    List<Class> ruleClasses = GoChecks.getChecks();
    List<String> allKeys = ruleClasses.stream().map(ruleClass -> ((org.sonar.check.Rule) ruleClass.getAnnotations()[0]).key()).collect(Collectors.toList());
    ActiveRulesBuilder rulesBuilder = new ActiveRulesBuilder();
    allKeys.forEach(key -> {
        NewActiveRule newActiveRule = rulesBuilder.create(RuleKey.of(GoRulesDefinition.REPOSITORY_KEY, key));
        if (activeRuleSet.contains(key)) {
            newActiveRule.activate();
        }
    });
    ActiveRules activeRules = rulesBuilder.build();
    CheckFactory checkFactory = new CheckFactory(activeRules);
    Checks<Check> checks = checkFactory.create(GoRulesDefinition.REPOSITORY_KEY);
    checks.addAnnotatedChecks((Iterable) ruleClasses);
    return new GoSensor(checkFactory, fileLinesContextFactory);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) InputFile(org.sonar.api.batch.fs.InputFile) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) HashMap(java.util.HashMap) ActiveRules(org.sonar.api.batch.rule.ActiveRules) Mockito.spy(org.mockito.Mockito.spy) HashSet(java.util.HashSet) FileLinesContext(org.sonar.api.measures.FileLinesContext) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) CheckFactory(org.sonar.api.batch.rule.CheckFactory) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) Checks(org.sonar.api.batch.rule.Checks) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) Check(org.sonar.commonruleengine.checks.Check) Awaitility.await(org.awaitility.Awaitility.await) Files(java.nio.file.Files) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Set(java.util.Set) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) CoreMetrics(org.sonar.api.measures.CoreMetrics) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) TypeOfText(org.sonar.api.batch.sensor.highlighting.TypeOfText) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleKey(org.sonar.api.rule.RuleKey) Mockito.any(org.mockito.Mockito.any) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.mock(org.mockito.Mockito.mock) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Check(org.sonar.commonruleengine.checks.Check) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRules(org.sonar.api.batch.rule.ActiveRules) CheckFactory(org.sonar.api.batch.rule.CheckFactory) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 InputFile (org.sonar.api.batch.fs.InputFile)2 Check (org.sonar.commonruleengine.checks.Check)2 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Awaitility.await (org.awaitility.Awaitility.await)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)1