GeWuYou 80acf84e95 feat(godot): 添加AutoScene和AutoRegisterExportedCollections源代码生成器
- 实现AutoSceneGenerator为标记了[AutoScene]特性的Godot节点生成场景行为样板代码
- 实现AutoRegisterExportedCollectionsGenerator为导出集合生成批量注册样板方法
- 添加AutoBehaviorDiagnostics和AutoRegisterExportedCollectionsDiagnostics诊断描述符
- 创建AnalyzerReleases.Unshipped.md文件跟踪新的分析器规则
- 添加完整的单元测试覆盖两个生成器的功能和错误情况
- 更新.gitignore文件排除dotnet-home和脚本缓存目录
2026-04-13 10:51:40 +08:00

60 lines
2.2 KiB
C#

using GFramework.SourceGenerators.Common.Constants;
namespace GFramework.Godot.SourceGenerators.Diagnostics;
/// <summary>
/// 定义行为类自动生成器使用的诊断描述符。
/// </summary>
/// <remarks>
/// 这些规则覆盖 <c>AutoScene</c> 与 <c>AutoUiPage</c> 等行为生成器的常见使用约束,
/// 以便在生成被跳过前向调用方报告明确的失败原因。
/// </remarks>
internal static class AutoBehaviorDiagnostics
{
private const string Category = $"{PathContests.GodotNamespace}.SourceGenerators.Behavior";
/// <summary>
/// 报告行为生成器不支持在嵌套类型上运行。
/// </summary>
public static readonly DiagnosticDescriptor NestedClassNotSupported = new(
"GF_AutoBehavior_001",
"Auto behavior generators do not support nested classes",
"Generator '{0}' does not support nested class '{1}'",
Category,
DiagnosticSeverity.Error,
true);
/// <summary>
/// 报告目标类型没有继承生成器要求的 Godot 基类。
/// </summary>
public static readonly DiagnosticDescriptor MissingBaseType = new(
"GF_AutoBehavior_002",
"Auto behavior generators require a compatible base type",
"Type '{0}' must inherit from '{1}' to use '{2}'",
Category,
DiagnosticSeverity.Error,
true);
/// <summary>
/// 报告 UI 页面声明中使用了不存在的 <c>UiLayer</c> 名称。
/// </summary>
public static readonly DiagnosticDescriptor InvalidUiLayerName = new(
"GF_AutoBehavior_003",
"Unknown UiLayer name",
"Ui layer '{0}' on '{1}' does not exist on GFramework.Game.Abstractions.Enums.UiLayer",
Category,
DiagnosticSeverity.Error,
true);
/// <summary>
/// 报告行为生成器特性参数不满足约定签名,导致生成器无法推导所需元数据。
/// </summary>
public static readonly DiagnosticDescriptor InvalidAttributeArguments = new(
"GF_AutoBehavior_004",
"Auto behavior attribute arguments are invalid",
"Attribute '{0}' on '{1}' must provide {2}",
Category,
DiagnosticSeverity.Error,
true);
}