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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_js_generator.py

Issue 2888503002: Mojo bindings generator: introduce Stylizer to specify naming rules. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Generates JavaScript source files from a mojom.Module.""" 5 """Generates JavaScript source files from a mojom.Module."""
6 6
7 import mojom.generate.generator as generator 7 import mojom.generate.generator as generator
8 import mojom.generate.module as mojom 8 import mojom.generate.module as mojom
9 import mojom.generate.pack as pack 9 import mojom.generate.pack as pack
10 import os 10 import os
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return js_filters 150 return js_filters
151 151
152 @UseJinja("module.amd.tmpl") 152 @UseJinja("module.amd.tmpl")
153 def _GenerateAMDModule(self): 153 def _GenerateAMDModule(self):
154 return self._GetParameters() 154 return self._GetParameters()
155 155
156 def GenerateFiles(self, args): 156 def GenerateFiles(self, args):
157 if self.variant: 157 if self.variant:
158 raise Exception("Variants not supported in JavaScript bindings.") 158 raise Exception("Variants not supported in JavaScript bindings.")
159 159
160 # TODO(yzshen): Add a JavaScriptStylizer.
161 self.module.Stylize(generator.Stylizer())
162
160 # TODO(yzshen): Remove this method once the old JS bindings go away. 163 # TODO(yzshen): Remove this method once the old JS bindings go away.
161 self._SetUniqueNameForImports() 164 self._SetUniqueNameForImports()
162 165
163 self.Write(self._GenerateAMDModule(), 166 self.Write(self._GenerateAMDModule(), "%s.js" % self.module.path)
164 self.MatchMojomFilePath("%s.js" % self.module.name))
165 167
166 def _SetUniqueNameForImports(self): 168 def _SetUniqueNameForImports(self):
167 used_names = set() 169 used_names = set()
168 for each_import in self.module.imports: 170 for each_import in self.module.imports:
169 simple_name = each_import.name.split(".")[0] 171 simple_name = os.path.basename(each_import.path).split(".")[0]
170 172
171 # Since each import is assigned a variable in JS, they need to have unique 173 # Since each import is assigned a variable in JS, they need to have unique
172 # names. 174 # names.
173 unique_name = simple_name 175 unique_name = simple_name
174 counter = 0 176 counter = 0
175 while unique_name in used_names: 177 while unique_name in used_names:
176 counter += 1 178 counter += 1
177 unique_name = simple_name + str(counter) 179 unique_name = simple_name + str(counter)
178 180
179 used_names.add(unique_name) 181 used_names.add(unique_name)
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return self._TranslateConstants(value) 376 return self._TranslateConstants(value)
375 377
376 def _GetStructsFromMethods(self): 378 def _GetStructsFromMethods(self):
377 result = [] 379 result = []
378 for interface in self.module.interfaces: 380 for interface in self.module.interfaces:
379 for method in interface.methods: 381 for method in interface.methods:
380 result.append(method.param_struct) 382 result.append(method.param_struct)
381 if method.response_param_struct is not None: 383 if method.response_param_struct is not None:
382 result.append(method.response_param_struct) 384 result.append(method.response_param_struct)
383 return result 385 return result
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_java_generator.py ('k') | mojo/public/tools/bindings/mojom_bindings_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698