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

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

Issue 1034553003: [Extension API Extern Generation] Fix array, choices specification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 c.Append(' */') 173 c.Append(' */')
174 return c 174 return c
175 175
176 def _TypeToJsType(self, js_type): 176 def _TypeToJsType(self, js_type):
177 """Converts a model.Type to a JS type (number, Array, etc.)""" 177 """Converts a model.Type to a JS type (number, Array, etc.)"""
178 if js_type.property_type in (PropertyType.INTEGER, PropertyType.DOUBLE): 178 if js_type.property_type in (PropertyType.INTEGER, PropertyType.DOUBLE):
179 return 'number' 179 return 'number'
180 elif js_type.property_type is PropertyType.OBJECT: 180 elif js_type.property_type is PropertyType.OBJECT:
181 return 'Object' 181 return 'Object'
182 elif js_type.property_type is PropertyType.ARRAY: 182 elif js_type.property_type is PropertyType.ARRAY:
183 return 'Array' 183 return '!Array<%s>' % self._TypeToJsType(js_type.item_type)
184 elif js_type.property_type is PropertyType.REF: 184 elif js_type.property_type is PropertyType.REF:
185 ref_type = js_type.ref_type 185 ref_type = js_type.ref_type
186 # Enums are defined as chrome.fooAPI.MyEnum, but types are defined simply 186 # Enums are defined as chrome.fooAPI.MyEnum, but types are defined simply
187 # as MyType. 187 # as MyType.
188 if self._namespace.types[ref_type].property_type is PropertyType.ENUM: 188 if self._namespace.types[ref_type].property_type is PropertyType.ENUM:
189 ref_type = 'chrome.%s.%s' % (self._namespace.name, ref_type) 189 ref_type = '!chrome.%s.%s' % (self._namespace.name, ref_type)
190 return ref_type 190 return ref_type
191 elif js_type.property_type is PropertyType.CHOICES:
192 return '(%s)' % '|'.join(
193 [self._TypeToJsType(choice) for choice in js_type.choices])
194 elif js_type.property_type is PropertyType.ANY:
195 return '*'
191 elif js_type.property_type.is_fundamental: 196 elif js_type.property_type.is_fundamental:
192 return js_type.property_type.name 197 return js_type.property_type.name
193 else: 198 else:
194 return '?' # TODO(tbreisacher): Make this more specific. 199 return '?' # TODO(tbreisacher): Make this more specific.
195 200
196 def _GenerateFunction(self, function): 201 def _GenerateFunction(self, function):
197 """Generates the code representing a function, including its documentation. 202 """Generates the code representing a function, including its documentation.
198 For example: 203 For example:
199 204
200 /** 205 /**
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 * @const 242 * @const
238 */""") 243 */""")
239 .Append('chrome.%s = {};' % self._namespace.name)) 244 .Append('chrome.%s = {};' % self._namespace.name))
240 return c 245 return c
241 246
242 def _GenerateFunctionParams(self, function): 247 def _GenerateFunctionParams(self, function):
243 params = function.params[:] 248 params = function.params[:]
244 if function.callback: 249 if function.callback:
245 params.append(function.callback) 250 params.append(function.callback)
246 return ', '.join(param.name for param in params) 251 return ', '.join(param.name for param in params)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698