Stores information about a class.
| 2751 | |
| 2752 | |
| 2753 | class _ClassInfo(_BlockInfo): |
| 2754 | """Stores information about a class.""" |
| 2755 | |
| 2756 | def __init__(self, name, class_or_struct, clean_lines, linenum): |
| 2757 | _BlockInfo.__init__(self, linenum, False) |
| 2758 | self.name = name |
| 2759 | self.is_derived = False |
| 2760 | self.check_namespace_indentation = True |
| 2761 | if class_or_struct == 'struct': |
| 2762 | self.access = 'public' |
| 2763 | self.is_struct = True |
| 2764 | else: |
| 2765 | self.access = 'private' |
| 2766 | self.is_struct = False |
| 2767 | |
| 2768 | # Remember initial indentation level for this class. Using raw_lines here |
| 2769 | # instead of elided to account for leading comments. |
| 2770 | self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum]) |
| 2771 | |
| 2772 | # Try to find the end of the class. This will be confused by things like: |
| 2773 | # class A { |
| 2774 | # } *x = { ... |
| 2775 | # |
| 2776 | # But it's still good enough for CheckSectionSpacing. |
| 2777 | self.last_line = 0 |
| 2778 | depth = 0 |
| 2779 | for i in range(linenum, clean_lines.NumLines()): |
| 2780 | line = clean_lines.elided[i] |
| 2781 | depth += line.count('{') - line.count('}') |
| 2782 | if not depth: |
| 2783 | self.last_line = i |
| 2784 | break |
| 2785 | |
| 2786 | def CheckBegin(self, filename, clean_lines, linenum, error): |
| 2787 | # Look for a bare ':' |
| 2788 | if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]): |
| 2789 | self.is_derived = True |
| 2790 | |
| 2791 | def CheckEnd(self, filename, clean_lines, linenum, error): |
| 2792 | # If there is a DISALLOW macro, it should appear near the end of |
| 2793 | # the class. |
| 2794 | seen_last_thing_in_class = False |
| 2795 | for i in xrange(linenum - 1, self.starting_linenum, -1): |
| 2796 | match = Search( |
| 2797 | r'\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(' + |
| 2798 | self.name + r'\)', |
| 2799 | clean_lines.elided[i]) |
| 2800 | if match: |
| 2801 | if seen_last_thing_in_class: |
| 2802 | error(filename, i, 'readability/constructors', 3, |
| 2803 | match.group(1) + ' should be the last thing in the class') |
| 2804 | break |
| 2805 | |
| 2806 | if not Match(r'^\s*$', clean_lines.elided[i]): |
| 2807 | seen_last_thing_in_class = True |
| 2808 | |
| 2809 | # Check that closing brace is aligned with beginning of the class. |
| 2810 | # Only do this if the closing brace is indented by only whitespaces. |