2 changed files with 1 additions and 73 deletions
@ -1,72 +0,0 @@ |
|||||
#!/usr/bin/env python3 |
|
||||
# -*- coding: utf-8 -*- |
|
||||
""" |
|
||||
批量更新Java文件注释格式 |
|
||||
将所有@Author 1024创新实验室相关的注释统一改为 @Author wzh |
|
||||
""" |
|
||||
|
|
||||
import os |
|
||||
import re |
|
||||
from pathlib import Path |
|
||||
|
|
||||
def update_java_comments(file_path): |
|
||||
"""更新单个Java文件的注释""" |
|
||||
try: |
|
||||
with open(file_path, 'r', encoding='utf-8') as f: |
|
||||
content = f.read() |
|
||||
|
|
||||
# 匹配并替换注释块 |
|
||||
# 模式1: 多行注释包含 @Author 1024创新实验室... |
|
||||
pattern = r'/\*\*\s*\n(\s*\*.*?\n)*?\s*\*\s*@Author\s+1024创新实验室[^\n]*\n(\s*\*.*?\n)*?\s*\*/' |
|
||||
|
|
||||
def replace_comment(match): |
|
||||
comment_block = match.group(0) |
|
||||
|
|
||||
# 提取功能说明(第一行) |
|
||||
desc_match = re.search(r'/\*\*\s*\n\s*\*\s*(.+?)\s*\n', comment_block) |
|
||||
if not desc_match: |
|
||||
return comment_block |
|
||||
description = desc_match.group(1) |
|
||||
|
|
||||
# 提取@Date |
|
||||
date_match = re.search(r'\*\s*@Date\s+(.+?)\s*\n', comment_block) |
|
||||
if not date_match: |
|
||||
return comment_block |
|
||||
date_value = date_match.group(1) |
|
||||
|
|
||||
# 构建新的注释 |
|
||||
new_comment = f"/**\n * {description}\n *\n * @Date {date_value}\n * @Author wzh\n */" |
|
||||
return new_comment |
|
||||
|
|
||||
new_content = re.sub(pattern, replace_comment, content, flags=re.MULTILINE | re.DOTALL) |
|
||||
|
|
||||
if new_content != content: |
|
||||
with open(file_path, 'w', encoding='utf-8') as f: |
|
||||
f.write(new_content) |
|
||||
return True |
|
||||
return False |
|
||||
except Exception as e: |
|
||||
print(f"Error processing {file_path}: {e}") |
|
||||
return False |
|
||||
|
|
||||
def main(): |
|
||||
"""主函数""" |
|
||||
base_dir = Path('/Users/wang/wang/space/frameworkSpace/smart-flow-master/smart-flow-api') |
|
||||
|
|
||||
# 查找所有Java文件 |
|
||||
java_files = list(base_dir.rglob('*.java')) |
|
||||
|
|
||||
updated_count = 0 |
|
||||
total_count = len(java_files) |
|
||||
|
|
||||
print(f"Found {total_count} Java files") |
|
||||
|
|
||||
for i, java_file in enumerate(java_files, 1): |
|
||||
if update_java_comments(java_file): |
|
||||
updated_count += 1 |
|
||||
print(f"[{i}/{total_count}] Updated: {java_file.relative_to(base_dir)}") |
|
||||
|
|
||||
print(f"\nCompleted! Updated {updated_count} files out of {total_count}") |
|
||||
|
|
||||
if __name__ == '__main__': |
|
||||
main() |
|
||||
Loading…
Reference in new issue