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