From f415ad92f1b7ddfe669aa631446ee3c7d7c69810 Mon Sep 17 00:00:00 2001 From: Gavriil Sitnikov Date: Fri, 4 Aug 2017 19:20:44 +0300 Subject: [PATCH] Some small bugs of generation fixed --- Java/Class.java.twig | 10 ++++------ Java/utils.twig | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Java/Class.java.twig b/Java/Class.java.twig index 8fc24f4..63a5590 100644 --- a/Java/Class.java.twig +++ b/Java/Class.java.twig @@ -9,11 +9,11 @@ import android.support.annotation.Nullable; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; -import {{ packageName }}.*; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -49,9 +49,7 @@ public class {% include 'blocks/class/classtype.twig' with { type: type } %} ext super.validate(); {%- include 'blocks/class/fields-validate.twig' with { fields: fields } %} } -{% if parent is not null %} - @Override -{%- endif %} + protected void copyTo(@NonNull final {% include 'blocks/class/classtype.twig' with { type: type } %} destination) { {%- if parent is not null %} super.copyTo(destination); @@ -83,12 +81,12 @@ public class {% include 'blocks/class/classtype.twig' with { type: type } %} ext {%- include 'blocks/class/fields-equals.twig' with { fields: fields } -%}; } - private void writeObject(@NonNull final ObjectOutputStream outputStream) { + private void writeObject(@NonNull final ObjectOutputStream outputStream) throws IOException { {%- include 'blocks/class/fields-write-object.twig' with { fields: fields } %} } @SuppressWarnings("unchecked") - private void readObject(@NonNull final ObjectInputStream inputStream) { + private void readObject(@NonNull final ObjectInputStream inputStream) throws IOException, ClassNotFoundException { {%- include 'blocks/class/fields-read-object.twig' with { fields: fields } %} } diff --git a/Java/utils.twig b/Java/utils.twig index 784b826..eee9f81 100644 --- a/Java/utils.twig +++ b/Java/utils.twig @@ -43,7 +43,7 @@ LoganSquareJsonModel {%- elseif valueType.baseTypeName == "Decimal" -%} BigDecimal {%- elseif valueType.baseTypeName == "Bool" -%} -{%- if tryUsePrimitive -%}bool{%- else -%}Boolean{%- endif -%} +{%- if tryUsePrimitive -%}boolean{%- else -%}Boolean{%- endif -%} {%- elseif valueType.baseTypeName == "Map" -%} Map<{{ self.formatNonOptionalValueType(valueType.keysType, false) }}, {{ self.formatNonOptionalValueType(valueType.valuesType, false) }}> {%- elseif valueType.baseTypeName == "Array" -%} @@ -90,7 +90,7 @@ new HashMap<>({{ fieldName }}) {%- if optional -%} {{ object }}.{{ fieldName }} = new JsonOptional({{- self.formatNullableValueSetter(fieldName, valueType, nullable) -}}); {%- elseif nullable -%} -{{ object }}.{{ fieldName }} = self.formatNullableValueSetter(fieldName, valueType, nullable) -}}; +{{ object }}.{{ fieldName }} = self.formatNullableValueSetter(fieldName, valueType, nullable); {%- else -%} {{ object }}.{{ fieldName }} = {{ fieldName }}; {%- endif -%} @@ -119,7 +119,7 @@ Collections.unmodifiableMap({{ fieldName }}) {%- if optional -%} return new JsonOptional({{- self.formatNullableValueGetter(fieldName, valueType, nullable) -}}); {%- elseif nullable -%} -return self.formatNullableValueGetter(fieldName, valueType, nullable) -}}; +return self.formatNullableValueGetter(fieldName, valueType, nullable); {%- else -%} return this.{{ fieldName }}; {%- endif -%} @@ -183,20 +183,20 @@ writeObject({{ fieldName }}) {% macro formatReadObject(valueType, nullable, optional) %} {% import _self as self %} {%- if nullable or optional -%} -({{ self.formatValueType(valueType, nullable, optional) }}) readObject() +({{ self.formatValueType(valueType, nullable, optional) }}) inputStream.readObject() {%- else -%} {%- if valueType.baseTypeName == "Int" -%} -readInt() +inputStream.readInt() {%- elseif valueType.baseTypeName == "Long" -%} -readLong() +inputStream.readLong() {%- elseif valueType.baseTypeName == "Double" -%} -readDouble() +inputStream.readDouble() {%- elseif valueType.baseTypeName == "String" -%} -readUTF() +inputStream.readUTF() {%- elseif valueType.baseTypeName == "Bool" -%} -readBoolean() +inputStream.readBoolean() {%- else -%} -({{ self.formatValueType(valueType, nullable, optional) }}) readObject() +({{ self.formatValueType(valueType, nullable, optional) }}) inputStream.readObject() {%- endif -%} {%- endif -%} {% endmacro %}