MCPcopy Create free account
hub / github.com/alibaba/graph-learn / _ClassInfo

Class _ClassInfo

dynamic_graph_service/ci/cpplint.py:2485–2551  ·  view source on GitHub ↗

Stores information about a class.

Source from the content-addressed store, hash-verified

2483
2484
2485class _ClassInfo(_BlockInfo):
2486 """Stores information about a class."""
2487
2488 def __init__(self, name, class_or_struct, clean_lines, linenum):
2489 _BlockInfo.__init__(self, linenum, False)
2490 self.name = name
2491 self.is_derived = False
2492 self.check_namespace_indentation = True
2493 if class_or_struct == 'struct':
2494 self.access = 'public'
2495 self.is_struct = True
2496 else:
2497 self.access = 'private'
2498 self.is_struct = False
2499
2500 # Remember initial indentation level for this class. Using raw_lines here
2501 # instead of elided to account for leading comments.
2502 self.class_indent = GetIndentLevel(clean_lines.raw_lines[linenum])
2503
2504 # Try to find the end of the class. This will be confused by things like:
2505 # class A {
2506 # } *x = { ...
2507 #
2508 # But it's still good enough for CheckSectionSpacing.
2509 self.last_line = 0
2510 depth = 0
2511 for i in range(linenum, clean_lines.NumLines()):
2512 line = clean_lines.elided[i]
2513 depth += line.count('{') - line.count('}')
2514 if not depth:
2515 self.last_line = i
2516 break
2517
2518 def CheckBegin(self, filename, clean_lines, linenum, error):
2519 # Look for a bare ':'
2520 if Search('(^|[^:]):($|[^:])', clean_lines.elided[linenum]):
2521 self.is_derived = True
2522
2523 def CheckEnd(self, filename, clean_lines, linenum, error):
2524 # If there is a DISALLOW macro, it should appear near the end of
2525 # the class.
2526 seen_last_thing_in_class = False
2527 for i in xrange(linenum - 1, self.starting_linenum, -1):
2528 match = Search(
2529 r'\b(DISALLOW_COPY_AND_ASSIGN|DISALLOW_IMPLICIT_CONSTRUCTORS)\(' +
2530 self.name + r'\)',
2531 clean_lines.elided[i])
2532 if match:
2533 if seen_last_thing_in_class:
2534 error(filename, i, 'readability/constructors', 3,
2535 match.group(1) + ' should be the last thing in the class')
2536 break
2537
2538 if not Match(r'^\s*$', clean_lines.elided[i]):
2539 seen_last_thing_in_class = True
2540
2541 # Check that closing brace is aligned with beginning of the class.
2542 # Only do this if the closing brace is indented by only whitespaces.

Callers 1

UpdateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected