From e94caa429ecb456ab64d9823cfb38331e295aea5 Mon Sep 17 00:00:00 2001 From: Gavriil Sitnikov Date: Thu, 22 Jun 2017 20:17:58 +0300 Subject: [PATCH] Fields generation added --- Java/Class.java.twig | 10 ++++------ Java/blocks/class/fields-initialization.twig | 11 +++++++++++ Java/blocks/class/fields-super-initialization.twig | 5 +++++ Java/blocks/class/fields.twig | 12 ++++++++++++ Java/utils.twig | 2 +- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 Java/blocks/class/fields-initialization.twig create mode 100644 Java/blocks/class/fields-super-initialization.twig create mode 100644 Java/blocks/class/fields.twig diff --git a/Java/Class.java.twig b/Java/Class.java.twig index 84296dd..fd29182 100644 --- a/Java/Class.java.twig +++ b/Java/Class.java.twig @@ -13,16 +13,14 @@ import ru.touchin.templates.logansquare.LoganSquareJsonModel; */ @JsonObject(serializeNullObjects = true) public class {% include 'blocks/class/classtype.twig' with { type: type } %} extends {% include 'blocks/class/supertype.twig' with { type: type, parent: parent } %} { - +{% include 'blocks/class/fields.twig' with { fields: fields } %} public {{ type.baseTypeName }}() { super(); } - -{% if (fields is not empty) %} +{% if (allFieldsOrdered is not empty) %} public {{ type.baseTypeName }}({%- include 'blocks/class/init-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) { - super(); + super({%- include 'blocks/class/fields-super-initialization.twig' with { fields: superclassesFields } -%}); + {%- include 'blocks/class/fields-initialization.twig' with { fields: fields } %} } {% endif %} - - } \ No newline at end of file diff --git a/Java/blocks/class/fields-initialization.twig b/Java/blocks/class/fields-initialization.twig new file mode 100644 index 0000000..3e81e18 --- /dev/null +++ b/Java/blocks/class/fields-initialization.twig @@ -0,0 +1,11 @@ +{%- import '../../utils.twig' as utils -%} +{%- for field in fields %} +{%- if field.type.type.baseTypeName == "List" %} + this.{{ field.name }} = new ArrayList<>({{ field.name }}); +{%- elseif field.type.type.baseTypeName == "Map" %} + this.{{ field.name }} = new HashMap<>({{ field.name }}); +{%- else %} +//TODO NULLABLE COLLECTIONS + this.{{ field.name }} = {{ field.name }}; +{%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/Java/blocks/class/fields-super-initialization.twig b/Java/blocks/class/fields-super-initialization.twig new file mode 100644 index 0000000..be68fb8 --- /dev/null +++ b/Java/blocks/class/fields-super-initialization.twig @@ -0,0 +1,5 @@ +{%- if fields is not empty -%} +{%- for field in fields -%} + {{ field.name }} {%- if not (loop.last) %}, {% endif %} +{%- endfor -%} +{%- endif -%} \ No newline at end of file diff --git a/Java/blocks/class/fields.twig b/Java/blocks/class/fields.twig new file mode 100644 index 0000000..703ea1f --- /dev/null +++ b/Java/blocks/class/fields.twig @@ -0,0 +1,12 @@ +{%- import '../../utils.twig' as utils -%} + +{%- if fields is not empty -%} +{% for field in fields %} + /** + * {{ field.description }} + */ + @JsonField(name = "{{ field.jsonName }}") + {{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable, field.optional) }} + private {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {{ field.name }}; +{% endfor -%} +{% endif %} \ No newline at end of file diff --git a/Java/utils.twig b/Java/utils.twig index b843372..498b37a 100644 --- a/Java/utils.twig +++ b/Java/utils.twig @@ -23,7 +23,7 @@ LoganSquareJsonModel @NonNull {%- elseif nullable -%} @Nullable -{%- elseif not (baseTypeName == "Int" or baseTypeName == "Long" or baseTypeName == "Double" or baseTypeName == "Decimal" or baseTypeName == "Bool") -%} +{%- elseif not (baseTypeName == "Int" or baseTypeName == "Long" or baseTypeName == "Double" or baseTypeName == "Bool") -%} @NonNull {%- endif -%} {% endmacro %}