tools/android/checkxmlstyle/checkxmlstyle.py
def _CheckColorPaletteReferences(input_api, output_api):
  """
  Checks colors defined in color_palette.xml are not references in colors.xml.
  """
  warnings = []
  color_palette = None

  for f in IncludedFiles(input_api):
    if not f.LocalPath().endswith('/colors.xml'):
      continue

    if color_palette is None:
      color_palette = _colorXml2Dict(
          input_api.ReadFile(helpers.COLOR_PALETTE_PATH))
    for line_number, line in f.ChangedContents():
      r = helpers.COLOR_REFERENCE_PATTERN.search(line)
      if not r:
        continue
      color = r.group()
      if _removePrefix(color) in color_palette:
        warnings.append(
            '  %s:%d\n    \t%s' % (f.LocalPath(), line_number, line.strip()))

  if warnings:
    return [
        output_api.PresubmitPromptWarning(
            '''
  Android Color Palette Reference Check warning:
    Your new color values added in colors.xml are defined in color_palette.xml.

    We can recommend using semantic colors already defined in
    ui/android/java/res/values/semantic_colors_non_adaptive.xml
    or ui/android/java/res/values/semantic_colors_adaptive.xml if possible.

    See https://crbug.com/775198 for more information.
  ''', warnings)
    ]
  return []

  Checks colors defined in color_palette.xml are not references in colors.xml.
  
Checks colors defined in color_palette.xml are not references in colors.xml.
Checks colors defined in color_palette . xml are not references in colors . xml .
def _CheckColorPaletteReferences(input_api, output_api):
  warnings = []
  color_palette = None
  for f in IncludedFiles(input_api):
    if not f.LocalPath().endswith('/colors.xml'):
      continue
    if color_palette is None:
      color_palette = _colorXml2Dict(
          input_api.ReadFile(helpers.COLOR_PALETTE_PATH))
    for line_number, line in f.ChangedContents():
      r = helpers.COLOR_REFERENCE_PATTERN.search(line)
      if not r:
        continue
      color = r.group()
      if _removePrefix(color) in color_palette:
        warnings.append(
            '  %s:%d\n    \t%s' % (f.LocalPath(), line_number, line.strip()))
  if warnings:
    return [
        output_api.PresubmitPromptWarning(
            '''
  Android Color Palette Reference Check warning:
    Your new color values added in colors.xml are defined in color_palette.xml.
    We can recommend using semantic colors already defined in
    ui/android/java/res/values/semantic_colors_non_adaptive.xml
    or ui/android/java/res/values/semantic_colors_adaptive.xml if possible.
    See https://crbug.com/775198 for more information.
  ''', warnings)
    ]
  return []
def _CheckColorPaletteReferences ( input_api , output_api ) : warnings = [ ] color_palette = None for f in IncludedFiles ( input_api ) : if not f . LocalPath ( ) . endswith ( '/colors.xml' ) : continue if color_palette is None : color_palette = _colorXml2Dict ( input_api . ReadFile ( helpers . COLOR_PALETTE_PATH ) ) for line_number , line in f . ChangedContents ( ) : r = helpers . COLOR_REFERENCE_PATTERN . search ( line ) if not r : continue color = r . group ( ) if _removePrefix ( color ) in color_palette : warnings . append ( '  %s:%d\n    \t%s' % ( f . LocalPath ( ) , line_number , line . strip ( ) ) ) if warnings : return [ output_api . PresubmitPromptWarning ( '''
  Android Color Palette Reference Check warning:
    Your new color values added in colors.xml are defined in color_palette.xml.

    We can recommend using semantic colors already defined in
    ui/android/java/res/values/semantic_colors_non_adaptive.xml
    or ui/android/java/res/values/semantic_colors_adaptive.xml if possible.

    See https://crbug.com/775198 for more information.
  ''' , warnings ) ] return [ ]
Checks colors defined in color_palette.xml are not references in colors.xml.
Checks colors defined in color_palette . xml are not references in colors . xml .
"""
  Checks colors defined in color_palette.xml are not references in colors.xml.
  """
input_api
output_api