diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py --- a/clang-tools-extra/clang-tidy/add_new_check.py +++ b/clang-tools-extra/clang-tidy/add_new_check.py @@ -165,31 +165,50 @@ header_added = False header_found = False check_added = False + check_fq_name = module + '-' + check_name check_decl = (' CheckFactories.registerCheck<' + check_name_camel + - '>(\n "' + module + '-' + check_name + '");\n') - - for line in lines: - if not header_added: - match = re.search('#include "(.*)"', line) - if match: - header_found = True - if match.group(1) > check_name_camel: + '>(\n "' + check_fq_name + '");\n') + + lines = iter(lines) + try: + while True: + line = lines.next() + if not header_added: + match = re.search('#include "(.*)"', line) + if match: + header_found = True + if match.group(1) > check_name_camel: + header_added = True + f.write('#include "' + check_name_camel + '.h"\n') + elif header_found: header_added = True f.write('#include "' + check_name_camel + '.h"\n') - elif header_found: - header_added = True - f.write('#include "' + check_name_camel + '.h"\n') - - if not check_added: - if line.strip() == '}': - check_added = True - f.write(check_decl) - else: - match = re.search('registerCheck<(.*)>', line) - if match and match.group(1) > check_name_camel: + + if not check_added: + if line.strip() == '}': check_added = True f.write(check_decl) - f.write(line) + else: + match = re.search('registerCheck<(.*)> *\( *(?:"([^"]*)")?', line) + prev_line = None + if match: + current_check_name = match.group(2) + if current_check_name is None: + # If we didn't find the check name on this line, look on the + # next one. + prev_line = line + line = lines.next() + match = re.search(' *"([^"]*)"', line) + if match: + current_check_name = match.group(1) + if current_check_name > check_fq_name: + check_added = True + f.write(check_decl) + if prev_line: + f.write(prev_line) + f.write(line) + except StopIteration: + pass # Adds a release notes entry.