private void addRuleProperty(Rule rule, Field field) { org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class); if (propertyAnnotation != null) { String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName()); RuleParam param = rule.createParameter(fieldKey); param.setDescription(propertyAnnotation.description()); param.setDefaultValue(propertyAnnotation.defaultValue()); if (!StringUtils.isBlank(propertyAnnotation.type())) { try { param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name()); } catch (IllegalArgumentException e) { throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e); } } else { param.setType(guessType(field.getType()).name()); } } }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (Strings.isNullOrEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }