| Index: mojo/public/tools/bindings/generators/java_templates/data_types_definition.tmpl
|
| diff --git a/mojo/public/tools/bindings/generators/java_templates/data_types_definition.tmpl b/mojo/public/tools/bindings/generators/java_templates/data_types_definition.tmpl
|
| index aa3f6f6d9d27ea637fea86d78e4af7141ca0ab66..4c0823cce6b3cefba10310e9750a3b9c75c04915 100644
|
| --- a/mojo/public/tools/bindings/generators/java_templates/data_types_definition.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/java_templates/data_types_definition.tmpl
|
| @@ -1,19 +1,19 @@
|
| -{% from "constant_definition.tmpl" import constant_def %}
|
| -{% from "enum_definition.tmpl" import enum_def %}
|
| +{%- from "constant_definition.tmpl" import constant_def %}
|
| +{%- from "enum_definition.tmpl" import enum_def %}
|
|
|
| {%- macro equality(kind, v1, v2, ne=False) -%}
|
| {%- if kind|is_reference_kind -%}
|
| {%- if kind|is_array_kind -%}
|
| {%- if kind.kind|is_reference_kind -%}
|
| -{% if ne %}!{% endif %}java.util.Arrays.deepEquals({{v1}}, {{v2}})
|
| +{%- if ne %}!{%- endif %}java.util.Arrays.deepEquals({{v1}}, {{v2}})
|
| {%- else -%}
|
| -{% if ne %}!{% endif %}java.util.Arrays.equals({{v1}}, {{v2}})
|
| +{%- if ne %}!{%- endif %}java.util.Arrays.equals({{v1}}, {{v2}})
|
| {%- endif -%}
|
| {%- else -%}
|
| -{% if ne %}!{% endif %}org.chromium.mojo.bindings.BindingsHelper.equals({{v1}}, {{v2}})
|
| +{%- if ne %}!{%- endif %}org.chromium.mojo.bindings.BindingsHelper.equals({{v1}}, {{v2}})
|
| {%- endif -%}
|
| {%- else -%}
|
| -{{v1}} {% if ne %}!={% else %}=={% endif %} {{v2}}
|
| +{{v1}} {%- if ne %}!={%- else %}=={%- endif %} {{v2}}
|
| {%- endif -%}
|
| {%- endmacro -%}
|
|
|
| @@ -37,27 +37,27 @@ org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE
|
| {%- endif -%}
|
| {%- endmacro -%}
|
|
|
| -{% macro encode(variable, kind, offset, bit, level=0, check_for_null=True) %}
|
| -{% if kind|is_pointer_array_kind or kind|is_union_array_kind %}
|
| -{% set sub_kind = kind.kind %}
|
| -{% if check_for_null %}
|
| +{%- macro encode(variable, kind, offset, bit, level=0, check_for_null=True) %}
|
| +{%- if kind|is_pointer_array_kind or kind|is_union_array_kind %}
|
| +{%- set sub_kind = kind.kind %}
|
| +{%- if check_for_null %}
|
| if ({{variable}} == null) {
|
| encoder{{level}}.encodeNullPointer({{offset}}, {{kind|is_nullable_kind|java_true_false}});
|
| } else {
|
| -{% else %}
|
| +{%- else %}
|
| {
|
| -{% endif %}
|
| -{% if kind|is_pointer_array_kind %}
|
| -{% set encodePointer = 'encodePointerArray' %}
|
| -{% else %}
|
| -{% set encodePointer = 'encodeUnionArray' %}
|
| -{% endif %}
|
| +{%- endif %}
|
| +{%- if kind|is_pointer_array_kind %}
|
| +{%- set encodePointer = 'encodePointerArray' %}
|
| +{%- else %}
|
| +{%- set encodePointer = 'encodeUnionArray' %}
|
| +{%- endif %}
|
| org.chromium.mojo.bindings.Encoder encoder{{level + 1}} = encoder{{level}}.{{encodePointer}}({{variable}}.length, {{offset}}, {{kind|array_expected_length}});
|
| for (int i{{level}} = 0; i{{level}} < {{variable}}.length; ++i{{level}}) {
|
| {{encode(variable~'[i'~level~']', sub_kind, 'org.chromium.mojo.bindings.DataHeader.HEADER_SIZE + ' ~ array_element_size(sub_kind) ~ ' * i'~level, 0, level+1)|indent(8)}}
|
| }
|
| }
|
| -{% elif kind|is_map_kind %}
|
| +{%- elif kind|is_map_kind %}
|
| if ({{variable}} == null) {
|
| encoder{{level}}.encodeNullPointer({{offset}}, {{kind|is_nullable_kind|java_true_false}});
|
| } else {
|
| @@ -74,28 +74,28 @@ if ({{variable}} == null) {
|
| {{encode('keys'~level, kind.key_kind|array, 'org.chromium.mojo.bindings.DataHeader.HEADER_SIZE', 0, level+1, False)|indent(4)}}
|
| {{encode('values'~level, kind.value_kind|array, 'org.chromium.mojo.bindings.DataHeader.HEADER_SIZE + org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE', 0, level+1, False)|indent(4)}}
|
| }
|
| -{% else %}
|
| +{%- else %}
|
| encoder{{level}}.{{kind|encode_method(variable, offset, bit)}};
|
| -{% endif %}
|
| -{% endmacro %}
|
| +{%- endif %}
|
| +{%- endmacro %}
|
|
|
| -{% macro decode(variable, kind, offset, bit, level=0) %}
|
| -{% if kind|is_struct_kind or
|
| +{%- macro decode(variable, kind, offset, bit, level=0) %}
|
| +{%- if kind|is_struct_kind or
|
| kind|is_pointer_array_kind or
|
| kind|is_union_array_kind or
|
| kind|is_map_kind %}
|
| org.chromium.mojo.bindings.Decoder decoder{{level+1}} = decoder{{level}}.readPointer({{offset}}, {{kind|is_nullable_kind|java_true_false}});
|
| -{% if kind|is_struct_kind %}
|
| +{%- if kind|is_struct_kind %}
|
| {{variable}} = {{kind|java_type}}.decode(decoder{{level+1}});
|
| -{% else %}{# kind|is_pointer_array_kind or is_map_kind #}
|
| -{% if kind|is_nullable_kind %}
|
| +{%- else %}{# kind|is_pointer_array_kind or is_map_kind #}
|
| +{%- if kind|is_nullable_kind %}
|
| if (decoder{{level+1}} == null) {
|
| {{variable}} = null;
|
| } else {
|
| -{% else %}
|
| +{%- else %}
|
| {
|
| -{% endif %}
|
| -{% if kind|is_map_kind %}
|
| +{%- endif %}
|
| +{%- if kind|is_map_kind %}
|
| decoder{{level+1}}.readDataHeaderForMap();
|
| {{kind.key_kind|java_type}}[] keys{{level}};
|
| {{kind.value_kind|java_type}}[] values{{level}};
|
| @@ -109,69 +109,69 @@ if (decoder{{level+1}} == null) {
|
| for (int index{{level}} = 0; index{{level}} < keys{{level}}.length; ++index{{level}}) {
|
| {{variable}}.put(keys{{level}}[index{{level}}], values{{level}}[index{{level}}]);
|
| }
|
| -{% else %}
|
| +{%- else %}
|
| org.chromium.mojo.bindings.DataHeader si{{level+1}} = decoder{{level+1}}.readDataHeaderForPointerArray({{kind|array_expected_length}});
|
| {{variable}} = {{kind|new_array('si'~(level+1)~'.elementsOrVersion')}};
|
| for (int i{{level+1}} = 0; i{{level+1}} < si{{level+1}}.elementsOrVersion; ++i{{level+1}}) {
|
| {{decode(variable~'[i'~(level+1)~']', kind.kind, 'org.chromium.mojo.bindings.DataHeader.HEADER_SIZE + ' ~ array_element_size(kind.kind) ~' * i'~(level+1), 0, level+1)|indent(8)}}
|
| }
|
| -{% endif %}
|
| +{%- endif %}
|
| }
|
| -{% endif %}
|
| -{% elif kind|is_union_kind %}
|
| +{%- endif %}
|
| +{%- elif kind|is_union_kind %}
|
| {{variable}} = {{kind|java_type}}.decode(decoder{{level}}, {{offset}});
|
| -{% else %}
|
| +{%- else %}
|
| {{variable}} = decoder{{level}}.{{kind|decode_method(offset, bit)}};
|
| -{% if kind|is_array_kind and kind.kind|is_enum_kind %}
|
| -{% if kind|is_nullable_kind %}
|
| +{%- if kind|is_array_kind and kind.kind|is_enum_kind %}
|
| +{%- if kind|is_nullable_kind %}
|
| if ({{variable}} != null) {
|
| -{% else %}
|
| +{%- else %}
|
| {
|
| -{% endif %}
|
| +{%- endif %}
|
| for (int i{{level}} = 0; i{{level}} < {{variable}}.length; ++i{{level}}) {
|
| {{kind.kind|java_class_for_enum}}.validate({{variable}}[i{{level}}]);
|
| }
|
| }
|
| -{% elif kind|is_enum_kind %}
|
| +{%- elif kind|is_enum_kind %}
|
| {{kind|java_class_for_enum}}.validate({{variable}});
|
| -{% endif %}
|
| -{% endif %}
|
| -{% endmacro %}
|
| +{%- endif %}
|
| +{%- endif %}
|
| +{%- endmacro %}
|
|
|
| -{% macro struct_def(struct, inner_class=False) %}
|
| +{%- macro struct_def(struct, inner_class=False) %}
|
| {{'static' if inner_class else 'public'}} final class {{struct|name}} extends org.chromium.mojo.bindings.Struct {
|
|
|
| private static final int STRUCT_SIZE = {{struct.versions[-1].num_bytes}};
|
| private static final org.chromium.mojo.bindings.DataHeader[] VERSION_ARRAY = new org.chromium.mojo.bindings.DataHeader[] {
|
| {%- for version in struct.versions -%}
|
| - new org.chromium.mojo.bindings.DataHeader({{version.num_bytes}}, {{version.version}}){% if not loop.last %}, {% endif -%}
|
| + new org.chromium.mojo.bindings.DataHeader({{version.num_bytes}}, {{version.version}}){%- if not loop.last %}, {%- endif -%}
|
| {%- endfor -%}
|
| };
|
| private static final org.chromium.mojo.bindings.DataHeader DEFAULT_STRUCT_INFO = VERSION_ARRAY[{{struct.versions|length - 1}}];
|
| -{% for constant in struct.constants %}
|
| +{%- for constant in struct.constants %}
|
|
|
| {{constant_def(constant)|indent(4)}}
|
| -{% endfor %}
|
| -{% for enum in struct.enums %}
|
| +{%- endfor %}
|
| +{%- for enum in struct.enums %}
|
|
|
| {{enum_def(enum, false)|indent(4)}}
|
| -{% endfor %}
|
| -{% if struct.fields %}
|
| +{%- endfor %}
|
| +{%- if struct.fields %}
|
|
|
| -{% for field in struct.fields %}
|
| +{%- for field in struct.fields %}
|
| public {{field.kind|java_type}} {{field|name}};
|
| -{% endfor %}
|
| -{% endif %}
|
| +{%- endfor %}
|
| +{%- endif %}
|
|
|
| private {{struct|name}}(int version) {
|
| super(STRUCT_SIZE, version);
|
| -{% for field in struct.fields %}
|
| -{% if field.default %}
|
| +{%- for field in struct.fields %}
|
| +{%- if field.default %}
|
| {{field|name}} = {{field|default_value}};
|
| -{% elif field.kind|is_any_handle_kind %}
|
| +{%- elif field.kind|is_any_handle_kind %}
|
| {{field|name}} = org.chromium.mojo.system.InvalidHandle.INSTANCE;
|
| -{% endif %}
|
| -{% endfor %}
|
| +{%- endif %}
|
| +{%- endfor %}
|
| }
|
|
|
| public {{struct|name}}() {
|
| @@ -200,31 +200,37 @@ if ({{variable}} != null) {
|
| if (decoder0 == null) {
|
| return null;
|
| }
|
| - org.chromium.mojo.bindings.DataHeader mainDataHeader = decoder0.readAndValidateDataHeader(VERSION_ARRAY);
|
| - {{struct|name}} result = new {{struct|name}}(mainDataHeader.elementsOrVersion);
|
| -{% for byte in struct.bytes %}
|
| -{% for packed_field in byte.packed_fields %}
|
| - if (mainDataHeader.elementsOrVersion >= {{packed_field.min_version}}) {
|
| - {{decode('result.' ~ packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(12)}}
|
| + decoder0.increaseStackDepth();
|
| + {{struct|name}} result;
|
| + try {
|
| + org.chromium.mojo.bindings.DataHeader mainDataHeader = decoder0.readAndValidateDataHeader(VERSION_ARRAY);
|
| + result = new {{struct|name}}(mainDataHeader.elementsOrVersion);
|
| +{%- for byte in struct.bytes %}
|
| +{%- for packed_field in byte.packed_fields %}
|
| + if (mainDataHeader.elementsOrVersion >= {{packed_field.min_version}}) {
|
| + {{decode('result.' ~ packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(16)}}
|
| + }
|
| +{%- endfor %}
|
| +{%- endfor %}
|
| + } finally {
|
| + decoder0.decreaseStackDepth();
|
| }
|
| -{% endfor %}
|
| -{% endfor %}
|
| return result;
|
| }
|
|
|
| @SuppressWarnings("unchecked")
|
| @Override
|
| protected final void encode(org.chromium.mojo.bindings.Encoder encoder) {
|
| -{% if not struct.bytes %}
|
| +{%- if not struct.bytes %}
|
| encoder.getEncoderAtDataOffset(DEFAULT_STRUCT_INFO);
|
| -{% else %}
|
| +{%- else %}
|
| org.chromium.mojo.bindings.Encoder encoder0 = encoder.getEncoderAtDataOffset(DEFAULT_STRUCT_INFO);
|
| -{% endif %}
|
| -{% for byte in struct.bytes %}
|
| -{% for packed_field in byte.packed_fields %}
|
| +{%- endif %}
|
| +{%- for byte in struct.bytes %}
|
| +{%- for packed_field in byte.packed_fields %}
|
| {{encode(packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(8)}}
|
| -{% endfor %}
|
| -{% endfor %}
|
| +{%- endfor %}
|
| +{%- endfor %}
|
| }
|
|
|
| /**
|
| @@ -238,13 +244,13 @@ if ({{variable}} != null) {
|
| return false;
|
| if (getClass() != object.getClass())
|
| return false;
|
| -{% if struct.fields|length %}
|
| +{%- if struct.fields|length %}
|
| {{struct|name}} other = ({{struct|name}}) object;
|
| -{% for field in struct.fields %}
|
| +{%- for field in struct.fields %}
|
| if ({{equality(field.kind, 'this.'~field|name, 'other.'~field|name, True)}})
|
| return false;
|
| -{% endfor %}
|
| -{% endif %}
|
| +{%- endfor %}
|
| +{%- endif %}
|
| return true;
|
| }
|
|
|
| @@ -255,28 +261,28 @@ if ({{variable}} != null) {
|
| public int hashCode() {
|
| final int prime = 31;
|
| int result = prime + getClass().hashCode();
|
| -{% for field in struct.fields %}
|
| +{%- for field in struct.fields %}
|
| result = prime * result + {{hash(field.kind, field|name)}};
|
| -{% endfor %}
|
| +{%- endfor %}
|
| return result;
|
| }
|
| }
|
| -{% endmacro %}
|
| +{%- endmacro %}
|
|
|
|
|
| -{% macro union_def(union) %}
|
| +{%- macro union_def(union) %}
|
| public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
|
|
| public static final class Tag {
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| public static final int {{field|ucc}} = {{loop.index0}};
|
| -{% endfor %}
|
| +{%- endfor %}
|
| };
|
|
|
| private int mTag_ = -1;
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| private {{field.kind|java_type}} m{{field|ucc}};
|
| -{% endfor %}
|
| +{%- endfor %}
|
|
|
| public int which() {
|
| return mTag_;
|
| @@ -285,7 +291,7 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| public boolean isUnknown() {
|
| return mTag_ == -1;
|
| }
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
|
|
| // TODO(rockot): Fix the findbugs error and remove this suppression.
|
| // See http://crbug.com/570386.
|
| @@ -302,7 +308,7 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| assert mTag_ == Tag.{{field|ucc}};
|
| return m{{field|ucc}};
|
| }
|
| -{% endfor %}
|
| +{%- endfor %}
|
|
|
|
|
| @Override
|
| @@ -310,20 +316,20 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| encoder0.encode(org.chromium.mojo.bindings.BindingsHelper.UNION_SIZE, offset);
|
| encoder0.encode(mTag_, offset + 4);
|
| switch (mTag_) {
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| case Tag.{{field|ucc}}: {
|
| -{% if field.kind|is_union_kind %}
|
| +{%- if field.kind|is_union_kind %}
|
| if (m{{field|ucc}} == null) {
|
| encoder0.encodeNullPointer(offset + 8, {{field.kind|is_nullable_kind|java_true_false}});
|
| } else {
|
| m{{field|ucc}}.encode(encoder0.encoderForUnionPointer(offset + 8), 0);
|
| }
|
| -{% else %}
|
| +{%- else %}
|
| {{encode('m' ~ field|ucc, field.kind, 'offset + 8', 0)|indent(16)}}
|
| -{% endif %}
|
| +{%- endif %}
|
| break;
|
| }
|
| -{% endfor %}
|
| +{%- endfor %}
|
| default: {
|
| break;
|
| }
|
| @@ -341,20 +347,20 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| }
|
| {{union|name}} result = new {{union|name}}();
|
| switch (dataHeader.elementsOrVersion) {
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| case Tag.{{field|ucc}}: {
|
| -{% if field.kind|is_union_kind %}
|
| +{%- if field.kind|is_union_kind %}
|
| org.chromium.mojo.bindings.Decoder decoder1 = decoder0.readPointer(offset + org.chromium.mojo.bindings.DataHeader.HEADER_SIZE, {{field.kind|is_nullable_kind|java_true_false}});
|
| if (decoder1 != null) {
|
| result.m{{field|ucc}} = {{field.kind|name}}.decode(decoder1, 0);
|
| }
|
| -{% else %}
|
| +{%- else %}
|
| {{decode('result.m'~field|ucc, field.kind, 'offset + org.chromium.mojo.bindings.DataHeader.HEADER_SIZE', 0)|indent(16)}}
|
| -{% endif %}
|
| +{%- endif %}
|
| result.mTag_ = Tag.{{field|ucc}};
|
| break;
|
| }
|
| -{% endfor %}
|
| +{%- endfor %}
|
| default: {
|
| break;
|
| }
|
| @@ -377,10 +383,10 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| if (mTag_ != other.mTag_)
|
| return false;
|
| switch (mTag_) {
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| case Tag.{{field|ucc}}:
|
| return {{equality(field.kind, 'm'~field|ucc, 'other.m'~field|ucc)}};
|
| -{% endfor %}
|
| +{%- endfor %}
|
| default:
|
| break;
|
| }
|
| @@ -396,12 +402,12 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| int result = prime + getClass().hashCode();
|
| result = prime * result + org.chromium.mojo.bindings.BindingsHelper.hashCode(mTag_);
|
| switch (mTag_) {
|
| -{% for field in union.fields %}
|
| +{%- for field in union.fields %}
|
| case Tag.{{field|ucc}}: {
|
| result = prime * result + {{hash(field.kind, 'm'~field|ucc)}};
|
| break;
|
| }
|
| -{% endfor %}
|
| +{%- endfor %}
|
| default: {
|
| break;
|
| }
|
| @@ -409,4 +415,4 @@ public final class {{union|name}} extends org.chromium.mojo.bindings.Union {
|
| return result;
|
| }
|
| }
|
| -{% endmacro %}
|
| +{%- endmacro %}
|
|
|