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

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_style_builder.py

Issue 2811253002: Extract default naming logic in StyleBuilderWriter to a method. (Closed)
Patch Set: Rebase Created 3 years, 8 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 import sys 30 import sys
31 31
32 import css_properties 32 import css_properties
33 import json5_generator 33 import json5_generator
34 from name_utilities import lower_first 34 from name_utilities import lower_first, upper_camel_case
35 import template_expander 35 import template_expander
36 36
37 37
38 class StyleBuilderWriter(css_properties.CSSProperties): 38 class StyleBuilderWriter(css_properties.CSSProperties):
39 filters = { 39 filters = {
40 'lower_first': lower_first, 40 'lower_first': lower_first,
41 } 41 }
42 42
43 def __init__(self, json5_file_path): 43 def __init__(self, json5_file_path):
44 super(StyleBuilderWriter, self).__init__(json5_file_path) 44 super(StyleBuilderWriter, self).__init__(json5_file_path)
45 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h, 45 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h,
46 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp, 46 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp,
47 ('StyleBuilder.cpp'): self.generate_style_builder, 47 ('StyleBuilder.cpp'): self.generate_style_builder,
48 } 48 }
49 49
50 def set_if_none(property, key, value): 50 for property in self._properties.values():
51 if property[key] is None: 51 self._apply_property_naming_defaults(property)
52 property[key] = value
53 52
54 for property in self._properties.values(): 53 def _apply_property_naming_defaults(self, property_):
alancutter (OOO until 2018) 2017/04/19 04:36:35 self is unused, make this a static method or utili
shend 2017/04/19 05:26:05 Done.
55 upper_camel = property['upper_camel_name'] 54 def set_if_none(property_, key, value):
56 set_if_none(property, 'name_for_methods', upper_camel.replace('Webki t', '')) 55 if property_[key] is None:
57 name = property['name_for_methods'] 56 property_[key] = value
58 simple_type_name = str(property['type_name']).split('::')[-1] 57
59 set_if_none(property, 'type_name', 'E' + name) 58 # TODO(shend): Use name_utilities for manipulating names.
60 set_if_none(property, 'getter', name if simple_type_name != name els e 'Get' + name) 59 upper_camel = upper_camel_case(property_['name'])
61 set_if_none(property, 'setter', 'Set' + name) 60 set_if_none(property_, 'name_for_methods', upper_camel.replace('Webkit', ''))
62 set_if_none(property, 'inherited', False) 61 name = property_['name_for_methods']
63 set_if_none(property, 'initial', 'Initial' + name) 62 simple_type_name = str(property_['type_name']).split('::')[-1]
64 if property['custom_all']: 63 set_if_none(property_, 'type_name', 'E' + name)
65 property['custom_initial'] = True 64 set_if_none(property_, 'getter', name if simple_type_name != name else ' Get' + name)
66 property['custom_inherit'] = True 65 set_if_none(property_, 'setter', 'Set' + name)
67 property['custom_value'] = True 66 set_if_none(property_, 'inherited', False)
68 if property['inherited']: 67 set_if_none(property_, 'initial', 'Initial' + name)
69 property['is_inherited_setter'] = 'Set' + name + 'IsInherited' 68
70 property['should_declare_functions'] = not property['use_handlers_fo r'] and not property['longhands'] \ 69 if property_['custom_all']:
71 and not property['direction_aware'] and not property['builder_sk ip'] \ 70 property_['custom_initial'] = True
72 and property['is_property'] 71 property_['custom_inherit'] = True
72 property_['custom_value'] = True
73 if property_['inherited']:
74 property_['is_inherited_setter'] = 'Set' + name + 'IsInherited'
75 property_['should_declare_functions'] = not property_['use_handlers_for' ] and not property_['longhands'] \
76 and not property_['direction_aware'] and not property_['builder_skip '] \
77 and property_['is_property']
73 78
74 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', 79 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
75 filters=filters) 80 filters=filters)
76 def generate_style_builder_functions_h(self): 81 def generate_style_builder_functions_h(self):
77 return { 82 return {
78 'properties': self._properties, 83 'properties': self._properties,
79 } 84 }
80 85
81 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', 86 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
82 filters=filters) 87 filters=filters)
83 def generate_style_builder_functions_cpp(self): 88 def generate_style_builder_functions_cpp(self):
84 return { 89 return {
85 'properties': self._properties, 90 'properties': self._properties,
86 } 91 }
87 92
88 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) 93 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
89 def generate_style_builder(self): 94 def generate_style_builder(self):
90 return { 95 return {
91 'properties': self._properties, 96 'properties': self._properties,
92 } 97 }
93 98
94 99
95 if __name__ == '__main__': 100 if __name__ == '__main__':
96 json5_generator.Maker(StyleBuilderWriter).main() 101 json5_generator.Maker(StyleBuilderWriter).main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698