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

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: fix typo 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 from schema_util import CapitalizeFirstLetter
8 from schema_util import JsFunctionNameToClassName
7 9
8 import json 10 import json
9 import os 11 import os
10 import re 12 import re
11 13
12 # TODO(miket/asargent) - parameterize this. 14 # TODO(miket/asargent) - parameterize this.
13 SOURCE_BASE_PATH = 'chrome/common/extensions/api' 15 SOURCE_BASE_PATH = 'chrome/common/extensions/api'
14 16
15 class SchemaBundleGenerator(object): 17 class SchemaBundleGenerator(object):
16 """This class contains methods to generate code based on multiple schemas. 18 """This class contains methods to generate code based on multiple schemas.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 63
62 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) 64 c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
63 for namespace in self._model.namespaces.values(): 65 for namespace in self._model.namespaces.values():
64 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) 66 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
65 c.Append() 67 c.Append()
66 c.Concat(self.GenerateFunctionRegistry()) 68 c.Concat(self.GenerateFunctionRegistry())
67 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 69 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
68 c.Append() 70 c.Append()
69 return self.GenerateHeader('generated_api', c) 71 return self.GenerateHeader('generated_api', c)
70 72
71 def CapitalizeFirstLetter(self, value):
72 return value[0].capitalize() + value[1:]
73
74 def GenerateFunctionRegistry(self): 73 def GenerateFunctionRegistry(self):
75 c = code.Code() 74 c = code.Code()
76 c.Sblock("class GeneratedFunctionRegistry {") 75 c.Sblock("class GeneratedFunctionRegistry {")
77 c.Append("public:") 76 c.Append("public:")
78 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {") 77 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {")
79 for namespace in self._model.namespaces.values(): 78 for namespace in self._model.namespaces.values():
80 namespace_name = self.CapitalizeFirstLetter(namespace.name.replace( 79 namespace_name = CapitalizeFirstLetter(namespace.name.replace(
81 "experimental.", "")) 80 "experimental.", ""))
82 for function in namespace.functions.values(): 81 for function in namespace.functions.values():
83 if function.nocompile: 82 if function.nocompile:
84 continue 83 continue
85 function_name = namespace_name + self.CapitalizeFirstLetter( 84 function_name = JsFunctionNameToClassName(namespace.name, function.name)
86 function.name) 85 c.Append("registry->RegisterFunction<%sFunction>();" % (
87 c.Append("registry->RegisterFunction<%sFunction>();" % function_name) 86 function_name))
88 c.Eblock("}") 87 c.Eblock("}")
89 c.Eblock("};") 88 c.Eblock("};")
90 c.Append() 89 c.Append()
91 return c 90 return c
92 91
93 def GenerateSchemasHeader(self): 92 def GenerateSchemasHeader(self):
94 """Generates a code.Code object for the generated schemas .h file""" 93 """Generates a code.Code object for the generated schemas .h file"""
95 c = code.Code() 94 c = code.Code()
96 c.Append('#include <map>') 95 c.Append('#include <map>')
97 c.Append('#include <string>') 96 c.Append('#include <string>')
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 for index, line in enumerate(lines): 134 for index, line in enumerate(lines):
136 line = ' "%s"' % line 135 line = ' "%s"' % line
137 if index == len(lines) - 1: 136 if index == len(lines) - 1:
138 line += ';' 137 line += ';'
139 c.Append(line) 138 c.Append(line)
140 c.Eblock('}') 139 c.Eblock('}')
141 c.Append() 140 c.Append()
142 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 141 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
143 c.Append() 142 c.Append()
144 return c 143 return c
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/platform_apps/windows_api/test.js ('k') | tools/json_schema_compiler/schema_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698