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

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

Issue 626653002: Automatically generate externs.js for a format (idl, json) supported by tools/json_schema_compiler. Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Minor changes. Created 6 years, 2 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 | « tools/json_schema_compiler/compiler.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """
5 Generates an externs.js file for Chrome extension APIs.
6 """
7
8 from code import Code
9 from model import CamelName, Function, PropertyType
10 from schema_util import StripNamespace
11
12 import os
13 from datetime import datetime
14
15 LICENSE = (
16 """// Copyright %s The Chromium Authors. All rights reserved.
17 // Use of this source code is governed by a BSD-style license that can be
18 // found in the LICENSE file.""" %
19 datetime.now().year)
20
21 PREAMBLE = (
22 """// Auto generated externs.js; do not edit.
23 """)
24
25 class ExternsJsGenerator(object):
26 def Generate(self, namespace):
27 self.api_namespace_ = 'chrome.%s' % CamelName(namespace.unix_name)
28
29 c = Code()
30 c.Append(LICENSE)
31
32 c.Append()
33
34 c.Append('/**')
35 c.Append(' * @const')
36 c.Append(' */')
37 c.Append('%s = {};' % self.api_namespace_)
38
39 # TODO(dtseng): Support namespace.functions, namespace.events.
40 for value in namespace.types.values():
41 c.Append('/**')
42 if value.description:
43 c.Append(' * %s' % value.description)
44 if value.property_type.name == 'enum':
45 c.Append(' * @enum {string}')
46 c.Append(' */')
47 c.Append('%s.%s = {' % (self.api_namespace_, value.name))
48 entries = []
49 for enum_value in value.enum_values:
50 entries.append(' %s: \'%s\'' % (enum_value.name, enum_value.name))
51 c.Append(',\n'.join(entries))
52 c.Append('};')
53 elif value.property_type.name == 'object':
54 # TODO(dtseng): Implement fully.
55 c.Append(' * @constructor')
56 c.Append(' */')
57 c.Append('%s.%s = function() {};' % (self.api_namespace_, value.name))
58 else:
59 raise Exception('Unknown property type: %s' % value.property_type.name)
60 return c
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/compiler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698