feat: 实现 Blazor 前端界面 (Task 4.3) 和 CLI 工具 (Task 5.1)

Task 4.3 - Blazor 前端界面:
- 创建 CodePlay.WebUI Blazor Server 项目
- 实现 Converter.razor 代码转换页面
- 提供代码输入、语言选择、转换按钮
- 显示转换结果、TODO 列表和问题列表
- 更新导航菜单
- 注册 ConversionService 服务

Task 5.1 - CLI 命令行工具:
- 集成 System.CommandLine 库
- 实现 convert 命令(代码转换)
- 实现 list 命令(列出支持的转换)
- 实现 check 命令(检查是否支持)
- 支持 -s/-t 指定源/目标语言
- 支持 -i/-o 指定输入/输出文件
- 支持 -v 指定验证轮次
- 支持 -c 指定配置文件

测试:
- CLI help 命令: 
- CLI list 命令: 
- CLI convert 命令:  (成功转换 C# 到 Java)
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
This commit is contained in:
monkeycode-ai
2026-06-03 08:23:31 +00:00
parent c09982e252
commit 4ed56f46e2
28 changed files with 1113 additions and 324 deletions
-213
View File
@@ -1,213 +0,0 @@
using CodePlay.Core.Interfaces;
using CodePlay.Core.Models;
using CodePlay.Core.Common;
namespace CodePlay.Core.Validators;
/// <summary>
/// 自动修复引擎
/// </summary>
public class AutoFixEngine : IAutoFixEngine
{
/// <summary>
/// 尝试修复编译错误
/// </summary>
public Task<FixResult> FixAsync(string code, List<CompilationError> errors, int round, CancellationToken cancellationToken = default)
{
var result = new FixResult
{
CanFix = false,
RemainingErrors = new List<CompilationError>()
};
if (errors == null || errors.Count == 0)
{
result.CanFix = true;
result.FixedCode = code;
return Task.FromResult(result);
}
var fixedCode = code;
var remainingErrors = new List<CompilationError>();
switch (round)
{
case 1:
// 第 1 轮:修复导入/using 语句
result = FixRound1(code, errors);
break;
case 2:
// 第 2 轮:修复类型映射
result = FixRound2(code, errors);
break;
case 3:
// 第 3 轮:修复 API 调用
result = FixRound3(code, errors);
break;
default:
result.RemainingErrors = errors;
break;
}
return Task.FromResult(result);
}
/// <summary>
/// 第 1 轮:修复导入/using 语句
/// </summary>
private FixResult FixRound1(string code, List<CompilationError> errors)
{
var result = new FixResult
{
CanFix = false,
RemainingErrors = new List<CompilationError>()
};
var needsSystemUsing = false;
var needsCollectionsUsing = false;
var needsLinqUsing = false;
foreach (var error in errors)
{
if (error.ErrorId == "CS0246" || error.ErrorId == "CS0103")
{
// 类型或命名空间找不到
if (error.Message.Contains("Console"))
{
needsSystemUsing = true;
}
else if (error.Message.Contains("List") || error.Message.Contains("Dictionary"))
{
needsCollectionsUsing = true;
}
else if (error.Message.Contains("LINQ") || error.Message.Contains("var"))
{
needsLinqUsing = true;
}
else
{
result.RemainingErrors.Add(error);
}
}
else
{
result.RemainingErrors.Add(error);
}
}
// 添加缺失的 using
var fixedCode = code;
var fixDescription = new StringBuilder();
if (needsSystemUsing && !code.Contains("using System;"))
{
fixedCode = fixedCode.Insert(0, "using System;\n");
fixDescription.Append("Added using System; ");
}
if (needsCollectionsUsing && !code.Contains("using System.Collections.Generic;"))
{
fixedCode = fixedCode.Insert(0, "using System.Collections.Generic;\n");
fixDescription.Append("Added using System.Collections.Generic;");
}
if (needsLinqUsing && !code.Contains("using System.Linq;"))
{
fixedCode = fixedCode.Insert(0, "using System.Linq;\n");
fixDescription.Append("Added using System.Linq;");
}
if (fixDescription.Length > 0)
{
result.CanFix = true;
result.FixedCode = fixedCode;
result.FixDescription = fixDescription.ToString();
}
else
{
result.CanFix = false;
result.RemainingErrors = errors;
}
return result;
}
/// <summary>
/// 第 2 轮:修复类型映射
/// </summary>
private FixResult FixRound2(string code, List<CompilationError> errors)
{
var result = new FixResult
{
CanFix = false,
RemainingErrors = new List<CompilationError>()
};
var fixedCode = code;
var hasFixes = false;
foreach (var error in errors)
{
// Java 到 C# 的类型映射问题
if (error.ErrorId == "CS0246")
{
if (error.Message.Contains("String"))
{
fixedCode = fixedCode.Replace("String", "string");
hasFixes = true;
}
else if (error.Message.Contains("ArrayList"))
{
fixedCode = fixedCode.Replace("ArrayList", "List<object>");
hasFixes = true;
}
else if (error.Message.Contains("HashMap"))
{
fixedCode = fixedCode.Replace("HashMap", "Dictionary<object, object>");
hasFixes = true;
}
else
{
result.RemainingErrors.Add(error);
}
}
else
{
result.RemainingErrors.Add(error);
}
}
if (hasFixes)
{
result.CanFix = true;
result.FixedCode = fixedCode;
result.FixDescription = "Applied type mapping fixes";
}
else
{
result.RemainingErrors = errors;
}
return result;
}
/// <summary>
/// 第 3 轮:修复 API 调用
/// </summary>
private FixResult FixRound3(string code, List<CompilationError> errors)
{
var result = new FixResult
{
CanFix = false,
RemainingErrors = errors
};
// 这轮通常是复杂修复,MVP 版本暂不实现
// 可以考虑修复一些常见的 API 调用差异
return result;
}
}