Code Duplication    Length = 53-53 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 3798-3850 (lines=53) @@
3795
    return True
3796
  return False
3797
3798
def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
3799
  """Checks for additional blank line issues related to sections.
3800
3801
  Currently the only thing checked here is blank line before protected/private.
3802
3803
  Args:
3804
    filename: The name of the current file.
3805
    clean_lines: A CleansedLines instance containing the file.
3806
    class_info: A _ClassInfo objects.
3807
    linenum: The number of the line to check.
3808
    error: The function to call with any errors found.
3809
  """
3810
  # Skip checks if the class is small, where small means 25 lines or less.
3811
  # 25 lines seems like a good cutoff since that's the usual height of
3812
  # terminals, and any class that can't fit in one screen can't really
3813
  # be considered "small".
3814
  #
3815
  # Also skip checks if we are on the first line.  This accounts for
3816
  # classes that look like
3817
  #   class Foo { public: ... };
3818
  #
3819
  # If we didn't find the end of the class, last_line would be zero,
3820
  # and the check will be skipped by the first condition.
3821
  if (class_info.last_line - class_info.starting_linenum <= 24 or
3822
      linenum <= class_info.starting_linenum):
3823
    return
3824
3825
  matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3826
  if matched:
3827
    # Issue warning if the line before public/protected/private was
3828
    # not a blank line, but don't do this if the previous line contains
3829
    # "class" or "struct".  This can happen two ways:
3830
    #  - We are at the beginning of the class.
3831
    #  - We are forward-declaring an inner class that is semantically
3832
    #    private, but needed to be public for implementation reasons.
3833
    # Also ignores cases where the previous line ends with a backslash as can be
3834
    # common when defining classes in C macros.
3835
    prev_line = clean_lines.lines[linenum - 1]
3836
    if (not IsBlankLine(prev_line) and
3837
        not Search(r'\b(class|struct)\b', prev_line) and
3838
        not Search(r'\\$', prev_line)):
3839
      # Try a bit harder to find the beginning of the class.  This is to
3840
      # account for multi-line base-specifier lists, e.g.:
3841
      #   class Derived
3842
      #       : public Base {
3843
      end_class_head = class_info.starting_linenum
3844
      for i in range(class_info.starting_linenum, linenum):
3845
        if Search(r'\{\s*$', clean_lines.lines[i]):
3846
          end_class_head = i
3847
          break
3848
      if end_class_head < linenum - 1:
3849
        error(filename, linenum, 'whitespace/blank_line', 3,
3850
              '"%s:" should be preceded by a blank line' % matched.group(1))
3851
3852
3853
def GetPreviousNonBlankLine(clean_lines, linenum):

core/build-support/cpplint.py 1 location

@@ 3798-3850 (lines=53) @@
3795
    return True
3796
  return False
3797
3798
def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
3799
  """Checks for additional blank line issues related to sections.
3800
3801
  Currently the only thing checked here is blank line before protected/private.
3802
3803
  Args:
3804
    filename: The name of the current file.
3805
    clean_lines: A CleansedLines instance containing the file.
3806
    class_info: A _ClassInfo objects.
3807
    linenum: The number of the line to check.
3808
    error: The function to call with any errors found.
3809
  """
3810
  # Skip checks if the class is small, where small means 25 lines or less.
3811
  # 25 lines seems like a good cutoff since that's the usual height of
3812
  # terminals, and any class that can't fit in one screen can't really
3813
  # be considered "small".
3814
  #
3815
  # Also skip checks if we are on the first line.  This accounts for
3816
  # classes that look like
3817
  #   class Foo { public: ... };
3818
  #
3819
  # If we didn't find the end of the class, last_line would be zero,
3820
  # and the check will be skipped by the first condition.
3821
  if (class_info.last_line - class_info.starting_linenum <= 24 or
3822
      linenum <= class_info.starting_linenum):
3823
    return
3824
3825
  matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3826
  if matched:
3827
    # Issue warning if the line before public/protected/private was
3828
    # not a blank line, but don't do this if the previous line contains
3829
    # "class" or "struct".  This can happen two ways:
3830
    #  - We are at the beginning of the class.
3831
    #  - We are forward-declaring an inner class that is semantically
3832
    #    private, but needed to be public for implementation reasons.
3833
    # Also ignores cases where the previous line ends with a backslash as can be
3834
    # common when defining classes in C macros.
3835
    prev_line = clean_lines.lines[linenum - 1]
3836
    if (not IsBlankLine(prev_line) and
3837
        not Search(r'\b(class|struct)\b', prev_line) and
3838
        not Search(r'\\$', prev_line)):
3839
      # Try a bit harder to find the beginning of the class.  This is to
3840
      # account for multi-line base-specifier lists, e.g.:
3841
      #   class Derived
3842
      #       : public Base {
3843
      end_class_head = class_info.starting_linenum
3844
      for i in range(class_info.starting_linenum, linenum):
3845
        if Search(r'\{\s*$', clean_lines.lines[i]):
3846
          end_class_head = i
3847
          break
3848
      if end_class_head < linenum - 1:
3849
        error(filename, linenum, 'whitespace/blank_line', 3,
3850
              '"%s:" should be preceded by a blank line' % matched.group(1))
3851
3852
3853
def GetPreviousNonBlankLine(clean_lines, linenum):