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: tools/json_schema_compiler/js_util.py

Issue 1513573012: Fix line wrapping in json_schema_compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Generate -> Append Created 4 years, 11 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 | « tools/json_schema_compiler/js_interface_generator_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/js_util.py
diff --git a/tools/json_schema_compiler/js_util.py b/tools/json_schema_compiler/js_util.py
index f304b98b153d42995fe2aa5b5ff7efd4bcbc0eab..25995c0c8ecb97ea87998e8e967716a5ed2e34c1 100644
--- a/tools/json_schema_compiler/js_util.py
+++ b/tools/json_schema_compiler/js_util.py
@@ -30,14 +30,14 @@ class JsUtil(object):
"""
return (INFO % tool)
- def GenerateObjectDefinition(self, namespace_name, properties):
+ def AppendObjectDefinition(self, c, namespace_name, properties,
+ new_line=True):
"""Given an OrderedDict of properties, returns a Code containing the
description of an object.
"""
- if not properties: return Code()
+ if not properties: return
- c = Code()
- c.Sblock('{')
+ c.Sblock('{', new_line=new_line)
first = True
for field, prop in properties.items():
# Avoid trailing comma.
@@ -48,23 +48,19 @@ class JsUtil(object):
first = False
js_type = self._TypeToJsType(namespace_name, prop.type_)
if prop.optional:
- js_type = (Code().
- Append('(').
- Concat(js_type, new_line=False).
- Append('|undefined)', new_line=False))
+ js_type = (Code().Append('(')
+ .Concat(js_type, new_line=False)
+ .Append('|undefined)', new_line=False))
c.Append('%s: ' % field, strip_right=False)
c.Concat(js_type, new_line=False)
c.Eblock('}')
- return c
-
- def GenerateFunctionJsDoc(self, namespace_name, function):
- """Generates the documentation for a function as a Code.
+ def AppendFunctionJsDoc(self, c, namespace_name, function):
+ """Appends the documentation for a function as a Code.
Returns an empty code object if the object has no documentation.
"""
- c = Code()
c.Sblock(line='/**', line_prefix=' * ')
if function.description:
@@ -75,13 +71,15 @@ class JsUtil(object):
c.Concat(js_type, new_line=False)
if optional:
c.Append('=', new_line=False)
- c.Append('} %s' % name, new_line=False)
+ c.Append('}', new_line=False)
+ c.Comment(' %s' % name, comment_prefix='', wrap_indent=4, new_line=False)
if description:
c.Comment(' %s' % description, comment_prefix='',
wrap_indent=4, new_line=False)
for param in function.params:
- append_field(c, 'param', self._TypeToJsType(namespace_name, param.type_),
+ append_field(c, 'param',
+ self._TypeToJsType(namespace_name, param.type_),
param.name, param.optional, param.description)
if function.callback:
@@ -99,10 +97,9 @@ class JsUtil(object):
if function.deprecated:
c.Append('@deprecated %s' % function.deprecated)
- c.Append(self.GenerateSeeLink(namespace_name, 'method', function.name))
+ c.Append(self.GetSeeLink(namespace_name, 'method', function.name))
c.Eblock(' */')
- return c
def _FunctionToJsFunction(self, namespace_name, function):
"""Converts a model.Function to a JS type (i.e., function([params])...)"""
@@ -128,8 +125,9 @@ class JsUtil(object):
return Code().Append('number')
if js_type.property_type is PropertyType.OBJECT:
if js_type.properties:
- return self.GenerateObjectDefinition(namespace_name,
- js_type.properties)
+ c = Code()
+ self.AppendObjectDefinition(c, namespace_name, js_type.properties)
+ return c
return Code().Append('Object')
if js_type.property_type is PropertyType.ARRAY:
return (Code().Append('!Array<').
@@ -156,8 +154,8 @@ class JsUtil(object):
return Code().Append(js_type.property_type.name)
return Code().Append('?') # TODO(tbreisacher): Make this more specific.
- def GenerateSeeLink(self, namespace_name, object_type, object_name):
- """Generates a @see link for a given API 'object' (type, method, or event).
+ def GetSeeLink(self, namespace_name, object_type, object_name):
+ """Returns a @see link for a given API 'object' (type, method, or event).
"""
# NOTE(devlin): This is kind of a hack. Some APIs will be hosted on
« no previous file with comments | « tools/json_schema_compiler/js_interface_generator_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698