public static String getRuleKey(Class annotatedClass) { String key = null; org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); } return StringUtils.defaultIfEmpty(key, annotatedClass.getCanonicalName()); }
private String getRuleKey(Class annotatedClass) { String key = null; Rule ruleAnnotation = (Rule) annotatedClass.getAnnotation(Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); } else { Check checkAnnotation = (Check) annotatedClass.getAnnotation(Check.class); if (checkAnnotation != null) { key = checkAnnotation.key(); } } return StringUtils.defaultIfEmpty(key, annotatedClass.getCanonicalName()); }
private Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) { String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName()); String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null); String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null); Rule rule = Rule.create(repositoryKey, ruleKey, ruleName); rule.setDescription(description); rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority())); rule.setCardinality(ruleAnnotation.cardinality()); rule.setStatus(ruleAnnotation.status().name()); List<Field> fields = FieldUtils2.getFields(clazz, true); for (Field field : fields) { addRuleProperty(rule, field); } return rule; }