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

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

Issue 306893010: Generate java bindings for structs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow review Created 6 years, 6 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/enum_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/java_templates/enum_definition.tmpl b/mojo/public/tools/bindings/generators/java_templates/enum_definition.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..a052e7c2a370587fb56ad6a3887c59a0601bd25c
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/java_templates/enum_definition.tmpl
@@ -0,0 +1,21 @@
+{%- macro enum_value(enum, field, index) -%}
+{%- if field.value -%}
+(int) ({{field.value|expression_to_text(enum.module)}})
+{%- elif index == 0 -%}
+0
+{%- else -%}
+{{enum.fields[index - 1].name}} + 1
+{%- endif -%}
+{%- endmacro -%}
+
+{%- macro enum_def(enum, top_level) -%}
+public {{ 'static ' if not top_level }}final class {{enum|name}} {
+
+{% for field in enum.fields %}
+ public static final int {{field.name}} = {{enum_value(enum, field, loop.index0)}};
+{% endfor %}
+
+ private {{enum|name}}() {}
+
+}
+{%- endmacro -%}

Powered by Google App Engine
This is Rietveld 408576698