| OLD | NEW |
| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if prop.type_.property_type is PropertyType.FUNCTION: | 144 if prop.type_.property_type is PropertyType.FUNCTION: |
| 145 self._AppendFunction(c, prop.type_.function) | 145 self._AppendFunction(c, prop.type_.function) |
| 146 else: | 146 else: |
| 147 self._AppendTypeJsDoc(c, prop.type_, prop.optional) | 147 self._AppendTypeJsDoc(c, prop.type_, prop.optional) |
| 148 c.Append() | 148 c.Append() |
| 149 self._class_name = None | 149 self._class_name = None |
| 150 | 150 |
| 151 def _AppendTypedef(self, c, properties): | 151 def _AppendTypedef(self, c, properties): |
| 152 """Given an OrderedDict of properties, Appends code containing a @typedef. | 152 """Given an OrderedDict of properties, Appends code containing a @typedef. |
| 153 """ | 153 """ |
| 154 if not properties: return | 154 c.Append('@typedef {') |
| 155 | 155 |
| 156 c.Append('@typedef {') | 156 if properties: |
| 157 self._js_util.AppendObjectDefinition(c, self._namespace.name, properties, | 157 self._js_util.AppendObjectDefinition(c, self._namespace.name, properties, |
| 158 new_line=False) | 158 new_line=False) |
| 159 else: |
| 160 c.Append('Object', new_line=False) |
| 161 |
| 159 c.Append('}', new_line=False) | 162 c.Append('}', new_line=False) |
| 160 | 163 |
| 161 def _AppendFunction(self, c, function): | 164 def _AppendFunction(self, c, function): |
| 162 """Appends the code representing a function, including its documentation. | 165 """Appends the code representing a function, including its documentation. |
| 163 For example: | 166 For example: |
| 164 | 167 |
| 165 /** | 168 /** |
| 166 * @param {string} title The new title. | 169 * @param {string} title The new title. |
| 167 */ | 170 */ |
| 168 chrome.window.setTitle = function(title) {}; | 171 chrome.window.setTitle = function(title) {}; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 For example, it might return "chrome.namespace". | 222 For example, it might return "chrome.namespace". |
| 220 | 223 |
| 221 Also optionally includes the class name if this is in the context | 224 Also optionally includes the class name if this is in the context |
| 222 of outputting the members of a class. | 225 of outputting the members of a class. |
| 223 | 226 |
| 224 For example, "chrome.namespace.ClassName.prototype" | 227 For example, "chrome.namespace.ClassName.prototype" |
| 225 """ | 228 """ |
| 226 if self._class_name: | 229 if self._class_name: |
| 227 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) | 230 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) |
| 228 return 'chrome.%s' % self._namespace.name | 231 return 'chrome.%s' % self._namespace.name |
| OLD | NEW |