Files
java-10561/docs/clean_duplicate_imports.sh
2025-09-06 11:58:18 +08:00

42 lines
1.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 清理重复的LocalDateTime导入
echo "开始清理重复的LocalDateTime导入..."
# 获取所有包含重复LocalDateTime导入的Java文件
files=$(find src/main/java -name "*.java" -exec grep -l "import java.time.LocalDateTime" {} \;)
for file in $files; do
echo "检查文件: $file"
# 检查是否有重复的LocalDateTime导入
count=$(grep -c "import java.time.LocalDateTime" "$file")
if [ "$count" -gt 1 ]; then
echo "发现重复导入,正在修复: $file"
# 创建临时文件
temp_file=$(mktemp)
# 移除重复的LocalDateTime导入只保留第一个
awk '
/import java\.time\.LocalDateTime/ {
if (!seen) {
print
seen = 1
}
next
}
{ print }
' "$file" > "$temp_file"
# 替换原文件
mv "$temp_file" "$file"
echo "修复完成: $file"
fi
done
echo "清理重复导入完成!"