Search in sources :

Example 1 with Parameter

use of com.buschmais.jqassistant.core.rule.api.model.Parameter in project jqa-core-framework by buschmais.

the class AnalyzerRuleVisitor method getRuleParameters.

private Map<String, Object> getRuleParameters(ExecutableRule executableRule) throws RuleException {
    Map<String, Object> ruleParameters = new HashMap<>();
    Map<String, Parameter> parameters = executableRule.getParameters();
    for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
        String parameterName = entry.getKey();
        Parameter parameter = entry.getValue();
        Object parameterValue;
        String parameterValueAsString = this.ruleParameters.get(parameterName);
        if (parameterValueAsString != null) {
            try {
                parameterValue = parameter.getType().parse(parameterValueAsString);
            } catch (RuleException e) {
                throw new RuleException("Cannot determine value for parameter " + parameterName + "' of rule '" + executableRule + "'.");
            }
        } else {
            parameterValue = parameter.getDefaultValue();
        }
        if (parameterValue == null) {
            throw new RuleException("No value or default value defined for required parameter '" + parameterName + "' of rule '" + executableRule + "'.");
        }
        ruleParameters.put(parameterName, parameterValue);
    }
    return ruleParameters;
}
Also used : HashMap(java.util.HashMap) Parameter(com.buschmais.jqassistant.core.rule.api.model.Parameter) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Parameter (com.buschmais.jqassistant.core.rule.api.model.Parameter)1 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1