From 5f55a1b8dbee6c25a73cf70b4b2a0863b7ebbd25 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 27 Dec 2025 21:29:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(generator):=20=E5=B0=86Attributes?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BAAbstracti?= =?UTF-8?q?ons=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将GFramework.SourceGenerators.Attributes重命名为GFramework.SourceGenerators.Abstractions - 将GFramework.Godot.SourceGenerators.Attributes重命名为GFramework.Godot.SourceGenerators.Abstractions - 更新所有源生成器中对Attribute命名空间的引用 - 修改项目引用从Attributes指向Abstractions - 添加程序集打包配置到生成项目 - 更新解决方案文件中的项目引用路径 - 修正测试文件中的命名空间引用 --- .../GFramework.Godot.SourceGenerators.Abstractions.csproj | 1 + .../logging/GodotLogAttribute.cs | 4 +--- .../GFramework.Godot.SourceGenerators.csproj | 8 +++++--- .../logging/GodotLoggerGenerator.cs | 2 +- .../GFramework.SourceGenerators.Abstractions.csproj | 1 + .../enums/EnumExtensionsAttribute.cs | 4 +--- .../logging/LogAttribute.cs | 4 +--- .../rule/ContextAwareAttribute.cs | 4 +--- .../rule/ContextAwareGeneratorTests.cs | 8 ++++---- .../GFramework.SourceGenerators.csproj | 8 +++++--- .../enums/EnumExtensionsGenerator.cs | 2 +- GFramework.SourceGenerators/logging/LoggerGenerator.cs | 2 +- GFramework.SourceGenerators/rule/ContextAwareGenerator.cs | 2 +- GFramework.sln | 4 ++-- 14 files changed, 26 insertions(+), 28 deletions(-) rename GFramework.Godot.SourceGenerators.Attributes/GFramework.Godot.SourceGenerators.Attributes.csproj => GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj (78%) rename {GFramework.Godot.SourceGenerators.Attributes => GFramework.Godot.SourceGenerators.Abstractions}/logging/GodotLogAttribute.cs (92%) rename GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj => GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj (84%) rename {GFramework.SourceGenerators.Attributes => GFramework.SourceGenerators.Abstractions}/enums/EnumExtensionsAttribute.cs (88%) rename {GFramework.SourceGenerators.Attributes => GFramework.SourceGenerators.Abstractions}/logging/LogAttribute.cs (92%) rename {GFramework.SourceGenerators.Attributes => GFramework.SourceGenerators.Abstractions}/rule/ContextAwareAttribute.cs (72%) diff --git a/GFramework.Godot.SourceGenerators.Attributes/GFramework.Godot.SourceGenerators.Attributes.csproj b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj similarity index 78% rename from GFramework.Godot.SourceGenerators.Attributes/GFramework.Godot.SourceGenerators.Attributes.csproj rename to GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj index 71decee..3d2751f 100644 --- a/GFramework.Godot.SourceGenerators.Attributes/GFramework.Godot.SourceGenerators.Attributes.csproj +++ b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj @@ -5,6 +5,7 @@ GeWuYou.GFramework.Godot.SourceGenerators.Attributes 1.0.0 10 + GFramework.Godot.SourceGenerators.Attributes diff --git a/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs b/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs similarity index 92% rename from GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs rename to GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs index 17afa44..a3b2b92 100644 --- a/GFramework.Godot.SourceGenerators.Attributes/logging/GodotLogAttribute.cs +++ b/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs @@ -1,7 +1,5 @@ #nullable enable -using System; - -namespace GFramework.Godot.SourceGenerators.Attributes.logging; +namespace GFramework.GFramework.Godot.SourceGenerators.Abstractions.logging; /// /// Godot日志特性,用于在类上标记以自动生成日志字段 diff --git a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj index 41bc1f3..db5e1fd 100644 --- a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj +++ b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj @@ -23,8 +23,7 @@ - + @@ -36,5 +35,8 @@ PackagePath="analyzers/dotnet/cs" Visible="false"/> - + + + + diff --git a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs index db47829..06e8cdc 100644 --- a/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs +++ b/GFramework.Godot.SourceGenerators/logging/GodotLoggerGenerator.cs @@ -16,7 +16,7 @@ namespace GFramework.Godot.SourceGenerators.logging; public sealed class GodotLoggerGenerator : IIncrementalGenerator { private const string AttributeMetadataName = - "GFramework.Godot.SourceGenerators.Attributes.logging.GodotLogAttribute"; + "GFramework.Godot.SourceGenerators.Abstractions.logging.GodotLogAttribute"; private const string AttributeShortName = "GodotLogAttribute"; private const string AttributeShortNameWithoutSuffix = "GodotLog"; diff --git a/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj b/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj similarity index 84% rename from GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj rename to GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj index 5ec19a5..17d60c6 100644 --- a/GFramework.SourceGenerators.Attributes/GFramework.SourceGenerators.Attributes.csproj +++ b/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj @@ -4,6 +4,7 @@ GeWuYou.GFramework.SourceGenerators.Attributes 1.0.0 10 + GFramework.SourceGenerators.Attributes diff --git a/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs b/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs similarity index 88% rename from GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs rename to GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs index 1e388ca..3fca257 100644 --- a/GFramework.SourceGenerators.Attributes/enums/EnumExtensionsAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs @@ -1,6 +1,4 @@ -using System; - -namespace GFramework.SourceGenerators.Attributes.enums; +namespace GFramework.GFramework.SourceGenerators.Abstractions.enums; /// /// 标注在 enum 上,Source Generator 会为该 enum 生成扩展方法。 diff --git a/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs b/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs similarity index 92% rename from GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs rename to GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs index a38f0d3..6256089 100644 --- a/GFramework.SourceGenerators.Attributes/logging/LogAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs @@ -1,7 +1,5 @@ #nullable enable -using System; - -namespace GFramework.SourceGenerators.Attributes.logging; +namespace GFramework.GFramework.SourceGenerators.Abstractions.logging; /// /// 标注在类上,Source Generator 会为该类自动生成一个日志记录器字段。 diff --git a/GFramework.SourceGenerators.Attributes/rule/ContextAwareAttribute.cs b/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs similarity index 72% rename from GFramework.SourceGenerators.Attributes/rule/ContextAwareAttribute.cs rename to GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs index d1060d0..433c16f 100644 --- a/GFramework.SourceGenerators.Attributes/rule/ContextAwareAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs @@ -1,6 +1,4 @@ -using System; - -namespace GFramework.SourceGenerators.Attributes.rule; +namespace GFramework.GFramework.SourceGenerators.Abstractions.rule; /// /// 标记该类需要自动实现 IContextAware diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs index bb5d942..dd23b7e 100644 --- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs +++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs @@ -22,7 +22,7 @@ public class ContextAwareGeneratorTests const string source = """ using System; - namespace GFramework.SourceGenerators.Attributes.rule + namespace GFramework.SourceGenerators.Abstractions.rule { [AttributeUsage(AttributeTargets.Class)] public sealed class ContextAwareAttribute : Attribute @@ -32,7 +32,7 @@ public class ContextAwareGeneratorTests namespace TestApp { - using GFramework.SourceGenerators.Attributes.rule; + using GFramework.SourceGenerators.Abstractions.rule; [ContextAware] public partial class MyRule: GFramework.Core.rule.IContextAware @@ -89,7 +89,7 @@ public class ContextAwareGeneratorTests const string source = """ using System; - namespace GFramework.SourceGenerators.Attributes.rule + namespace GFramework.SourceGenerators.Abstractions.rule { [AttributeUsage(AttributeTargets.Class)] public sealed class ContextAwareAttribute : Attribute @@ -99,7 +99,7 @@ public class ContextAwareGeneratorTests namespace TestApp { - using GFramework.SourceGenerators.Attributes.rule; + using GFramework.SourceGenerators.Abstractions.rule; using GFramework.Core.rule; // 间接接口:继承自 IContextAware diff --git a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj index 37b5ec8..eee4406 100644 --- a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj +++ b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj @@ -24,8 +24,7 @@ - + @@ -37,5 +36,8 @@ PackagePath="analyzers/dotnet/cs" Visible="false"/> - + + + + diff --git a/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs b/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs index 9e31593..9d9b36f 100644 --- a/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs +++ b/GFramework.SourceGenerators/enums/EnumExtensionsGenerator.cs @@ -11,7 +11,7 @@ namespace GFramework.SourceGenerators.enums; public class EnumExtensionsGenerator : IIncrementalGenerator { private const string AttributeFullName = - "GFramework.SourceGenerators.Attributes.generator.enums.GenerateEnumExtensionsAttribute"; + "GFramework.SourceGenerators.Abstractions.generator.enums.GenerateEnumExtensionsAttribute"; public void Initialize(IncrementalGeneratorInitializationContext context) { diff --git a/GFramework.SourceGenerators/logging/LoggerGenerator.cs b/GFramework.SourceGenerators/logging/LoggerGenerator.cs index b298ce5..5d931c0 100644 --- a/GFramework.SourceGenerators/logging/LoggerGenerator.cs +++ b/GFramework.SourceGenerators/logging/LoggerGenerator.cs @@ -18,7 +18,7 @@ namespace GFramework.SourceGenerators.logging; [Generator] public sealed class LoggerGenerator : IIncrementalGenerator { - private const string AttributeMetadataName = "GFramework.SourceGenerators.Attributes.logging.LogAttribute"; + private const string AttributeMetadataName = "GFramework.SourceGenerators.Abstractions.logging.LogAttribute"; private const string AttributeShortName = "LogAttribute"; private const string AttributeShortNameWithoutSuffix = "Log"; diff --git a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs index 0124541..56655ad 100644 --- a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs +++ b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs @@ -11,7 +11,7 @@ namespace GFramework.SourceGenerators.rule; public sealed class ContextAwareGenerator : IIncrementalGenerator { private const string AttributeMetadataName = - "GFramework.SourceGenerators.Attributes.rule.ContextAwareAttribute"; + "GFramework.SourceGenerators.Abstractions.rule.ContextAwareAttribute"; public void Initialize(IncrementalGeneratorInitializationContext context) { diff --git a/GFramework.sln b/GFramework.sln index f1efe57..ca953de 100644 --- a/GFramework.sln +++ b/GFramework.sln @@ -4,7 +4,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework ", "GFramework.c EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators", "GFramework.SourceGenerators\GFramework.SourceGenerators.csproj", "{E9D51809-0351-4B83-B85B-B5F469AAB3B8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators.Attributes", "GFramework.SourceGenerators.Attributes\GFramework.SourceGenerators.Attributes.csproj", "{84C5C3C9-5620-4924-BA04-92F813F2B70F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators.Abstractions", "GFramework.SourceGenerators.Abstractions\GFramework.SourceGenerators.Abstractions.csproj", "{84C5C3C9-5620-4924-BA04-92F813F2B70F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Core", "GFramework.Core\GFramework.Core.csproj", "{A6D5854D-79EA-487A-9ED9-396E6A1F8031}" EndProject @@ -14,7 +14,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Game", "GFramewo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.SourceGenerators", "GFramework.Godot.SourceGenerators\GFramework.Godot.SourceGenerators.csproj", "{C56FD287-CBC6-4C44-B3DF-103FA3660CA0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.SourceGenerators.Attributes", "GFramework.Godot.SourceGenerators.Attributes\GFramework.Godot.SourceGenerators.Attributes.csproj", "{3A1132B7-EC3B-4BB6-A752-8ADC92BC08A0}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.Godot.SourceGenerators.Abstractions", "GFramework.Godot.SourceGenerators.Abstractions\GFramework.Godot.SourceGenerators.Abstractions.csproj", "{3A1132B7-EC3B-4BB6-A752-8ADC92BC08A0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFramework.SourceGenerators.Common", "GFramework.SourceGenerators.Common\GFramework.SourceGenerators.Common.csproj", "{3DB57A3A-ACCF-47BE-A17B-2ADD68B6C8AA}" EndProject