GFramework/GFramework.SourceGenerators/Diagnostics/AutoRegisterModuleDiagnostics.cs
GeWuYou 62d448354c feat: 增强生成器属性参数校验与泛型约束支持,完善诊断体系
### 属性参数校验(Attribute Validation)
- AutoUiPageGenerator
  - 新增 GF_AutoBehavior_004 诊断:
    - 检测 AutoUiPageAttribute 参数无效情况
  - 添加测试用例验证错误参数的诊断报告

- AutoRegisterExportedCollectionsGenerator
  - 新增 GF_AutoExport_008 诊断:
    - 检测 RegisterExportedCollectionAttribute 参数无效情况
  - 改进 TryGetRegistrationAttributeArguments 方法:
    - 精确报告错误位置
  - 更新文档以包含新增诊断规则

### 泛型约束支持(Generic Constraints)
- AutoUiPageGenerator / AutoRegisterModuleGenerator
  - 支持以下泛型约束的正确生成:
    - class?
    - notnull
    - unmanaged
  - 添加对应测试用例确保生成正确性

### 诊断体系优化(Diagnostics Improvements)
- AutoRegisterModuleGenerator
  - 重构 AutoRegisterModuleDiagnostics:
    - 优化诊断定义顺序,提高可读性与维护性
2026-04-13 15:13:51 +08:00

49 lines
1.9 KiB
C#

using GFramework.SourceGenerators.Common.Constants;
namespace GFramework.SourceGenerators.Diagnostics;
internal static class AutoRegisterModuleDiagnostics
{
private const string Category = $"{PathContests.SourceGeneratorsPath}.Architecture";
public static readonly DiagnosticDescriptor NestedClassNotSupported = new(
"GF_AutoModule_001",
"AutoRegisterModule does not support nested classes",
"AutoRegisterModule does not support nested class '{0}'",
Category,
DiagnosticSeverity.Error,
true);
public static readonly DiagnosticDescriptor RegistrationTypeRequired = new(
"GF_AutoModule_002",
"Registration attribute requires a concrete type",
"Attribute '{0}' on '{1}' requires a concrete type argument",
Category,
DiagnosticSeverity.Error,
true);
public static readonly DiagnosticDescriptor RegistrationTypeMustImplementExpectedInterface = new(
"GF_AutoModule_003",
"Registration type does not implement the expected interface",
"Type '{0}' used by '{1}' must implement '{2}'",
Category,
DiagnosticSeverity.Error,
true);
public static readonly DiagnosticDescriptor RegistrationTypeMustHaveParameterlessConstructor = new(
"GF_AutoModule_004",
"Registration type must have an accessible parameterless constructor",
"Type '{0}' used by '{1}' must have an accessible parameterless constructor",
Category,
DiagnosticSeverity.Error,
true);
public static readonly DiagnosticDescriptor InstallMethodConflict = new(
"GF_AutoModule_005",
"Install method conflicts with generated code",
"Class '{0}' already defines 'Install(IArchitecture)', which conflicts with AutoRegisterModule generated code",
Category,
DiagnosticSeverity.Error,
true);
}