public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) { for (Class annotatedClass : annotatedClasses) { loadRule(repo, annotatedClass); } }
@CheckForNull RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(clazz, org.sonar.check.Rule.class); if (ruleAnnotation != null) { return loadRule(repo, clazz, ruleAnnotation); } else { LOG.warn("The class " + clazz.getCanonicalName() + " should be annotated with " + org.sonar.check.Rule.class); return null; } }
@Test public void override_annotation_programmatically() { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); NewRule newRule = annotationLoader.loadRule(newRepository, RuleWithProperty.class); newRule.setName("Overridden name"); newRule.param("property").setDefaultValue("true"); newRule.param("property").setDescription("Overridden"); newRepository.done(); RulesDefinition.Repository repository = context.repository("squid"); assertThat(repository.rules()).hasSize(1); RulesDefinition.Rule rule = repository.rules().get(0); assertThat(rule.key()).isEqualTo("foo"); assertThat(rule.status()).isEqualTo(RuleStatus.BETA); assertThat(rule.name()).isEqualTo("Overridden name"); assertThat(rule.htmlDescription()).isEqualTo("Foo Bar"); assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); assertThat(rule.params()).hasSize(1); RulesDefinition.Param prop = rule.param("property"); assertThat(prop.key()).isEqualTo("property"); assertThat(prop.description()).isEqualTo("Overridden"); assertThat(prop.defaultValue()).isEqualTo("true"); assertThat(prop.type()).isEqualTo(RuleParamType.STRING); }
public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) { for (Class annotatedClass : annotatedClasses) { loadRule(repo, annotatedClass); } }
public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) { for (Class annotatedClass : annotatedClasses) { loadRule(repo, annotatedClass); } }
@CheckForNull RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(clazz, org.sonar.check.Rule.class); if (ruleAnnotation != null) { return loadRule(repo, clazz, ruleAnnotation); } else { LOG.warn("The class " + clazz.getCanonicalName() + " should be annotated with " + org.sonar.check.Rule.class); return null; } }
@CheckForNull RulesDefinition.NewRule loadRule(RulesDefinition.NewExtendedRepository repo, Class clazz) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(clazz, org.sonar.check.Rule.class); if (ruleAnnotation != null) { return loadRule(repo, clazz, ruleAnnotation); } else { LOG.warn("The class " + clazz.getCanonicalName() + " should be annotated with " + org.sonar.check.Rule.class); return null; } }