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

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 and resolved conflicts 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):
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 66
63 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) 67 c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
64 for namespace in self._model.namespaces.values(): 68 for namespace in self._model.namespaces.values():
65 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) 69 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
66 c.Append() 70 c.Append()
67 c.Concat(self.GenerateFunctionRegistry()) 71 c.Concat(self.GenerateFunctionRegistry())
68 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 72 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
69 c.Append() 73 c.Append()
70 return self.GenerateHeader('generated_api', c) 74 return self.GenerateHeader('generated_api', c)
71 75
72 def CapitalizeFirstLetter(self, value):
73 return value[0].capitalize() + value[1:]
74
75 def GenerateFunctionRegistry(self): 76 def GenerateFunctionRegistry(self):
76 c = code.Code() 77 c = code.Code()
77 c.Sblock("class GeneratedFunctionRegistry {") 78 c.Sblock("class GeneratedFunctionRegistry {")
78 c.Append("public:") 79 c.Append("public:")
79 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {") 80 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {")
80 for namespace in self._model.namespaces.values(): 81 for namespace in self._model.namespaces.values():
81 for function in namespace.functions.values(): 82 for function in namespace.functions.values():
82 if function.nocompile: 83 if function.nocompile:
83 continue 84 continue
84 namespace_name = self.CapitalizeFirstLetter(namespace.name.replace( 85
85 "experimental.", "")) 86 # Transform a fully qualified function name like foo.bar.baz into
Mihai Parparita -not on Chrome 2012/06/26 05:19:16 Move into a function so that it can be unit tested
asargent_no_longer_on_chrome 2012/07/20 00:11:46 Done.
Mihai Parparita -not on Chrome 2012/07/20 00:36:52 Not seeing this change in the current patch.
86 function_name = namespace_name + self.CapitalizeFirstLetter( 87 # FooBarBaz, stripping any leading 'Experimental' prefix.
87 function.name) 88 parts = []
89 function_name = namespace.name + "." + function.name
90 for part in function_name.split("."):
91 parts.append(CapitalizeFirstLetter(part))
92 if parts[0] == "Experimental":
93 del parts[0]
94 function_name = "".join(parts)
95
88 c.Append("registry->RegisterFunction<%sFunction>();" % ( 96 c.Append("registry->RegisterFunction<%sFunction>();" % (
89 function_name)) 97 function_name))
90 c.Eblock("}") 98 c.Eblock("}")
91 c.Eblock("};") 99 c.Eblock("};")
92 c.Append() 100 c.Append()
93 return c 101 return c
94 102
95 def GenerateSchemasHeader(self): 103 def GenerateSchemasHeader(self):
96 """Generates a code.Code object for the generated schemas .h file""" 104 """Generates a code.Code object for the generated schemas .h file"""
97 c = code.Code() 105 c = code.Code()
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 for index, line in enumerate(lines): 145 for index, line in enumerate(lines):
138 line = ' "%s"' % line 146 line = ' "%s"' % line
139 if index == len(lines) - 1: 147 if index == len(lines) - 1:
140 line += ';' 148 line += ';'
141 c.Append(line) 149 c.Append(line)
142 c.Eblock('}') 150 c.Eblock('}')
143 c.Append() 151 c.Append()
144 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 152 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
145 c.Append() 153 c.Append()
146 return c 154 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698