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

Unified Diff: mojo/public/tools/bindings/generators/mojom_java_generator.py

Issue 607933002: mojo: Fix java generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs and emptu package. Created 6 years, 3 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/mojom_java_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_java_generator.py b/mojo/public/tools/bindings/generators/mojom_java_generator.py
index 678c3e5ea846e8ccf155d919f054c7b4daaf2e8f..043d9e3acf4940029cf21459f6dddef3ac28a8bf 100644
--- a/mojo/public/tools/bindings/generators/mojom_java_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_java_generator.py
@@ -108,8 +108,11 @@ def CamelCase(name):
def ConstantStyle(name):
components = NameToComponent(name)
- if components[0] == 'k':
+ if components[0] == 'k' and len(components) > 1:
components = components[1:]
+ # variable cannot starts with a digit.
+ if components[0][0].isdigit():
+ components[0] = '_' + components[0]
return '_'.join([x.upper() for x in components])
def GetNameForElement(element):
@@ -126,9 +129,10 @@ def GetNameForElement(element):
return (GetNameForElement(element.enum) + '.' +
ConstantStyle(element.name))
if isinstance(element, (mojom.NamedValue,
- mojom.Constant)):
+ mojom.Constant,
+ mojom.EnumField)):
return ConstantStyle(element.name)
- raise Exception('Unexpected element: ' % element)
+ raise Exception('Unexpected element: %s' % element)
def GetInterfaceResponseName(method):
return UpperCamelCase(method.name + 'Response')
@@ -215,7 +219,9 @@ def GetPackage(module):
if 'JavaPackage' in module.attributes:
return ParseStringAttribute(module.attributes['JavaPackage'])
# Default package.
- return 'org.chromium.mojom.' + module.namespace
+ if module.namespace:
+ return 'org.chromium.mojom.' + module.namespace
+ return 'org.chromium.mojom'
def GetNameForKind(context, kind):
def _GetNameHierachy(kind):
@@ -344,13 +350,13 @@ def GetMethodOrdinalName(method):
def HasMethodWithResponse(interface):
for method in interface.methods:
- if method.response_parameters:
+ if method.response_parameters is not None:
return True
return False
def HasMethodWithoutResponse(interface):
for method in interface.methods:
- if not method.response_parameters:
+ if method.response_parameters is None:
return True
return False

Powered by Google App Engine
This is Rietveld 408576698