Class Checks<C>


  • public class Checks<C>
    extends java.lang.Object
    Instantiates checks (objects that provide implementation of coding rules) that use sonar-check-api annotations. Checks are selected and configured from the Quality profiles enabled on the current module.
    Example of check class:
       @org.sonar.check.Rule(key = "S001")
       public class CheckS001 {
         @org.sonar.check.RuleProperty
         private String pattern;
    
         public String getPattern() {
           return pattern;
         }
     }
     
    How to use:
       public class MyRuleEngine extends BatchExtension {
         private final CheckFactory checkFactory;
    
         public MyRuleEngine(CheckFactory checkFactory) {
           this.checkFactory = checkFactory;
         }
    
         public void execute() {
           Checks checks = checkFactory.create("my-rule-repository");
           checks.addAnnotatedChecks(CheckS001.class);
           // checks.all() contains an instance of CheckS001
           // with field "pattern" set to the value specified in
           // the Quality profile
    
           // Checks are used to detect issues on source code
    
           // checks.ruleKey(obj) can be used to create the related issues
         }
       }
     

    It replaces org.sonar.api.checks.AnnotationCheckFactory
    Since:
    4.2
    • Method Detail

      • of

        @CheckForNull
        public C of​(RuleKey ruleKey)
      • all

        public java.util.Collection<C> all()
      • ruleKey

        @CheckForNull
        public RuleKey ruleKey​(C check)
      • addAnnotatedChecks

        public Checks<C> addAnnotatedChecks​(java.lang.Object... checkClassesOrObjects)
      • addAnnotatedChecks

        public Checks<C> addAnnotatedChecks​(java.lang.Iterable checkClassesOrObjects)