fluent.api.generator.templates.validation.check.jtwig Maven / Gradle / Ivy
{% set productType = var.type.parameters[0] %}
{% set packageName = (packageName == "") ? productType.packageName : packageName %}
{% set classSuffix = "Check" %}
{% set className = (className == "") ? concat(productType.simpleName, classSuffix) : className %}
{% set factoryMethod = (factoryMethod == "") ? concat(productType.simpleName, "With") : factoryMethod %}
{% set classParameters = empty(productType.parameterVariables) ? "" : concat("<", join(productType.parameterVariables, ", "), ">") %}
package {{ packageName }};
import javax.annotation.Generated;
import fluent.api.End;
import fluent.validation.Check;
import fluent.validation.AbstractCheckDsl;
import {{productType}};
import static fluent.validation.BasicChecks.equalTo;
@Generated("Generated code using {{ templatePath }}")
public final class {{ className }}{% if not empty(productType.parameterVariables) %}<{% for t in productType.parameterVariables %}{% if loop.first %}{% else %}, {% endif %}{{ t.declaration }}{% endfor %}>{% endif %}
extends AbstractCheckDsl<{{ className }}{{ classParameters }} , {{ productType.simpleName }}> {
protected {{ className }}(Check super {{ productType.simpleName }}> check) {
super(check, {{ className }}::new);
}
protected {{ className }}() {
super({{ className }}::new);
}
public static {% if not empty(productType.parameterVariables) %}<{% for t in productType.parameterVariables %}{% if loop.first %}{% else %}, {% endif %}{{ t.declaration }}{% endfor %}>{% endif %} {{ className }}{{ classParameters }} {{ factoryMethod }}() {
return new {{ className }}{% if not empty(productType.parameterVariables) %}<>{% endif %}();
}
{% for getter in productType.methods %}{% if getter.name.matches(getterPattern) and getter.name != "getClass" and getter.parameters.size == 0 %}
{% set propertyName = getter.toProperty(getterPattern, getterNameGroup) %}
public {{ className }}{{ classParameters }} {{ propertyName }}(Check super {{ getter.type.wrapper }}> value) {
return withField("{{ propertyName }}", {{ productType.simpleName }}::{{ getter }}).matching(value);
}
public {{ className }}{{ classParameters }} {{ propertyName }}({{ getter.type }} value) {
return {{ propertyName }}(equalTo(value));
}
{% endif %}{% endfor %}
public static final class Factory {
{% for getter in productType.methods %}{% if getter.name.matches(getterPattern) and getter.name != "getClass" and getter.parameters.size == 0 %}
{% set propertyName = getter.toProperty(getterPattern, getterNameGroup) %}
public static {{ className }}{{ classParameters }} {{ propertyName }}(Check super {{ getter.type.wrapper }}> value) {
return {{ factoryMethod }}().{{ propertyName }}(value);
}
public static {{ className }}{{ classParameters }} {{ propertyName }}({{ getter.type }} value) {
return {{ propertyName }}(equalTo(value));
}
{% endif %}{% endfor %}
}
}