From 7ec2185ae035f99f9da6f63aa4a6d38387d989bb Mon Sep 17 00:00:00 2001
From: gewuyou <95328647+GeWuYou@users.noreply.github.com>
Date: Wed, 22 Apr 2026 09:20:00 +0800
Subject: [PATCH] =?UTF-8?q?refactor(source-generators):=20=E6=8B=86?=
=?UTF-8?q?=E5=88=86=E4=B8=8A=E4=B8=8B=E6=96=87=E6=84=9F=E7=9F=A5=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 重构 ContextAwareGenerator 的上下文属性生成流程,降低 MA0051 复杂度
- 补充 analyzer warning reduction 的 RP-017 恢复记录与验证结果
- 更新 下一步 MA0158 多目标兼容性评估方向
---
.../Rule/ContextAwareGenerator.cs | 27 +++++++++++++++
.../analyzer-warning-reduction-tracking.md | 30 +++++++++++++----
.../analyzer-warning-reduction-trace.md | 33 +++++++++++++++++++
3 files changed, 84 insertions(+), 6 deletions(-)
diff --git a/GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs b/GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
index b2c4d90e..5e3a0356 100644
--- a/GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
+++ b/GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
@@ -139,12 +139,31 @@ public sealed class ContextAwareGenerator : MetadataAttributeClassGeneratorBase
///
/// 字符串构建器
private static void GenerateContextProperty(StringBuilder sb)
+ {
+ GenerateContextBackingFields(sb);
+ GenerateContextGetter(sb);
+ GenerateContextProviderConfiguration(sb);
+ }
+
+ ///
+ /// 生成上下文缓存和同步所需的字段。
+ ///
+ /// 字符串构建器。
+ private static void GenerateContextBackingFields(StringBuilder sb)
{
sb.AppendLine(" private global::GFramework.Core.Abstractions.Architectures.IArchitectureContext? _context;");
sb.AppendLine(
" private static global::GFramework.Core.Abstractions.Architectures.IArchitectureContextProvider? _contextProvider;");
sb.AppendLine(" private static readonly object _contextSync = new();");
sb.AppendLine();
+ }
+
+ ///
+ /// 生成实例上下文访问器,包含显式注入优先和 provider 惰性回退语义。
+ ///
+ /// 字符串构建器。
+ private static void GenerateContextGetter(StringBuilder sb)
+ {
sb.AppendLine(" /// ");
sb.AppendLine(" /// 获取当前实例绑定的架构上下文。");
sb.AppendLine(" /// ");
@@ -185,6 +204,14 @@ public sealed class ContextAwareGenerator : MetadataAttributeClassGeneratorBase
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine();
+ }
+
+ ///
+ /// 生成静态 provider 配置 API,供测试和宿主在懒加载前替换默认上下文来源。
+ ///
+ /// 字符串构建器。
+ private static void GenerateContextProviderConfiguration(StringBuilder sb)
+ {
sb.AppendLine(" /// ");
sb.AppendLine(" /// 配置当前生成类型共享的上下文提供者。");
sb.AppendLine(" /// ");
diff --git a/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md b/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md
index 7bbba424..ffe8d6ec 100644
--- a/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md
+++ b/ai-plan/public/analyzer-warning-reduction/todos/analyzer-warning-reduction-tracking.md
@@ -7,18 +7,22 @@
## 当前恢复点
-- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-016`
-- 当前阶段:`Phase 16`
+- 恢复点编号:`ANALYZER-WARNING-REDUCTION-RP-017`
+- 当前阶段:`Phase 17`
- 当前焦点:
- 已完成 `GFramework.Core` 当前 `MA0016` / `MA0002` / `MA0015` / `MA0077` 低风险收口批次
+ - 已复核 `net10.0` 下的 `MA0158` 基线:`GFramework.Core` / `GFramework.Cqrs` 当前共有 `16` 个 object lock
+ 建议点,属于跨 target 兼容性风险,不在本轮直接批量替换
+ - 已完成 `GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs` 的剩余 `MA0051` 结构拆分,生成输出保持不变
- `LoggingConfiguration`、`FilterConfiguration` 与 `CollectionExtensions` 已改用集合抽象接口,并保留内部具体集合默认值
- `CoroutineScheduler` 的 tag/group 字典已显式使用 `StringComparer.Ordinal`,保持既有区分大小写语义
- `EasyEvents.AddEvent()` 的重复注册路径已改为状态冲突异常,避免把泛型类型参数伪装成方法参数名
- `Option` 已声明 `IEquatable