-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes generating a separate class for nested sequence/scalar type
* Adds changes to `Field` to store `AbstractDataType` information of the field value * Modified to `map_constraint_to_abstract_data_type` to consider nested sequence/scalar type and change `AsbtractDataType` and `tera_fields` accordingly * Modified template to call `util_macros` for reading or writing a field as sequence
- Loading branch information
Showing
5 changed files
with
215 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/bin/ion/commands/beta/generate/templates/java/util_macros.templ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{# following macro defines statements to read a class field as sequence #} | ||
{% macro read_as_sequence(field) %} | ||
new {{ field.value_type }}(); | ||
{# Reads `Sequence` field that is an `ArrayList` #} | ||
{% if field.abstract_data_type["Sequence"].sequence_type == "List" %} | ||
if(reader.getType() != IonType.LIST) { | ||
throw new IonException("Expected list, found " + reader.getType() + " while reading {{ field.name | camel }}."); | ||
} | ||
{% elif field.abstract_data_type["Sequence"].sequence_type == "SExp" %} | ||
if(reader.getType() != IonType.SEXP) { | ||
throw new IonException("Expected sexpression, found " + reader.getType() + " while reading {{ field.name | camel }}."); | ||
} | ||
{% endif %} | ||
reader.stepIn(); | ||
{# Iterate through the `ArrayList` and read each element in it based on the data type provided in `field.abstract_data_type[Sequence]` #} | ||
while (reader.hasNext()) { | ||
reader.next(); | ||
{% if field.abstract_data_type["Sequence"].element_type | is_built_in_type == false %} | ||
{{ field.name | camel }}.add({{ field.abstract_data_type["Sequence"].element_type }}.readFrom(reader)); | ||
{% else %} | ||
{% if field.abstract_data_type["Sequence"].element_type == "bytes[]" %} | ||
{{ field.name | camel }}.add(reader.newBytes()); | ||
{% else %} | ||
{{ field.name | camel }}.add(reader.{{ field.abstract_data_type["Sequence"].element_type | camel }}Value()); | ||
{% endif %} | ||
{% endif %} | ||
} | ||
reader.stepOut(); | ||
{% endmacro %} | ||
{# following macro defines statements to write a class field as sequence #} | ||
{% macro write_as_sequence(field) %} | ||
{# Writes `Sequence` field that is an `ArrayList` as an Ion sequence #} | ||
{% if field.abstract_data_type["Sequence"].sequence_type == "List" %} | ||
writer.stepIn(IonType.LIST); | ||
{% else %} | ||
writer.stepIn(IonType.SEXP); | ||
{% endif %} | ||
for ({{ field.abstract_data_type["Sequence"].element_type }} value: this.{{ field.name |camel }}) { | ||
{% if field.abstract_data_type["Sequence"].element_type | is_built_in_type == false %} | ||
value.writeTo(writer); | ||
{% else %} | ||
writer.write{{ field.abstract_data_type["Sequence"].element_type | upper_camel }}(value); | ||
{% endif %} | ||
} | ||
writer.stepOut(); | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters