Java源码示例:org.sonar.squidbridge.annotations.RuleTemplate

示例1
@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);
    }
}
 
示例2
@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);
    }
}
 
示例3
/**
 * 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);
}