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

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

Issue 1529423002: Dart: Fix conversion of identifiers to lowerCamelCase. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Comments Created 5 years 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 | « mojo/public/interfaces/bindings/tests/regression_tests.mojom ('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
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 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 dart source files from a mojom.Module.""" 5 """Generates dart source files from a mojom.Module."""
6 6
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import sys 10 import sys
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 value_type = DartDeclType(kind.value_kind) 219 value_type = DartDeclType(kind.value_kind)
220 return "Map<"+ key_type + ", " + value_type + ">" 220 return "Map<"+ key_type + ", " + value_type + ">"
221 if mojom.IsInterfaceKind(kind) or \ 221 if mojom.IsInterfaceKind(kind) or \
222 mojom.IsInterfaceRequestKind(kind): 222 mojom.IsInterfaceRequestKind(kind):
223 return "Object" 223 return "Object"
224 if mojom.IsEnumKind(kind): 224 if mojom.IsEnumKind(kind):
225 return GetDartType(kind) 225 return GetDartType(kind)
226 226
227 def NameToComponent(name): 227 def NameToComponent(name):
228 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar -> 228 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar ->
229 # HTTP_Entry2_FooBar) 229 # HTTP_Entry2_FooBar). Numbers terminate a string of lower-case characters.
230 name = re.sub('([^_])([A-Z][^A-Z_]+)', r'\1_\2', name) 230 name = re.sub('([^_])([A-Z][^A-Z1-9_]+)', r'\1_\2', name)
231 # insert '_' between non upper and start of upper blocks (e.g., 231 # insert '_' between non upper and start of upper blocks (e.g.,
232 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar) 232 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar).
233 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name) 233 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name)
234 return [x.lower() for x in name.split('_')] 234 return [x.lower() for x in name.split('_')]
235 235
236 def UpperCamelCase(name): 236 def UpperCamelCase(name):
237 return ''.join([x.capitalize() for x in NameToComponent(name)]) 237 return ''.join([x.capitalize() for x in NameToComponent(name)])
238 238
239 def CamelCase(name): 239 def CamelCase(name):
240 uccc = UpperCamelCase(name) 240 uccc = UpperCamelCase(name)
241 return uccc[0].lower() + uccc[1:] 241 return uccc[0].lower() + uccc[1:]
242 242
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 interface_to_import[name] = each_import["unique_name"] + "." + name 554 interface_to_import[name] = each_import["unique_name"] + "." + name
555 return interface_to_import 555 return interface_to_import
556 556
557 def ImportedFrom(self): 557 def ImportedFrom(self):
558 interface_to_import = {} 558 interface_to_import = {}
559 for each_import in self.module.imports: 559 for each_import in self.module.imports:
560 for each_interface in each_import["module"].interfaces: 560 for each_interface in each_import["module"].interfaces:
561 name = each_interface.name 561 name = each_interface.name
562 interface_to_import[name] = each_import["unique_name"] + "." 562 interface_to_import[name] = each_import["unique_name"] + "."
563 return interface_to_import 563 return interface_to_import
OLDNEW
« no previous file with comments | « mojo/public/interfaces/bindings/tests/regression_tests.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698