feat: 实现 Task 3.2 Java 编译验证和 Task 4.4 前端代码编辑器
Task 3.2 - Java 编译验证: - JavaCompilerValidator: 使用 javac 进行编译验证 - 支持临时文件编译和清理 - 集成到 ICompilerValidator 接口 - 单元测试 (需要 javac 环境) Task 4.4 - 前端代码编辑器: - CodeEditor.vue: Monaco Editor 集成 - 支持 C#/Java/C++ 语法高亮 - 智能代码补全 (main 方法,System.out.println 等) - 支持主题切换 (vs-dark/vs/hc-black) - 支持只读模式、最小化地图、自动布局 - 暴露 API: setValue, getValue, focus, layout 测试状态: - 总测试数: 42 - 通过: 41 ✅ - 跳过: 1 (Java 编译器测试需要 javac 环境) 前端依赖: - 需安装 monaco-editor: npm install monaco-editor Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
This commit is contained in:
@@ -3,447 +3,99 @@ using CodePlay.Core.Common;
|
||||
|
||||
namespace CodePlay.Core.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// 语言解析器接口
|
||||
/// </summary>
|
||||
public interface IParser
|
||||
{
|
||||
/// <summary>
|
||||
/// 解析源代码并生成 AST
|
||||
/// </summary>
|
||||
/// <param name="sourceCode">源代码</param>
|
||||
/// <param name="cancellationToken">取消令牌</param>
|
||||
/// <returns>语法树</returns>
|
||||
Task<SyntaxTree> ParseAsync(string sourceCode, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码转换器接口
|
||||
/// </summary>
|
||||
public interface IConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// 转换语法树
|
||||
/// </summary>
|
||||
/// <param name="syntaxTree">源语言语法树</param>
|
||||
/// <param name="targetLanguage">目标语言</param>
|
||||
/// <param name="options">转换选项</param>
|
||||
/// <param name="cancellationToken">取消令牌</param>
|
||||
/// <returns>转换结果</returns>
|
||||
Task<ConversionResult> ConvertAsync(SyntaxTree syntaxTree, LanguageType targetLanguage, ConversionOptions? options = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器接口
|
||||
/// </summary>
|
||||
public interface ICodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 从语法树生成代码
|
||||
/// </summary>
|
||||
/// <param name="syntaxTree">语法树</param>
|
||||
/// <returns>生成的代码</returns>
|
||||
string Generate(SyntaxTree syntaxTree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编译验证器接口
|
||||
/// </summary>
|
||||
public interface ICompilerValidator
|
||||
{
|
||||
/// <summary>
|
||||
/// 编译并验证代码
|
||||
/// </summary>
|
||||
/// <param name="code">代码</param>
|
||||
/// <param name="language">语言类型</param>
|
||||
/// <param name="cancellationToken">取消令牌</param>
|
||||
/// <returns>验证结果</returns>
|
||||
Task<ValidationResult> ValidateAsync(string code, LanguageType language, CancellationToken cancellationToken = default);
|
||||
Task<ValidationSummary> ValidateAsync(string code, LanguageType targetLanguage, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动修复引擎接口
|
||||
/// </summary>
|
||||
public interface IAutoFixEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 尝试修复编译错误
|
||||
/// </summary>
|
||||
/// <param name="code">代码</param>
|
||||
/// <param name="errors">编译错误列表</param>
|
||||
/// <param name="round">当前修复轮次</param>
|
||||
/// <param name="cancellationToken">取消令牌</param>
|
||||
/// <returns>修复结果</returns>
|
||||
Task<FixResult> FixAsync(string code, List<CompilationError> errors, int round, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换策略接口
|
||||
/// </summary>
|
||||
public interface IConversionStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 源语言
|
||||
/// </summary>
|
||||
LanguageType SourceLanguage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 目标语言
|
||||
/// </summary>
|
||||
LanguageType TargetLanguage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 转换语法节点
|
||||
/// </summary>
|
||||
/// <param name="node">语法节点</param>
|
||||
/// <param name="context">转换上下文</param>
|
||||
/// <returns>转换后的节点</returns>
|
||||
SyntaxNode ConvertNode(SyntaxNode node, ConversionContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 映射类型
|
||||
/// </summary>
|
||||
/// <param name="sourceType">源类型名称</param>
|
||||
/// <returns>目标类型名称</returns>
|
||||
string MapType(string sourceType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 语法树
|
||||
/// </summary>
|
||||
public class SyntaxTree
|
||||
{
|
||||
/// <summary>
|
||||
/// 语言类型
|
||||
/// </summary>
|
||||
public class SyntaxTree {
|
||||
public LanguageType Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根节点
|
||||
/// </summary>
|
||||
public SyntaxNode Root { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 源文件路径
|
||||
/// </summary>
|
||||
public string? SourceFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 原始源代码
|
||||
/// </summary>
|
||||
public string? SourceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注释列表
|
||||
/// </summary>
|
||||
public List<SyntaxComment> Comments { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 文档字符串列表
|
||||
/// </summary>
|
||||
public List<SyntaxDocumentation> Documentation { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 语法节点
|
||||
/// </summary>
|
||||
public class SyntaxNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点类型
|
||||
/// </summary>
|
||||
public class SyntaxNode {
|
||||
public SyntaxNodeType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点文本
|
||||
/// </summary>
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 子节点列表
|
||||
/// </summary>
|
||||
public List<SyntaxNode> Children { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 元数据
|
||||
/// </summary>
|
||||
public Dictionary<string, object?> Metadata { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 父节点
|
||||
/// </summary>
|
||||
public SyntaxNode? Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为不可转换语法
|
||||
/// </summary>
|
||||
public bool IsUnconvertible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TODO 说明(当 IsUnconvertible 为 true 时)
|
||||
/// </summary>
|
||||
public string? TodoDescription { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 语法节点类型
|
||||
/// </summary>
|
||||
public enum SyntaxNodeType
|
||||
{
|
||||
/// <summary>
|
||||
/// 未知
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 编译单元
|
||||
/// </summary>
|
||||
CompilationUnit = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 命名空间
|
||||
/// </summary>
|
||||
Namespace = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 类
|
||||
/// </summary>
|
||||
Class = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 接口
|
||||
/// </summary>
|
||||
Interface = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 方法
|
||||
/// </summary>
|
||||
Method = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
Property = 6,
|
||||
|
||||
/// <summary>
|
||||
/// 字段
|
||||
/// </summary>
|
||||
Field = 7,
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
Constructor = 8,
|
||||
|
||||
/// <summary>
|
||||
/// 语句
|
||||
/// </summary>
|
||||
Statement = 9,
|
||||
|
||||
/// <summary>
|
||||
/// 表达式
|
||||
/// </summary>
|
||||
Expression = 10,
|
||||
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// </summary>
|
||||
Type = 11,
|
||||
|
||||
/// <summary>
|
||||
/// 参数
|
||||
/// </summary>
|
||||
Parameter = 12,
|
||||
|
||||
/// <summary>
|
||||
/// 注释
|
||||
/// </summary>
|
||||
Comment = 13,
|
||||
|
||||
/// <summary>
|
||||
/// 文档注释
|
||||
/// </summary>
|
||||
DocumentationComment = 14
|
||||
public enum SyntaxNodeType {
|
||||
Unknown = 0, CompilationUnit = 1, Namespace = 2, Class = 3, Interface = 4,
|
||||
Method = 5, Property = 6, Field = 7, Constructor = 8, Statement = 9,
|
||||
Expression = 10, Type = 11, Parameter = 12, Comment = 13, DocumentationComment = 14
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 语法注释
|
||||
/// </summary>
|
||||
public class SyntaxComment
|
||||
{
|
||||
/// <summary>
|
||||
/// 注释类型
|
||||
/// </summary>
|
||||
public class SyntaxComment {
|
||||
public CommentType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注释文本
|
||||
/// </summary>
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
public int LineNumber { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注释类型
|
||||
/// </summary>
|
||||
public enum CommentType
|
||||
{
|
||||
/// <summary>
|
||||
/// 单行注释 //
|
||||
/// </summary>
|
||||
SingleLine = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 多行注释 /* */
|
||||
/// </summary>
|
||||
MultiLine = 1,
|
||||
|
||||
/// <summary>
|
||||
/// XML 文档注释 ///
|
||||
/// </summary>
|
||||
XmlDoc = 2,
|
||||
|
||||
/// <summary>
|
||||
/// JavaDoc /** */
|
||||
/// </summary>
|
||||
JavaDoc = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Doxygen /// 或 /** */
|
||||
/// </summary>
|
||||
Doxygen = 4
|
||||
}
|
||||
public enum CommentType { SingleLine = 0, MultiLine = 1, XmlDoc = 2, JavaDoc = 3, Doxygen = 4 }
|
||||
|
||||
/// <summary>
|
||||
/// 语法文档
|
||||
/// </summary>
|
||||
public class SyntaxDocumentation
|
||||
{
|
||||
/// <summary>
|
||||
/// 文档所属元素
|
||||
/// </summary>
|
||||
public class SyntaxDocumentation {
|
||||
public string ElementName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 文档内容
|
||||
/// </summary>
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 文档格式
|
||||
/// </summary>
|
||||
public DocFormat Format { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文档格式
|
||||
/// </summary>
|
||||
public enum DocFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// XML Doc (C#)
|
||||
/// </summary>
|
||||
XmlDoc = 0,
|
||||
|
||||
/// <summary>
|
||||
/// JavaDoc (Java)
|
||||
/// </summary>
|
||||
JavaDoc = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Doxygen (C++)
|
||||
/// </summary>
|
||||
Doxygen = 2
|
||||
}
|
||||
public enum DocFormat { XmlDoc = 0, JavaDoc = 1, Doxygen = 2 }
|
||||
|
||||
/// <summary>
|
||||
/// 转换上下文
|
||||
/// </summary>
|
||||
public class ConversionContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 源语言
|
||||
/// </summary>
|
||||
public class ConversionContext {
|
||||
public LanguageType SourceLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 目标语言
|
||||
/// </summary>
|
||||
public LanguageType TargetLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 转换选项
|
||||
/// </summary>
|
||||
public ConversionOptions? Options { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 问题列表
|
||||
/// </summary>
|
||||
public List<ConversionIssue> Issues { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// TODO 列表
|
||||
/// </summary>
|
||||
public List<TodoItem> TodoItems { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 转换日志
|
||||
/// </summary>
|
||||
public List<TransformationLog> Logs { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复结果
|
||||
/// </summary>
|
||||
public class FixResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否可以修复
|
||||
/// </summary>
|
||||
public class FixResult {
|
||||
public bool CanFix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修复后的代码
|
||||
/// </summary>
|
||||
public string? FixedCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修复说明
|
||||
/// </summary>
|
||||
public string? FixDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余错误列表
|
||||
/// </summary>
|
||||
public List<CompilationError> RemainingErrors { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编译验证结果
|
||||
/// </summary>
|
||||
public class CompilationResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public class CompilationResult {
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 编译输出
|
||||
/// </summary>
|
||||
public string Output { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 错误列表
|
||||
/// </summary>
|
||||
public List<CompilationError> Errors { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 警告列表
|
||||
/// </summary>
|
||||
public List<CompilationError> Warnings { get; set; } = new();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user