4c94bdf666
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>
102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using CodePlay.Core.Models;
|
|
using CodePlay.Core.Common;
|
|
|
|
namespace CodePlay.Core.Interfaces;
|
|
|
|
public interface IParser
|
|
{
|
|
Task<SyntaxTree> ParseAsync(string sourceCode, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public interface IConverter
|
|
{
|
|
Task<ConversionResult> ConvertAsync(SyntaxTree syntaxTree, LanguageType targetLanguage, ConversionOptions? options = null, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public interface ICodeGenerator
|
|
{
|
|
string Generate(SyntaxTree syntaxTree);
|
|
}
|
|
|
|
public interface ICompilerValidator
|
|
{
|
|
Task<ValidationSummary> ValidateAsync(string code, LanguageType targetLanguage, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public interface IAutoFixEngine
|
|
{
|
|
Task<FixResult> FixAsync(string code, List<CompilationError> errors, int round, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public interface IConversionStrategy
|
|
{
|
|
LanguageType SourceLanguage { get; }
|
|
LanguageType TargetLanguage { get; }
|
|
SyntaxNode ConvertNode(SyntaxNode node, ConversionContext context);
|
|
string MapType(string sourceType);
|
|
}
|
|
|
|
public class SyntaxTree {
|
|
public LanguageType Language { get; set; }
|
|
public SyntaxNode Root { get; set; } = new();
|
|
public string? SourceFilePath { get; set; }
|
|
public string? SourceCode { get; set; }
|
|
public List<SyntaxComment> Comments { get; set; } = new();
|
|
public List<SyntaxDocumentation> Documentation { get; set; } = new();
|
|
}
|
|
|
|
public class SyntaxNode {
|
|
public SyntaxNodeType Type { get; set; }
|
|
public string Text { get; set; } = string.Empty;
|
|
public List<SyntaxNode> Children { get; set; } = new();
|
|
public Dictionary<string, object?> Metadata { get; set; } = new();
|
|
public SyntaxNode? Parent { get; set; }
|
|
public bool IsUnconvertible { get; set; }
|
|
public string? TodoDescription { get; set; }
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
public class SyntaxComment {
|
|
public CommentType Type { get; set; }
|
|
public string Text { get; set; } = string.Empty;
|
|
public int LineNumber { get; set; }
|
|
}
|
|
|
|
public enum CommentType { SingleLine = 0, MultiLine = 1, XmlDoc = 2, JavaDoc = 3, Doxygen = 4 }
|
|
|
|
public class SyntaxDocumentation {
|
|
public string ElementName { get; set; } = string.Empty;
|
|
public string Content { get; set; } = string.Empty;
|
|
public DocFormat Format { get; set; }
|
|
}
|
|
|
|
public enum DocFormat { XmlDoc = 0, JavaDoc = 1, Doxygen = 2 }
|
|
|
|
public class ConversionContext {
|
|
public LanguageType SourceLanguage { get; set; }
|
|
public LanguageType TargetLanguage { get; set; }
|
|
public ConversionOptions? Options { get; set; }
|
|
public List<ConversionIssue> Issues { get; set; } = new();
|
|
public List<TodoItem> TodoItems { get; set; } = new();
|
|
public List<TransformationLog> Logs { get; set; } = new();
|
|
}
|
|
|
|
public class FixResult {
|
|
public bool CanFix { get; set; }
|
|
public string? FixedCode { get; set; }
|
|
public string? FixDescription { get; set; }
|
|
public List<CompilationError> RemainingErrors { get; set; } = new();
|
|
}
|
|
|
|
public class CompilationResult {
|
|
public bool Success { get; set; }
|
|
public string Output { get; set; } = string.Empty;
|
|
public List<CompilationError> Errors { get; set; } = new();
|
|
public List<CompilationError> Warnings { get; set; } = new();
|
|
}
|