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

Side by Side Diff: tools/json_schema_compiler/js_externs_generator.py

Issue 1010603007: [Extension API Extern Generation] Fix comment indentation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: True 80 char limit Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 """ 4 """
5 Generator that produces an externs file for the Closure Compiler. 5 Generator that produces an externs file for the Closure Compiler.
6 Note: This is a work in progress, and generated externs may require tweaking. 6 Note: This is a work in progress, and generated externs may require tweaking.
7 7
8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs 8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs
9 """ 9 """
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 """ 87 """
88 c = Code() 88 c = Code()
89 c.Append('/**') 89 c.Append('/**')
90 90
91 if js_type.description: 91 if js_type.description:
92 for line in js_type.description.splitlines(): 92 for line in js_type.description.splitlines():
93 c.Comment(line, comment_prefix = ' * ') 93 c.Comment(line, comment_prefix = ' * ')
94 94
95 is_constructor = self._IsTypeConstructor(js_type) 95 is_constructor = self._IsTypeConstructor(js_type)
96 if is_constructor: 96 if is_constructor:
97 c.Comment('@constructor', comment_prefix = ' * ') 97 c.Comment('@constructor', comment_prefix = ' * ', wrap_indent=4)
98 else: 98 else:
99 c.Concat(self._GenerateTypedef(js_type.properties)) 99 c.Concat(self._GenerateTypedef(js_type.properties))
100 100
101 c.Append(' */') 101 c.Append(' */')
102 102
103 var = 'var ' + js_type.simple_name 103 var = 'var ' + js_type.simple_name
104 if is_constructor: var += ' = function() {}' 104 if is_constructor: var += ' = function() {}'
105 var += ';' 105 var += ';'
106 c.Append(var) 106 c.Append(var)
107 107
(...skipping 26 matching lines...) Expand all
134 def _GenerateFunctionJsDoc(self, function): 134 def _GenerateFunctionJsDoc(self, function):
135 """Generates the documentation for a function as a Code. 135 """Generates the documentation for a function as a Code.
136 136
137 Returns an empty code object if the object has no documentation. 137 Returns an empty code object if the object has no documentation.
138 """ 138 """
139 c = Code() 139 c = Code()
140 c.Append('/**') 140 c.Append('/**')
141 141
142 lines = [] 142 lines = []
143 if function.description: 143 if function.description:
144 lines.extend(function.description.splitlines()) 144 for line in function.description.splitlines():
145 c.Comment(line, comment_prefix=' * ')
145 146
146 for param in function.params: 147 for param in function.params:
147 js_type = self._TypeToJsType(param.type_) 148 js_type = self._TypeToJsType(param.type_)
148 if param.optional: 149 if param.optional:
149 js_type += '=' 150 js_type += '='
150 lines.append('@param {%s} %s %s' % (js_type, 151 lines.append('@param {%s} %s %s' % (js_type,
151 param.name, 152 param.name,
152 param.description or '')) 153 param.description or ''))
153 154
154 if function.callback: 155 if function.callback:
155 lines.append('@param {%s} %s %s' % ( 156 lines.append('@param {%s} %s %s' % (
156 self._FunctionToJsFunction(function.callback), 157 self._FunctionToJsFunction(function.callback),
157 function.callback.name, 158 function.callback.name,
158 function.callback.description or '')) 159 function.callback.description or ''))
159 160
160 if function.returns: 161 if function.returns:
161 lines.append('@return {%s} %s' % (self._TypeToJsType(function.returns), 162 lines.append('@return {%s} %s' % (self._TypeToJsType(function.returns),
162 function.returns.description or '')) 163 function.returns.description or ''))
163 164
164 if function.deprecated: 165 if function.deprecated:
165 lines.append('@deprecated %s' % function.deprecated) 166 lines.append('@deprecated %s' % function.deprecated)
166 167
167 for line in lines: 168 for line in lines:
168 c.Comment(line, comment_prefix=' * '); 169 c.Comment(line, comment_prefix=' * ', wrap_indent=4);
169 170
170 c.Append(' */') 171 c.Append(' */')
171 return c 172 return c
172 173
173 def _FunctionToJsFunction(self, function): 174 def _FunctionToJsFunction(self, function):
174 """Converts a model.Function to a JS type (i.e., function([params])...)""" 175 """Converts a model.Function to a JS type (i.e., function([params])...)"""
175 params = ', '.join( 176 params = ', '.join(
176 [self._TypeToJsType(param.type_) for param in function.params]) 177 [self._TypeToJsType(param.type_) for param in function.params])
177 return_type = ( 178 return_type = (
178 self._TypeToJsType(function.returns) if function.returns else 'void') 179 self._TypeToJsType(function.returns) if function.returns else 'void')
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 * @const 251 * @const
251 */""") 252 */""")
252 .Append('chrome.%s = {};' % self._namespace.name)) 253 .Append('chrome.%s = {};' % self._namespace.name))
253 return c 254 return c
254 255
255 def _GenerateFunctionParams(self, function): 256 def _GenerateFunctionParams(self, function):
256 params = function.params[:] 257 params = function.params[:]
257 if function.callback: 258 if function.callback:
258 params.append(function.callback) 259 params.append(function.callback)
259 return ', '.join(param.name for param in params) 260 return ', '.join(param.name for param in params)
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/code_test.py ('k') | tools/json_schema_compiler/js_externs_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698