Index: build/android/gyp/java_cpp_enum.py |
diff --git a/build/android/gyp/java_cpp_enum.py b/build/android/gyp/java_cpp_enum.py |
index b304930d9d763089862948d8085b7304e24ff0a0..21913da76d7f5f22df4447f082ef825bb008f71d 100755 |
--- a/build/android/gyp/java_cpp_enum.py |
+++ b/build/android/gyp/java_cpp_enum.py |
@@ -11,6 +11,7 @@ import optparse |
import os |
from string import Template |
import sys |
+import textwrap |
import zipfile |
from util import build_utils |
@@ -265,25 +266,49 @@ def GenerateOutput(source_path, enum_definition): |
package ${PACKAGE}; |
+import android.support.annotation.IntDef; |
+ |
+import java.lang.annotation.Retention; |
+import java.lang.annotation.RetentionPolicy; |
+ |
public class ${CLASS_NAME} { |
+ @IntDef({ |
+${INT_DEF} |
+ }) |
+ @Retention(RetentionPolicy.SOURCE) |
+ public @interface ${ANNOTATION} {} |
${ENUM_ENTRIES} |
} |
""") |
enum_template = Template(' public static final int ${NAME} = ${VALUE};') |
enum_entries_string = [] |
+ enum_names = [] |
for enum_name, enum_value in enum_definition.entries.iteritems(): |
values = { |
'NAME': enum_name, |
'VALUE': enum_value, |
} |
enum_entries_string.append(enum_template.substitute(values)) |
+ enum_names.append(enum_name) |
enum_entries_string = '\n'.join(enum_entries_string) |
+ enum_names_indent = ' ' * 6 |
+ wrapper = textwrap.TextWrapper(initial_indent = enum_names_indent, |
+ subsequent_indent = enum_names_indent, |
+ width = 100) |
+ enum_names_string = '\n'.join(wrapper.wrap(', '.join(enum_names))) |
+ |
+ annotation_template = Template('${NAME}Enum') |
+ annotation_values = { 'NAME': enum_definition.class_name, } |
+ annotation_name = annotation_template.substitute(annotation_values) |
+ |
values = { |
'CLASS_NAME': enum_definition.class_name, |
'ENUM_ENTRIES': enum_entries_string, |
'PACKAGE': enum_definition.enum_package, |
+ 'INT_DEF': enum_names_string, |
+ 'ANNOTATION': annotation_name, |
'SCRIPT_NAME': GetScriptName(), |
'SOURCE_PATH': source_path, |
'YEAR': str(date.today().year) |