Index: mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl |
deleted file mode 100644 |
index 0abdac421b5c6b55d4eb514bde178307dd9aea4a..0000000000000000000000000000000000000000 |
--- a/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl |
+++ /dev/null |
@@ -1,215 +0,0 @@ |
-{% from "constant_definition.tmpl" import constant_def %} |
-{% from "enum_definition.tmpl" import enum_def %} |
- |
-{%- macro inequality(kind, v1, v2) -%} |
-{%- if kind|is_reference_kind -%} |
-{%- if kind|is_array_kind -%} |
-{%- if kind.kind|is_reference_kind -%} |
-!java.util.Arrays.deepEquals({{v1}}, {{v2}}) |
-{%- else -%} |
-!java.util.Arrays.equals({{v1}}, {{v2}}) |
-{%- endif -%} |
-{%- else -%} |
-!org.chromium.mojo.bindings.BindingsHelper.equals({{v1}}, {{v2}}) |
-{%- endif -%} |
-{%- else -%} |
-{{v1}} != {{v2}} |
-{%- endif -%} |
-{%- endmacro -%} |
- |
-{%- macro hash(kind, v) -%} |
-{%- if kind|is_array_kind -%} |
-{%- if kind.kind|is_reference_kind -%} |
-java.util.Arrays.deepHashCode({{v}}) |
-{%- else -%} |
-java.util.Arrays.hashCode({{v}}) |
-{%- endif -%} |
-{%- else -%} |
-org.chromium.mojo.bindings.BindingsHelper.hashCode({{v}}) |
-{%- endif -%} |
-{%- endmacro -%} |
- |
-{% macro encode(variable, kind, offset, bit, level=0, check_for_null=True) %} |
-{% if kind|is_pointer_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 %} |
-{ |
-{% endif %} |
- org.chromium.mojo.bindings.Encoder encoder{{level + 1}} = encoder{{level}}.encodePointerArray({{variable}}.length, {{offset}}, {{kind|array_expected_length}}); |
- for (int i{{level}} = 0; i{{level}} < {{variable}}.length; ++i{{level}}) { |
- {{encode(variable~'[i'~level~']', sub_kind, 'DataHeader.HEADER_SIZE + org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE * i'~level, 0, level+1)|indent(8)}} |
- } |
-} |
-{% elif kind|is_map_kind %} |
-if ({{variable}} == null) { |
- encoder{{level}}.encodeNullPointer({{offset}}, {{kind|is_nullable_kind|java_true_false}}); |
-} else { |
- org.chromium.mojo.bindings.Encoder encoder{{level + 1}} = encoder{{level}}.encoderForMap({{offset}}); |
- int size{{level}} = {{variable}}.size(); |
- {{kind.key_kind|java_type}}[] keys{{level}} = {{kind.key_kind|array|new_array('size'~level)}}; |
- {{kind.value_kind|java_type}}[] values{{level}} = {{kind.value_kind|array|new_array('size'~level)}}; |
- int index{{level}} = 0; |
- for (java.util.Map.Entry<{{kind.key_kind|java_type(true)}}, {{kind.value_kind|java_type(true)}}> entry{{level}} : {{variable}}.entrySet()) { |
- keys{{level}}[index{{level}}] = entry{{level}}.getKey(); |
- values{{level}}[index{{level}}] = entry{{level}}.getValue(); |
- ++index{{level}}; |
- } |
- {{encode('keys'~level, kind.key_kind|array, 'DataHeader.HEADER_SIZE', 0, level+1, False)|indent(4)}} |
- {{encode('values'~level, kind.value_kind|array, 'DataHeader.HEADER_SIZE + org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE', 0, level+1, False)|indent(4)}} |
-} |
-{% else %} |
-encoder{{level}}.{{kind|encode_method(variable, offset, bit)}}; |
-{% endif %} |
-{% endmacro %} |
- |
-{% macro decode(variable, kind, offset, bit, level=0) %} |
-{% if kind|is_struct_kind or kind|is_pointer_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 %} |
-{{variable}} = {{kind|java_type}}.decode(decoder{{level+1}}); |
-{% else %}{# kind|is_pointer_array_kind or is_map_kind #} |
-{% if kind|is_nullable_kind %} |
-if (decoder{{level+1}} == null) { |
- {{variable}} = null; |
-} else { |
-{% else %} |
-{ |
-{% endif %} |
-{% if kind|is_map_kind %} |
- decoder{{level+1}}.readDataHeaderForMap(); |
- {{kind.key_kind|java_type}}[] keys{{level}}; |
- {{kind.value_kind|java_type}}[] values{{level}}; |
- { |
- {{decode('keys'~level, kind.key_kind|array, 'DataHeader.HEADER_SIZE', 0, level+1)|indent(8)}} |
- } |
- { |
- {{decode('values'~level, kind.value_kind|array('keys'~level~'.length'), 'DataHeader.HEADER_SIZE + org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE', 0, level+1)|indent(8)}} |
- } |
- {{variable}} = new java.util.HashMap<{{kind.key_kind|java_type(true)}}, {{kind.value_kind|java_type(true)}}>(); |
- for (int index{{level}} = 0; index{{level}} < keys{{level}}.length; ++index{{level}}) { |
- {{variable}}.put(keys{{level}}[index{{level}}], values{{level}}[index{{level}}]); |
- } |
-{% else %} |
- DataHeader si{{level+1}} = decoder{{level+1}}.readDataHeaderForPointerArray({{kind|array_expected_length}}); |
- {{variable}} = {{kind|new_array('si'~(level+1)~'.numFields')}}; |
- for (int i{{level+1}} = 0; i{{level+1}} < si{{level+1}}.numFields; ++i{{level+1}}) { |
- {{decode(variable~'[i'~(level+1)~']', kind.kind, 'DataHeader.HEADER_SIZE + org.chromium.mojo.bindings.BindingsHelper.POINTER_SIZE * i'~(level+1), 0, level+1)|indent(8)}} |
- } |
-{% endif %} |
-} |
-{% endif %} |
-{% else %} |
-{{variable}} = decoder{{level}}.{{kind|decode_method(offset, bit)}}; |
-{% endif %} |
-{% endmacro %} |
- |
-{% 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.packed|struct_size}}; |
- private static final DataHeader DEFAULT_STRUCT_INFO = new DataHeader(STRUCT_SIZE, {{struct.packed.packed_fields|length}}); |
-{% for constant in struct.constants %} |
- |
- {{constant_def(constant)|indent(4)}} |
-{% endfor %} |
-{% for enum in struct.enums %} |
- |
- {{enum_def(enum, false)|indent(4)}} |
-{% endfor %} |
-{% if struct.fields %} |
- |
-{% for field in struct.fields %} |
- public {{field.kind|java_type}} {{field|name}}; |
-{% endfor %} |
-{% endif %} |
- |
- public {{struct|name}}() { |
- super(STRUCT_SIZE); |
-{% for field in struct.fields %} |
-{% if field.default %} |
- {{field|name}} = {{field|default_value}}; |
-{% elif field.kind|is_handle %} |
- {{field|name}} = org.chromium.mojo.system.InvalidHandle.INSTANCE; |
-{% endif %} |
-{% endfor %} |
- } |
- |
- public static {{struct|name}} deserialize(org.chromium.mojo.bindings.Message message) { |
- return decode(new org.chromium.mojo.bindings.Decoder(message)); |
- } |
- |
- @SuppressWarnings("unchecked") |
- public static {{struct|name}} decode(org.chromium.mojo.bindings.Decoder decoder0) { |
- if (decoder0 == null) { |
- return null; |
- } |
- {{struct|name}} result = new {{struct|name}}(); |
-{% if not struct.bytes %} |
- decoder0.readDataHeader(); |
-{% else %} |
- DataHeader mainDataHeader = decoder0.readDataHeader(); |
-{% endif %} |
-{% for byte in struct.bytes %} |
-{% for packed_field in byte.packed_fields %} |
- if (mainDataHeader.numFields > {{packed_field.ordinal}}) { |
- {{decode('result.' ~ packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(12)}} |
- } |
-{% endfor %} |
-{% endfor %} |
- return result; |
- } |
- |
- @SuppressWarnings("unchecked") |
- @Override |
- protected final void encode(org.chromium.mojo.bindings.Encoder encoder) { |
-{% if not struct.bytes %} |
- encoder.getEncoderAtDataOffset(DEFAULT_STRUCT_INFO); |
-{% 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 %} |
- {{encode(packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(8)}} |
-{% endfor %} |
-{% endfor %} |
- } |
- |
- /** |
- * @see Object#equals(Object) |
- */ |
- @Override |
- public boolean equals(Object object) { |
- if (object == this) |
- return true; |
- if (object == null) |
- return false; |
- if (getClass() != object.getClass()) |
- return false; |
-{% if struct.fields|length %} |
- {{struct|name}} other = ({{struct|name}}) object; |
-{% for field in struct.fields %} |
- if ({{inequality(field.kind, field|name, 'other.'~field|name)}}) |
- return false; |
-{% endfor %} |
-{% endif %} |
- return true; |
- } |
- |
- /** |
- * @see Object#hashCode() |
- */ |
- @Override |
- public int hashCode() { |
- final int prime = 31; |
- int result = prime + getClass().hashCode(); |
-{% for field in struct.fields %} |
- result = prime * result + {{hash(field.kind, field|name)}}; |
-{% endfor %} |
- return result; |
- } |
-} |
-{% endmacro %} |