Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl

Issue 683583002: Update mojo sdk to rev e083961bf11fd0c94d40be8853761da529b6d444 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: geolocation Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index f187dc13fd8b08bdb5ee4c87d9171750677db4f3..feeeab28532f072ed654688aa601e65771ae72f4 100644
--- a/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl
@@ -1,6 +1,34 @@
{% 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 %}
@@ -147,5 +175,37 @@ if (decoder{{level+1}} == null) {
{% 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;
+ {{struct|name}} other = ({{struct|name}}) object;
+{% for field in struct.fields %}
+ if ({{inequality(field.kind, field|name, 'other.'~field|name)}})
+ return false;
+{% endfor %}
+ return true;
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+{% for field in struct.fields %}
+ result = prime * result + {{hash(field.kind, field|name)}};
+{% endfor %}
+ return result;
+ }
}
{% endmacro %}
« no previous file with comments | « mojo/public/python/mojo/bindings/reflection.py ('k') | mojo/public/tools/bindings/generators/mojom_java_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698