org.sonar.squidbridge.annotations.RuleTemplate Java Examples

The following examples show how to use org.sonar.squidbridge.annotations.RuleTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SonarDefinition.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
protected void newRule(Class<?> ruleClass, NewRepository repository) {

    org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class);
    if (ruleAnnotation == null) {
        throw new IllegalArgumentException("No Rule annotation was found on " + ruleClass);
    }
    String ruleKey = ruleAnnotation.key();
    if (StringUtils.isEmpty(ruleKey)) {
        throw new IllegalArgumentException("No key is defined in Rule annotation of " + ruleClass);
    }
    NewRule rule = repository.rule(ruleKey);
    if (rule == null) {
        throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key());
    }
    ruleMetadata(ruleClass, rule);

    rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null);
    if (ruleAnnotation.cardinality() == Cardinality.MULTIPLE) {
        throw new IllegalArgumentException("Cardinality is not supported, use the RuleTemplate annotation instead for " + ruleClass);
    }
}
 
Example #2
Source File: SonarDefinition.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
protected void newRule(Class<?> ruleClass, NewRepository repository) {

    org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(ruleClass, org.sonar.check.Rule.class);
    if (ruleAnnotation == null) {
        throw new IllegalArgumentException("No Rule annotation was found on " + ruleClass);
    }
    String ruleKey = ruleAnnotation.key();
    if (StringUtils.isEmpty(ruleKey)) {
        throw new IllegalArgumentException("No key is defined in Rule annotation of " + ruleClass);
    }
    NewRule rule = repository.rule(ruleKey);
    if (rule == null) {
        throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key());
    }
    ruleMetadata(ruleClass, rule);

    rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null);
    if (ruleAnnotation.cardinality() == Cardinality.MULTIPLE) {
        throw new IllegalArgumentException("Cardinality is not supported, use the RuleTemplate annotation instead for " + ruleClass);
    }
}
 
Example #3
Source File: FlowRulesDefinition.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts the check to a rule by reading the params
 * @param check
 * @param repository
 */
@VisibleForTesting
protected void newRule(Class<? extends FlowCheck> check, NewRepository repository) {
  // Read the rule annotation of the check
  org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(check,
      org.sonar.check.Rule.class);
  if (ruleAnnotation == null) {
    throw new IllegalArgumentException("No Rule annotation was found on " + check.getName());
  }
  // Read the ruleType annotation of the check
  FlowCheckRuleType ruleTypeAnnotation = AnnotationUtils.getAnnotation(check,
      FlowCheckRuleType.class);
  RuleType rt;
  if (ruleTypeAnnotation == null) {
    rt = RuleType.CODE_SMELL;
  }else {
    rt = ruleTypeAnnotation.ruletype();
  }
  // Add to repo
  String ruleKey = ruleAnnotation.key();
  if (StringUtils.isEmpty(ruleKey)) {
    throw new IllegalArgumentException("No key is defined in Rule annotation of " + check.getName());
  }
  NewRule rule = repository.rule(ruleKey);
  if (rule == null) {
    throw new IllegalStateException(
        "No rule was created for " + check + " in " + repository.key());
  }
  ruleKeys.add(rule.key());
  // Set html template
  addHtmlDescription(rule, ruleKey);
  rule.setTemplate(AnnotationUtils.getAnnotation(check, RuleTemplate.class) != null);
  // Set the type of the rule, instead of working with tags
  rule.setType(rt);
}