From 1d0339bd9b62a282473a288789c5e23cfce04ffd Mon Sep 17 00:00:00 2001 From: Blank Date: Tue, 3 Nov 2026 06:07:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(hosting):=20=E6=8B=86=E5=88=86=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E6=A8=A1=E5=9D=97=E7=9B=B8=E4=BD=8D=E8=BE=B9=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E6=96=B9=E6=B3=95=E9=99=8D=E4=BD=8E=E8=AE=A4=E7=9F=A5?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ApplyHostModulePhaseEdges 认知复杂度 28 超出 Sonar S3776 阈值 15, 等价拆分为相位分类收集与 Before/After 相位边注入三个私有方法, 合成边集合与拓扑定序行为零变化。 Linear: GFX-1205 --- .../CapabilityDependencyChecker.cs | 115 ++++++++++++------ 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/Capability/GameFrameX.Capability.Hosting.Core/CapabilityDependencyChecker.cs b/Capability/GameFrameX.Capability.Hosting.Core/CapabilityDependencyChecker.cs index 46cd12c64..ad3e6db3f 100644 --- a/Capability/GameFrameX.Capability.Hosting.Core/CapabilityDependencyChecker.cs +++ b/Capability/GameFrameX.Capability.Hosting.Core/CapabilityDependencyChecker.cs @@ -106,9 +106,40 @@ private static void ApplyHostModulePhaseEdges(IReadOnlyList e return; } - var beforePhaseIds = new List(); - var afterPhaseIds = new List(); - var hostModuleIds = new HashSet(StringComparer.Ordinal); + var phases = CollectHostModulePhases(hostModules, edges); + if (phases.HostModuleIds.Count == 0) + { + return; + } + + for (var i = 0; i < enabledModules.Count; i++) + { + var moduleId = enabledModules[i].Manifest.Id; + if (phases.HostModuleIds.Contains(moduleId)) + { + // After 相位宿主模块依赖能力模块与 Before 相位宿主模块;Before 相位宿主模块之间不注入合成边(由自身声明与 Id 序决定)。 + if (phases.AfterPhaseIds.Contains(moduleId)) + { + AddAfterPhaseHostModuleDependencies(moduleId, enabledModules, phases.AfterPhaseIds, edges); + } + + continue; + } + + // 能力模块依赖全部 Before 相位宿主模块。 + AddBeforePhaseHostModuleEdges(moduleId, phases.BeforePhaseIds, edges); + } + } + + /// + /// 收集进入启用集的宿主模块相位分类(未进入本次装配模块表的宿主模块不参与合成边)。 + /// + /// 宿主模块表(含相位)。 + /// 定序边累积器(启用集成员判定用)。 + /// 相位分类结果。 + private static HostModulePhases CollectHostModulePhases(IReadOnlyList hostModules, Dictionary> edges) + { + var phases = new HostModulePhases(); for (var i = 0; i < hostModules.Count; i++) { var hostModuleId = hostModules[i].Module.Manifest.Id; @@ -118,54 +149,68 @@ private static void ApplyHostModulePhaseEdges(IReadOnlyList e continue; } - hostModuleIds.Add(hostModuleId); + phases.HostModuleIds.Add(hostModuleId); if (hostModules[i].Phase == CapabilityHostModulePhase.BeforeCapabilities) { - beforePhaseIds.Add(hostModuleId); + phases.BeforePhaseIds.Add(hostModuleId); } else { - afterPhaseIds.Add(hostModuleId); + phases.AfterPhaseIds.Add(hostModuleId); } } - if (beforePhaseIds.Count == 0 && afterPhaseIds.Count == 0) - { - return; - } + return phases; + } - for (var i = 0; i < enabledModules.Count; i++) + /// + /// 注入 After 相位宿主模块的合成定序边:依赖全部能力模块与全部 Before 相位宿主模块(不含其他 After 相位宿主模块)。 + /// + /// After 相位宿主模块 Id。 + /// 启用模块。 + /// After 相位宿主模块 Id 集。 + /// 定序边累积器。 + private static void AddAfterPhaseHostModuleDependencies(string moduleId, IReadOnlyList enabledModules, List afterPhaseIds, Dictionary> edges) + { + var dependentIds = edges[moduleId]; + for (var j = 0; j < enabledModules.Count; j++) { - var moduleId = enabledModules[i].Manifest.Id; - if (hostModuleIds.Contains(moduleId)) + var otherId = enabledModules[j].Manifest.Id; + if (!string.Equals(otherId, moduleId, StringComparison.Ordinal) + && !afterPhaseIds.Contains(otherId)) { - // After 相位宿主模块依赖能力模块与 Before 相位宿主模块;Before 相位宿主模块之间不注入合成边(由自身声明与 Id 序决定)。 - if (afterPhaseIds.Contains(moduleId)) - { - var dependentIds = edges[moduleId]; - for (var j = 0; j < enabledModules.Count; j++) - { - var otherId = enabledModules[j].Manifest.Id; - if (!string.Equals(otherId, moduleId, StringComparison.Ordinal) - && !afterPhaseIds.Contains(otherId)) - { - dependentIds.Add(otherId); - } - } - } - - continue; + dependentIds.Add(otherId); } + } + } - // 能力模块依赖全部 Before 相位宿主模块。 - var moduleEdges = edges[moduleId]; - for (var j = 0; j < beforePhaseIds.Count; j++) - { - moduleEdges.Add(beforePhaseIds[j]); - } + /// + /// 注入能力模块对全部 Before 相位宿主模块的合成定序边。 + /// + /// 能力模块 Id。 + /// Before 相位宿主模块 Id 列表。 + /// 定序边累积器。 + private static void AddBeforePhaseHostModuleEdges(string moduleId, List beforePhaseIds, Dictionary> edges) + { + var moduleEdges = edges[moduleId]; + for (var j = 0; j < beforePhaseIds.Count; j++) + { + moduleEdges.Add(beforePhaseIds[j]); } } + /// + /// 宿主模块相位分类结果(均已进入启用集)。 + /// + private sealed class HostModulePhases + { + public List BeforePhaseIds { get; } = new List(); + + public List AfterPhaseIds { get; } = new List(); + + public HashSet HostModuleIds { get; } = new HashSet(StringComparer.Ordinal); + } + /// /// 检查单个模块的必选 / 可选依赖(必选缺失记问题;可选缺失记数据;在场依赖记定序边与来源策略)。