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

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

Issue 10659021: Move chrome.appWindow to chrome.app.window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import code 5 import code
6 import cpp_util 6 import cpp_util
7 7
8 import json 8 import json
9 import os 9 import os
10 import re 10 import re
11 11
12 # TODO(miket/asargent) - parameterize this. 12 # TODO(miket/asargent) - parameterize this.
13 SOURCE_BASE_PATH = 'chrome/common/extensions/api' 13 SOURCE_BASE_PATH = 'chrome/common/extensions/api'
14 14
15
16 def CapitalizeFirstLetter(value):
not at google - send to devlin 2012/07/18 04:27:37 nit: start with _
asargent_no_longer_on_chrome 2012/07/20 00:11:47 this function moved to schema_util.py
17 return value[0].capitalize() + value[1:]
18
15 class SchemaBundleGenerator(object): 19 class SchemaBundleGenerator(object):
16 """This class contains methods to generate code based on multiple schemas. 20 """This class contains methods to generate code based on multiple schemas.
17 """ 21 """
18 22
19 def __init__(self, model, api_defs, cpp_type_generator): 23 def __init__(self, model, api_defs, cpp_type_generator):
20 self._model = model 24 self._model = model
21 self._api_defs = api_defs 25 self._api_defs = api_defs
22 self._cpp_type_generator = cpp_type_generator 26 self._cpp_type_generator = cpp_type_generator
23 27
24 def GenerateHeader(self, file_base, body_code): 28 def GenerateHeader(self, file_base, body_code):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 65
62 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) 66 c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
63 for namespace in self._model.namespaces.values(): 67 for namespace in self._model.namespaces.values():
64 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) 68 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
65 c.Append() 69 c.Append()
66 c.Concat(self.GenerateFunctionRegistry()) 70 c.Concat(self.GenerateFunctionRegistry())
67 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 71 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
68 c.Append() 72 c.Append()
69 return self.GenerateHeader('generated_api', c) 73 return self.GenerateHeader('generated_api', c)
70 74
71 def CapitalizeFirstLetter(self, value):
72 return value[0].capitalize() + value[1:]
73
74 def GenerateFunctionRegistry(self): 75 def GenerateFunctionRegistry(self):
75 c = code.Code() 76 c = code.Code()
76 c.Sblock("class GeneratedFunctionRegistry {") 77 c.Sblock("class GeneratedFunctionRegistry {")
77 c.Append("public:") 78 c.Append("public:")
78 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {") 79 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {")
79 for namespace in self._model.namespaces.values(): 80 for namespace in self._model.namespaces.values():
80 for function in namespace.functions.values(): 81 for function in namespace.functions.values():
81 if function.nocompile: 82 if function.nocompile:
82 continue 83 continue
83 namespace_name = self.CapitalizeFirstLetter(namespace.name.replace( 84
84 "experimental.", "")) 85 # Transform a fully qualified function name like foo.bar.baz into
85 function_name = namespace_name + self.CapitalizeFirstLetter( 86 # FooBarBaz, stripping any leading 'Experimental' prefix.
86 function.name) 87 parts = []
88 function_name = namespace.name + "." + function.name
89 for part in function_name.split("."):
90 parts.append(CapitalizeFirstLetter(part))
91 if parts[0] == "Experimental":
92 del parts[0]
93 function_name = "".join(parts)
94
87 c.Append("registry->RegisterFunction<%sFunction>();" % ( 95 c.Append("registry->RegisterFunction<%sFunction>();" % (
88 function_name)) 96 function_name))
89 c.Eblock("}") 97 c.Eblock("}")
90 c.Eblock("};") 98 c.Eblock("};")
91 c.Append() 99 c.Append()
92 return c 100 return c
93 101
94 def GenerateSchemasHeader(self): 102 def GenerateSchemasHeader(self):
95 """Generates a code.Code object for the generated schemas .h file""" 103 """Generates a code.Code object for the generated schemas .h file"""
96 c = code.Code() 104 c = code.Code()
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 for index, line in enumerate(lines): 144 for index, line in enumerate(lines):
137 line = ' "%s"' % line 145 line = ' "%s"' % line
138 if index == len(lines) - 1: 146 if index == len(lines) - 1:
139 line += ';' 147 line += ';'
140 c.Append(line) 148 c.Append(line)
141 c.Eblock('}') 149 c.Eblock('}')
142 c.Append() 150 c.Append()
143 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 151 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
144 c.Append() 152 c.Append()
145 return c 153 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698