org.sonar.check.RuleProperty Java Examples

The following examples show how to use org.sonar.check.RuleProperty. 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: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private void loadParameters(RulesDefinition.NewRule rule, Field field) {
    RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class);
    if (propertyAnnotation != null) {
        String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
        RulesDefinition.NewParam param = rule.createParam(fieldKey)
            .setDescription(propertyAnnotation.description())
            .setDefaultValue(propertyAnnotation.defaultValue());

        if (!StringUtils.isBlank(propertyAnnotation.type())) {
            try {
                param.setType(RuleParamType.parse(propertyAnnotation.type().trim()));
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Invalid property type [" + propertyAnnotation.type() + "]", e);
            }
        } else {
            param.setType(guessType(field.getType()));
        }
    }
}