Stores information about a class.
| 2265 | |
| 2266 | |
| 2267 | class _ClassInfo(_BlockInfo): |
| 2268 | """Stores information about a class.""" |
| 2269 | |
| 2270 | def __init__(self, name, class_or_struct, clean_lines, linenum): |
| 2271 | _BlockInfo.__init__(self, linenum, False) |
| 2272 | self.name = name |
| 2273 | self.is_derived = False |
| 2274 | self.check_namespace_indentation = True |
| 2275 | if class_or_struct == 'struct': |
| 2276 | self.access = 'public' |
| 2277 | self.is_struct = True |
| 2278 | else: |
| 2279 | self.access = 'private' |
| 2280 | self.is_struct = False |
| 2281 | |
| 2282 | # Remember initial indentation level for this class. Using raw_lines here |
| 2283 | # instead of elided to account for leading comments. |
| 2284 | self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum]) |
| 2285 | |
| 2286 | # Try to find the end of the class. This will be confused by things like: |
| 2287 | # class A { |
| 2288 | # } *x = { ... |
| 2289 | # |
| 2290 | # But it's still good enough for CheckSectionSpacing. |
| 2291 | self.last_line = 0 |
| 2292 | depth = 0 |
| 2293 | for i in range(linenum, clean_lines.NumLines()): |
| 2294 | line = clean_lines.elided[i] |
| 2295 | depth += line.count('{') - line.count('}') |
| 2296 | if not depth: |
| 2297 | self.last_line = i |
| 2298 | break |
| 2299 | |
| 2300 | def CheckBegin(self, filename, clean_lines, linenum, error): |
| 2301 | # Look for a bare ':' |
| 2302 | if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]): |
| 2303 | self.is_derived = True |
| 2304 | |
| 2305 | def CheckEnd(self, filename, clean_lines, linenum, error): |
| 2306 | # If there is a DISALLOW macro, it should appear near the end of |
| 2307 | # the class. |
| 2308 | seen_last_thing_in_class = False |
| 2309 | for i in xrange(linenum - 1, self.starting_linenum, -1): |
| 2310 | match = Search( |
| 2311 | r'\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(' + |
| 2312 | self.name + r'\)', |
| 2313 | clean_lines.elided[i]) |
| 2314 | if match: |
| 2315 | if seen_last_thing_in_class: |
| 2316 | error(filename, i, 'readability/constructors', 3, |
| 2317 | match.group(1) + ' should be the last thing in the class') |
| 2318 | break |
| 2319 | |
| 2320 | if not Match(r'^\s*$', clean_lines.elided[i]): |
| 2321 | seen_last_thing_in_class = True |
| 2322 | |
| 2323 | # Check that closing brace is aligned with beginning of the class. |
| 2324 | # Only do this if the closing brace is indented by only whitespaces. |