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

Unified Diff: build/android/gyp/java_cpp_enum.py

Issue 1932183002: Add IntDefs to generated Java enums. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update deps. Created 4 years, 5 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
« no previous file with comments | « blimp/client/BUILD.gn ('k') | build/android/gyp/java_cpp_enum_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « blimp/client/BUILD.gn ('k') | build/android/gyp/java_cpp_enum_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698