From 539d285faa3b2608a9f5a4be54d180938f29cfbe Mon Sep 17 00:00:00 2001
From: GwWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Sun, 28 Dec 2025 16:41:40 +0800
Subject: [PATCH] =?UTF-8?q?refactor(assets):=20=E7=A7=BB=E9=99=A4IAssetCat?=
=?UTF-8?q?alogSystem=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=E5=BC=82?=
=?UTF-8?q?=E5=B8=B8=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除RegisterSceneUnit方法的InvalidOperationException异常文档
- 移除RegisterScenePage方法的InvalidOperationException异常文档
- 为SourceGenerators.Abstractions项目启用可空引用类型支持
- 在测试中禁用GF_Common_Trace_001诊断警告
---
.../assets/IAssetCatalogSystem.cs | 4 --
...Godot.SourceGenerators.Abstractions.csproj | 1 +
.../core/GeneratorTest.cs | 3 +-
.../rule/ContextAwareGeneratorTests.cs | 47 +++++++------------
4 files changed, 19 insertions(+), 36 deletions(-)
diff --git a/GFramework.Game.Abstractions/assets/IAssetCatalogSystem.cs b/GFramework.Game.Abstractions/assets/IAssetCatalogSystem.cs
index cab53ee..ff38ba1 100644
--- a/GFramework.Game.Abstractions/assets/IAssetCatalogSystem.cs
+++ b/GFramework.Game.Abstractions/assets/IAssetCatalogSystem.cs
@@ -34,14 +34,12 @@ public interface IAssetCatalogSystem : ISystem
///
/// 场景单元的唯一标识键
/// 场景单元资源的路径
- /// 当指定的键已存在时抛出异常
public void RegisterSceneUnit(string key, string path);
///
/// 通过资产目录映射注册场景单元
///
/// 包含场景单元信息的资产目录映射对象
- /// 当映射ID不是SceneUnitId类型或键已存在时抛出异常
public void RegisterSceneUnit(AssetCatalog.AssetCatalogMapping mapping);
///
@@ -49,14 +47,12 @@ public interface IAssetCatalogSystem : ISystem
///
/// 场景页面的唯一标识键
/// 场景页面资源路径
- /// 当键已存在时抛出异常
void RegisterScenePage(string key, string path);
///
/// 通过资产目录映射注册场景页面
///
/// 包含场景页面信息的资产目录映射对象
- /// 当映射ID不是ScenePageId类型或键已存在时抛出异常
void RegisterScenePage(AssetCatalog.AssetCatalogMapping mapping);
///
diff --git a/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj
index 3e7de14..7acd9a3 100644
--- a/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj
+++ b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj
@@ -8,6 +8,7 @@
false
true
T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute
+ enable
diff --git a/GFramework.SourceGenerators.Tests/core/GeneratorTest.cs b/GFramework.SourceGenerators.Tests/core/GeneratorTest.cs
index 4dfbc09..b78411d 100644
--- a/GFramework.SourceGenerators.Tests/core/GeneratorTest.cs
+++ b/GFramework.SourceGenerators.Tests/core/GeneratorTest.cs
@@ -25,7 +25,8 @@ public static class GeneratorTest
TestState =
{
Sources = { source }
- }
+ },
+ DisabledDiagnostics = { "GF_Common_Trace_001" }
};
// 添加期望的生成源文件到测试状态中
diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
index 6727f4a..971c18d 100644
--- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
+++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
@@ -4,18 +4,11 @@ using NUnit.Framework;
namespace GFramework.SourceGenerators.Tests.rule;
-///
-/// 测试ContextAwareGenerator源代码生成器的功能
-///
[TestFixture]
public class ContextAwareGeneratorTests
{
- ///
- /// 测试ContextAware代码生成功能
- /// 验证当使用[ContextAware]特性标记的类能够正确生成上下文感知的相关代码
- ///
[Test]
- public Task Generates_ContextAware_Code()
+ public async Task Generates_ContextAware_Code()
{
const string source = """
using System;
@@ -33,7 +26,8 @@ public class ContextAwareGeneratorTests
using GFramework.SourceGenerators.Abstractions.rule;
[ContextAware]
- public partial class MyRule: GFramework.Core.Abstractions.rule.IContextAware
+ public partial class MyRule
+ : GFramework.Core.Abstractions.rule.IContextAware
{
}
}
@@ -44,7 +38,8 @@ public class ContextAwareGeneratorTests
{
public interface IContextAware
{
- void SetContext(GFramework.Core.Abstractions.architecture.IArchitectureContext context);
+ void SetContext(
+ GFramework.Core.Abstractions.architecture.IArchitectureContext context);
}
}
@@ -75,19 +70,14 @@ public class ContextAwareGeneratorTests
}
""";
- Assert.DoesNotThrowAsync(async () =>
- {
- await GeneratorTest.RunAsync(
- source + "\n" + frameworkStub,
- ("MyRule.ContextAware.g.cs", expected)
- );
- });
-
- return Task.CompletedTask;
+ await GeneratorTest.RunAsync(
+ source + "\n" + frameworkStub,
+ ("MyRule.ContextAware.g.cs", expected)
+ );
}
[Test]
- public Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
+ public async Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
{
const string source = """
using System;
@@ -105,7 +95,6 @@ public class ContextAwareGeneratorTests
using GFramework.SourceGenerators.Abstractions.rule;
using GFramework.Core.Abstractions.rule;
- // 间接接口:继承自 IContextAware
public interface IMyRuleContextAware : IContextAware
{
}
@@ -122,7 +111,8 @@ public class ContextAwareGeneratorTests
{
public interface IContextAware
{
- void SetContext(GFramework.Core.Abstractions.architecture.IArchitectureContext context);
+ void SetContext(
+ GFramework.Core.Abstractions.architecture.IArchitectureContext context);
}
}
@@ -153,14 +143,9 @@ public class ContextAwareGeneratorTests
}
""";
- Assert.DoesNotThrowAsync(async () =>
- {
- await GeneratorTest.RunAsync(
- source + "\n" + frameworkStub,
- ("MyRule.ContextAware.g.cs", expected)
- );
- });
-
- return Task.CompletedTask;
+ await GeneratorTest.RunAsync(
+ source + "\n" + frameworkStub,
+ ("MyRule.ContextAware.g.cs", expected)
+ );
}
}
\ No newline at end of file