Commit eab874da authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

Simplify name joining in make_computed_style_base.py.

Currently, when we wish to combine several strings together to form
the name for a class or data member for example, we have to use
join_name, which would combine the strings correctly in a space
separated format, followed by something like class_member_name that
formats the result into the correct style.

This patch allows things like class_member_name to take a list of
names, and join_name internally.

This does not change behaviour.

Bug: 628043
Change-Id: Iae966e45b9dc80a14bb57cf477af580fb64c85fc
Reviewed-on: https://chromium-review.googlesource.com/532676Reviewed-by: default avatarnainar <nainar@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487296}
parent 9526fcc7
......@@ -11,7 +11,7 @@ import make_style_builder
from name_utilities import (
enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, method_name,
class_name, join_name
class_name, join_names
)
from itertools import chain
......@@ -77,8 +77,8 @@ class Group(object):
self.fields = fields
self.parent = None
self.type_name = class_name(join_name('style', name, 'data'))
self.member_name = class_member_name(join_name(name, 'data'))
self.type_name = class_name(['style', name, 'data'])
self.member_name = class_member_name([name, 'data'])
self.num_32_bit_words_for_bit_fields = _num_32_bit_words_for_bit_fields(
field for field in fields if field.is_bit_field
)
......@@ -188,17 +188,17 @@ class Field(object):
self.is_independent = kwargs.pop('independent')
assert self.is_inherited or not self.is_independent, 'Only inherited fields can be independent'
self.is_inherited_method_name = method_name(join_name(name_for_methods, 'is inherited'))
self.is_inherited_method_name = method_name([name_for_methods, 'is inherited'])
# Method names
# TODO(nainar): Method name generation is inconsistent. Fix.
self.getter_method_name = getter_method_name
self.setter_method_name = setter_method_name
self.internal_getter_method_name = method_name(join_name(self.name, 'Internal'))
self.internal_mutable_method_name = method_name(join_name('Mutable', name_for_methods, 'Internal'))
self.internal_setter_method_name = method_name(join_name(setter_method_name, 'Internal'))
self.internal_getter_method_name = method_name([self.name, 'internal'])
self.internal_mutable_method_name = method_name(['mutable', name_for_methods, 'internal'])
self.internal_setter_method_name = method_name([setter_method_name, 'internal'])
self.initial_method_name = initial_method_name
self.resetter_method_name = method_name(join_name('Reset', name_for_methods))
self.resetter_method_name = method_name(['reset', name_for_methods])
self.default_generated_functions = default_generated_functions
# If the size of the field is not None, it means it is a bit field
self.is_bit_field = self.size is not None
......@@ -415,7 +415,7 @@ def _create_inherited_flag_field(property_):
Create the field used for an inheritance fast path from an independent CSS property,
and return the Field object.
"""
name_for_methods = join_name(property_['name_for_methods'], 'is inherited')
name_for_methods = join_names(property_['name_for_methods'], 'is', 'inherited')
return Field(
'inherited_flag',
name_for_methods,
......@@ -429,8 +429,8 @@ def _create_inherited_flag_field(property_):
custom_compare=False,
mutable=False,
getter_method_name=method_name(name_for_methods),
setter_method_name=method_name(join_name('set', name_for_methods)),
initial_method_name=method_name(join_name('initial', name_for_methods)),
setter_method_name=method_name(['set', name_for_methods]),
initial_method_name=method_name(['initial', name_for_methods]),
default_generated_functions=property_["default_generated_functions"]
)
......
......@@ -132,45 +132,68 @@ def split_name(name):
upper_first_letter(name))
def upper_camel_case(name):
return ''.join(upper_first_letter(word) for word in split_name(name))
def join_names(*names):
"""Given a list of names, join them into a single space-separated name."""
result = []
for name in names:
result.extend(split_name(name))
return ' '.join(result)
def lower_camel_case(name):
return lower_first_letter(upper_camel_case(name))
def naming_style(f):
"""Decorator for name utility functions.
Wraps a name utility function in a function that takes one or more names,
splits them into a list of words, and passes the list to the utility function.
"""
def inner(name_or_names):
names = name_or_names if isinstance(name_or_names, list) else [name_or_names]
words = []
for name in names:
words.extend(split_name(name))
return f(words)
return inner
def snake_case(name):
return '_'.join(word.lower() for word in split_name(name))
@naming_style
def upper_camel_case(words):
return ''.join(upper_first_letter(word) for word in words)
# Use these high level naming functions which describe the semantics of the name,
# rather than a particular style.
@naming_style
def lower_camel_case(words):
return lower_first_letter(upper_camel_case(words))
def enum_type_name(name):
return upper_camel_case(name)
@naming_style
def snake_case(words):
return '_'.join(word.lower() for word in words)
def enum_value_name(name):
return 'k' + upper_camel_case(name)
# Use these high level naming functions which describe the semantics of the name,
# rather than a particular style.
def class_name(name):
return upper_camel_case(name)
@naming_style
def enum_type_name(words):
return upper_camel_case(words)
def class_member_name(name):
return snake_case(name) + "_"
@naming_style
def enum_value_name(words):
return 'k' + upper_camel_case(words)
def method_name(name):
return upper_camel_case(name)
@naming_style
def class_name(words):
return upper_camel_case(words)
def join_name(*names):
"""Given a list of names, join them into a single space-separated name."""
result = []
for name in names:
result.extend(split_name(name))
return ' '.join(result)
@naming_style
def class_member_name(words):
return snake_case(words) + "_"
@naming_style
def method_name(words):
return upper_camel_case(words)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment