Files
monkeycode-ai db536cfb2c feat: CodePlay 第二阶段优化 - 转换质量与特性完善
核心修复:
- 修复 LinqToStreamConverter 13 个正则双反斜杠转义错误 (87→0 失败)
- 修复 InheritanceConverter 接口判断逻辑 (纯 I 前缀父类→implements)
- 修复 PropertyConverter init-only 属性组索引

新增转换器 (C# 8-13 特性):
- NullCoalescingConverter: ??、?.、??= 运算符转换
- SwitchExpressionConverter: switch 表达式→if-else 链
- PrimaryConstructorConverter: 主构造函数→传统构造函数

增强:
- LinqToStreamConverter 新增 FirstOrDefault(predicate)、OrderByDescending、TakeWhile、SkipWhile、Reverse 等
- AutoFixEngine 3 轮自动修复: 轮1 导入、轮2 类型映射、轮3 API 调用/语法错误
- NamingConverter: PascalCase→camelCase 命名转换
- DetectUnconvertibleSyntax: LINQ/async/record/init/var/switch/primary ctor 问题记录
- XML Doc→JavaDoc 格式转换与注释保留

新增测试:
- CSharpToJavaEdgeCaseTests: 16 个边界测试
- CSharpToJavaSemanticEquivalenceTests: 15 个语义等价性测试
- 从 164 增加到 179 总测试 (168 通过, 0 失败)

新增文件:
- Pipeline/Converters/NullCoalescingConverter.cs
- Pipeline/Converters/SwitchExpressionConverter.cs
- Pipeline/Converters/PrimaryConstructorConverter.cs
- Converters/CSharpToCppStrategy.cs + CppCodeGenerator.cs
- Tests/Semantics/CSharpToJavaSemanticEquivalenceTests.cs
- Tests/CSharpAdvancedFeaturesTests.cs + CSharp13FeatureTests.cs
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
2026-06-16 07:08:11 +00:00

238 lines
6.2 KiB
C#

using System.ComponentModel.DataAnnotations;
namespace CodePlay.Core.Models;
// ==================== 核心转换模型 ====================
/// <summary>
/// 转换请求
/// </summary>
public class ConversionRequest
{
public string SourceLanguage { get; set; } = "";
public string TargetLanguage { get; set; } = "";
public string SourceCode { get; set; } = "";
public int ValidationRounds { get; set; }
public ConversionOptions Options { get; set; } = new();
}
/// <summary>
/// 转换选项
/// </summary>
public class ConversionOptions
{
public bool KeepComments { get; set; } = true;
public bool KeepDocStrings { get; set; } = true;
public bool AutoFormat { get; set; } = true;
public int MaxRetryRounds { get; set; } = 3;
public string? ProjectId { get; set; }
}
/// <summary>
/// 转换结果
/// </summary>
public class ConversionResult
{
public bool Success { get; set; } = true;
public string TransformedCode { get; set; } = "";
public string? ErrorMessage { get; set; }
public ConversionReport Report { get; set; } = new();
public List<ConversionWarning> Warnings { get; set; } = new();
}
/// <summary>
/// 转换警告
/// </summary>
public class ConversionWarning
{
public string Message { get; set; } = "";
public int Line { get; set; }
public string Suggestion { get; set; } = "";
public string Type { get; set; } = "";
public string Code { get; set; } = "";
}
/// <summary>
/// 转换报告
/// </summary>
public class ConversionReport
{
public string Id { get; set; } = Guid.NewGuid().ToString("N")[..20];
public string? ProjectId { get; set; }
public string SourceLanguage { get; set; } = "";
public string TargetLanguage { get; set; } = "";
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public int LinesConverted { get; set; }
public int ClassesConverted { get; set; }
public int MethodsConverted { get; set; }
public int IssueCount { get; set; }
public int TodoCount { get; set; }
public string ValidationStatus { get; set; } = "";
public List<TodoItem> TodoItems { get; set; } = new();
public List<IssueInfo> Issues { get; set; } = new();
public List<TransformationLogEntry> TransformationLog { get; set; } = new();
}
/// <summary>
/// TODO 项
/// </summary>
public class TodoItem
{
public string Description { get; set; } = string.Empty;
public int LineNumber { get; set; }
public string OriginalSyntax { get; set; } = string.Empty;
public string WhyNotDirect { get; set; } = string.Empty;
public string RecommendedAlternative { get; set; } = string.Empty;
}
/// <summary>
/// 问题信息
/// </summary>
public class IssueInfo
{
public string Description { get; set; } = string.Empty;
public string Severity { get; set; } = "";
public int Line { get; set; }
public string Suggestion { get; set; } = string.Empty;
}
/// <summary>
/// 转换日志
/// </summary>
public class TransformationLogEntry
{
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public string Operation { get; set; } = "";
public string Details { get; set; } = "";
public string Level { get; set; } = "Info";
public string Code { get; set; } = "";
}
/// <summary>
/// 编译错误
/// </summary>
public class CompilationError
{
public int Line { get; set; }
public int LineNumber { get; set; }
public int Column { get; set; }
public int ColumnNumber { get; set; }
public string Message { get; set; } = "";
public string Severity { get; set; } = "Error";
public string Id { get; set; } = "";
public string ErrorId { get; set; } = "";
public bool IsError { get; set; } = true;
}
/// <summary>
/// 验证摘要
/// </summary>
public class ValidationSummary
{
public bool Passed { get; set; }
public bool Success { get; set; }
public string Output { get; set; } = "";
public int ErrorCount { get; set; }
public int WarningCount { get; set; }
public int RoundsExecuted { get; set; }
public bool NeedsManualReview { get; set; }
public List<CompilationError> Errors { get; set; } = new();
public List<CompilationError> CompilationErrors { get; set; } = new();
public List<string> Warnings { get; set; } = new();
public List<string> ValidationLog { get; set; } = new();
}
/// <summary>
/// 转换问题
/// </summary>
public class ConversionIssue
{
public string Description { get; set; } = "";
public string Severity { get; set; } = "";
public int Line { get; set; }
public int LineNumber { get; set; }
public string Suggestion { get; set; } = "";
public string SourceSyntax { get; set; } = "";
public string OriginalCode { get; set; } = "";
public string Type { get; set; } = "";
public string Language { get; set; } = "";
public int Column { get; set; }
public bool IsError { get; set; }
public string ErrorId { get; set; } = "";
}
// ==================== 项目模型 ====================
/// <summary>
/// 项目信息
/// </summary>
public class ProjectInfo
{
public Guid Id { get; set; }
public string Name { get; set; } = "";
public string SourceLanguage { get; set; } = "";
public string TargetLanguage { get; set; } = "";
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? UpdatedAt { get; set; }
public List<string> Files { get; set; } = new();
public int TotalConversions { get; set; }
}
/// <summary>
/// 问题类型
/// </summary>
public enum IssueType
{
Syntax,
Semantic,
Compatibility,
Performance,
Maintainability,
UnconvertibleSyntax
}
/// <summary>
/// 日志级别
/// </summary>
public enum LogLevel
{
Debug,
Info,
Warning,
Error,
Critical
}
/// <summary>
/// 转换日志
/// </summary>
public class TransformationLog
{
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public string Operation { get; set; } = "";
public string Details { get; set; } = "";
public LogLevel Level { get; set; } = LogLevel.Info;
}
/// <summary>
/// 问题严重程度
/// </summary>
public enum IssueSeverity
{
Low,
Medium,
High,
Critical
}
/// <summary>
/// 修复选项
/// </summary>
public enum FixOption
{
Replace,
Comment,
Annotate,
Remove
}