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 interface file for the Closure Compiler. | 5 Generator that produces an interface file for the Closure Compiler. |
6 Note: This is a work in progress, and generated interfaces may require tweaking. | 6 Note: This is a work in progress, and generated interfaces may require tweaking. |
7 """ | 7 """ |
8 | 8 |
9 from code import Code | 9 from code import Code |
10 from js_util import JsUtil | 10 from js_util import JsUtil |
(...skipping 28 matching lines...) Expand all Loading... |
39 .Append()) | 39 .Append()) |
40 | 40 |
41 self._AppendInterfaceObject(c) | 41 self._AppendInterfaceObject(c) |
42 c.Append() | 42 c.Append() |
43 | 43 |
44 c.Sblock('%s.prototype = {' % self._interface) | 44 c.Sblock('%s.prototype = {' % self._interface) |
45 | 45 |
46 for function in self._namespace.functions.values(): | 46 for function in self._namespace.functions.values(): |
47 self._AppendFunction(c, function) | 47 self._AppendFunction(c, function) |
48 | 48 |
| 49 c.TrimTrailingNewlines() |
| 50 c.Eblock('};') |
| 51 c.Append() |
| 52 |
49 for event in self._namespace.events.values(): | 53 for event in self._namespace.events.values(): |
50 self._AppendEvent(c, event) | 54 self._AppendEvent(c, event) |
51 | 55 |
52 c.TrimTrailingNewlines() | 56 c.TrimTrailingNewlines() |
53 | 57 |
54 c.Eblock('};') | |
55 | |
56 return c | 58 return c |
57 | 59 |
58 def _GetHeader(self, tool, namespace): | 60 def _GetHeader(self, tool, namespace): |
59 """Returns the file header text. | 61 """Returns the file header text. |
60 """ | 62 """ |
61 return (self._js_util.GetLicense() + '\n' + | 63 return (self._js_util.GetLicense() + '\n' + |
62 self._js_util.GetInfo(tool) + '\n' + | 64 self._js_util.GetInfo(tool) + '\n' + |
63 ('/** @fileoverview Interface for %s that can be overriden. */' % | 65 ('/** @fileoverview Interface for %s that can be overriden. */' % |
64 namespace) + '\n' + | 66 namespace) + '\n' + |
65 ASSERT); | 67 ASSERT); |
(...skipping 20 matching lines...) Expand all Loading... |
86 def _AppendEvent(self, c, event): | 88 def _AppendEvent(self, c, event): |
87 """Appends the interface for an event. | 89 """Appends the interface for an event. |
88 """ | 90 """ |
89 c.Sblock(line='/**', line_prefix=' * ') | 91 c.Sblock(line='/**', line_prefix=' * ') |
90 if (event.description): | 92 if (event.description): |
91 c.Comment(event.description, comment_prefix='') | 93 c.Comment(event.description, comment_prefix='') |
92 c.Append('@type {!ChromeEvent}') | 94 c.Append('@type {!ChromeEvent}') |
93 c.Append(self._js_util.GetSeeLink(self._namespace.name, 'event', | 95 c.Append(self._js_util.GetSeeLink(self._namespace.name, 'event', |
94 event.name)) | 96 event.name)) |
95 c.Eblock(' */') | 97 c.Eblock(' */') |
96 c.Append('%s: new ChromeEvent(),' % (event.name)) | 98 |
| 99 c.Append('%s.prototype.%s;' % (self._interface, event.name)) |
| 100 |
97 c.Append() | 101 c.Append() |
OLD | NEW |