templates.java.ingredient.liquid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of recipe-generator Show documentation
Show all versions of recipe-generator Show documentation
Generates ingredients and implementation hooks for the Recipe framework
{%- if ingredient.keyed -%}
{%- assign superclass = 'KeyedIngredient' -%}
{%- else -%}
{%- assign superclass = 'Ingredient' -%}
{%- endif -%}
{%- if options.javaPackage != "" -%}
package {{options.javaPackage}};
{% endif %}
{%- assign ingredientName = ingredient.name | append:options.ingredientPostfix -%}
import ca.derekcormier.recipe.{{superclass}};
import java.util.HashMap;
import java.util.Map;
public class {{ingredientName}} extends {{superclass}} {
{% for key in info.constantKeys -%}
public static String {{key}} = "{{info.constantValues[forloop.index0]}}";
{% endfor %}
{%- for initializer in ingredient.initializers %}
public {{ingredientName}}(
{%- for param in initializer.params -%}
{%- for required in ingredient.required -%}
{%- if param == required.name -%}
{%- assign type = required.type | javatype -%}
{%- assign typeWithSpace = type | append: ' ' -%}
{%- assign argument = typeWithSpace | append: param -%}
{%- endif -%}
{%- endfor -%}
{{- argument -}}
{%- unless forloop.last -%}, {% endunless -%}
{%- endfor -%}
) {
super("{{ingredient.name}}", "{{domain}}");
{%- for required in ingredient.required %}
{%- if initializer.params contains required.name %}
setRequired("{{required.name}}", {{required.name}});
{%- else %}
setRequired("{{required.name}}", {{required.default | javavalue:required.type}});
{%- endif -%}
{%- endfor %}
{% if ingredient.keyed and ingredient.defaultKey %}
setKey(getProperty("{{ingredient.defaultKey}}"));
{% endif %}
}{% endfor %}
{% if ingredient.initializers.size == 0 %}
public {{ingredientName}}() {
super("{{ingredient.name}}", "{{domain}}");
{%- for required in ingredient.required %}
setRequired("{{required.name}}", {{required.default | javavalue:required.type}});
{%- endfor %}
{% if ingredient.keyed and ingredient.defaultKey %}
setKey(getProperty("{{ingredient.defaultKey}}"));
{% endif %}
}{% endif %}
protected {{ingredientName}}({{ingredientName}} other) {
super(other);
}
{%- for optional in ingredient.optionals %}
public {{ingredientName}} with{{optional.name | capitalize}}(
{%- if optional.compound != true -%}
{%- if optional.type != 'flag' -%}
{{optional.type | javatype}} {{optional.name}}
{%- endif -%}
{%- else -%}
{%- for param in optional.params -%}
{%- assign type = param.type | javatype -%}
{%- assign typeWithSpace = type | append: ' ' -%}
{%- assign argument = typeWithSpace | append: param.name -%}
{{- argument -}}
{%- unless forloop.last -%}, {% endunless -%}
{%- endfor -%}
{%- endif -%}
) {
{{ingredientName}} copy = new {{ingredientName}}(this);
{%- if optional.compound != true -%}
{%- if optional.type != 'flag' %}
copy.setOptional("{{optional.name}}", {{optional.repeatable}}, {{optional.name}});
{%- else %}
copy.setOptional("{{optional.name}}", {{optional.repeatable}}, true);
{%- endif -%}
{%- else %}
copy.setCompoundOptional("{{optional.name}}", {{optional.repeatable}}
{%- for param in optional.params -%}
, "{{param.name}}", {{param.name}}
{%- endfor -%});
{%- endif %}
return copy;
}{% endfor %}
}