From 7311a19c84e8cf93b5c2259097fa7221511e0a90 Mon Sep 17 00:00:00 2001 From: susices Date: Thu, 30 Nov 2023 14:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E6=9E=90=E5=99=A8?= =?UTF-8?q?=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=A6=81=E6=AD=A2=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=A0=87=E8=AE=B0=E4=B8=BAComponent=E5=92=8CChild=20(?= =?UTF-8?q?#524)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EntityMemberDeclarationAnalyzer.cs | 19 ++++++++++++++++++- Share/Analyzer/Config/DiagnosticIds.cs | 2 ++ Share/Analyzer/Config/DiagnosticRules.cs | 18 ++++++++++++++++++ .../Codes/Model/Share/LockStep/LSWorld.cs | 1 - 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Share/Analyzer/Analyzer/EntityMemberDeclarationAnalyzer.cs b/Share/Analyzer/Analyzer/EntityMemberDeclarationAnalyzer.cs index a190f0fd577..717b665ae3b 100644 --- a/Share/Analyzer/Analyzer/EntityMemberDeclarationAnalyzer.cs +++ b/Share/Analyzer/Analyzer/EntityMemberDeclarationAnalyzer.cs @@ -13,7 +13,7 @@ namespace ET.Analyzer public class EntityMemberDeclarationAnalyzer: DiagnosticAnalyzer { public override ImmutableArray SupportedDiagnostics =>ImmutableArray.Create(EntityDelegateDeclarationAnalyzerRule.Rule, - EntityFieldDeclarationInEntityAnalyzerRule.Rule, LSEntityFloatMemberAnalyzer.Rule); + EntityFieldDeclarationInEntityAnalyzerRule.Rule, LSEntityFloatMemberAnalyzer.Rule, EntityComponentChildAnalyzerRule.Rule); public override void Initialize(AnalysisContext context) { @@ -53,11 +53,13 @@ private void Analyzer(SemanticModelAnalysisContext context, INamedTypeSymbol nam { AnalyzeDelegateMember(context, namedTypeSymbol); AnalyzeEntityMember(context, namedTypeSymbol); + AnalyzeComponentChildAttr(context, namedTypeSymbol); }else if (baseType == Definition.LSEntityType) { AnalyzeDelegateMember(context, namedTypeSymbol); AnalyzeEntityMember(context, namedTypeSymbol); AnalyzeFloatMemberInLSEntity(context,namedTypeSymbol); + AnalyzeComponentChildAttr(context, namedTypeSymbol); } } @@ -209,6 +211,21 @@ private bool GenericTypeHasFloatTypeArgs(INamedTypeSymbol namedTypeSymbol) return false; } + + /// + /// 实体类是否同时标记为component child + /// + private void AnalyzeComponentChildAttr(SemanticModelAnalysisContext context, INamedTypeSymbol namedTypeSymbol) + { + bool hasComponentOf = namedTypeSymbol.HasAttribute(Definition.ComponentOfAttribute); + bool hasChildOf = namedTypeSymbol.HasAttribute(Definition.ChildOfAttribute); + if (hasComponentOf && hasChildOf) + { + var syntax = namedTypeSymbol.DeclaringSyntaxReferences.First().GetSyntax() as ClassDeclarationSyntax; + Diagnostic diagnostic = Diagnostic.Create(EntityComponentChildAnalyzerRule.Rule, syntax?.Identifier.GetLocation(),namedTypeSymbol.Name); + context.ReportDiagnostic(diagnostic); + } + } } } diff --git a/Share/Analyzer/Config/DiagnosticIds.cs b/Share/Analyzer/Config/DiagnosticIds.cs index 577b1570501..608e5cfefe4 100644 --- a/Share/Analyzer/Config/DiagnosticIds.cs +++ b/Share/Analyzer/Config/DiagnosticIds.cs @@ -56,5 +56,7 @@ public static class DiagnosticIds public const string EntityHashCodeAnalyzerRuleId = "ET0027"; + + public const string EntityComponentChildAnalyzerRuleId = "ET0028"; } } \ No newline at end of file diff --git a/Share/Analyzer/Config/DiagnosticRules.cs b/Share/Analyzer/Config/DiagnosticRules.cs index e4d78461272..f8b4068858c 100644 --- a/Share/Analyzer/Config/DiagnosticRules.cs +++ b/Share/Analyzer/Config/DiagnosticRules.cs @@ -395,4 +395,22 @@ public static class EntityHashCodeAnalyzerRule true, Description); } + + public static class EntityComponentChildAnalyzerRule + { + private const string Title = "实体类禁止同时标记为Component和Child"; + + private const string MessageFormat = "实体类:{0} 禁止同时标记为Component和Child"; + + private const string Description = "实体类禁止同时标记为Component和Child."; + + public static readonly DiagnosticDescriptor Rule = + new DiagnosticDescriptor(DiagnosticIds.EntityComponentChildAnalyzerRuleId, + Title, + MessageFormat, + DiagnosticCategories.All, + DiagnosticSeverity.Error, + true, + Description); + } } \ No newline at end of file diff --git a/Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSWorld.cs b/Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSWorld.cs index 5784dd3a5e1..d97427679b0 100644 --- a/Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSWorld.cs +++ b/Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSWorld.cs @@ -26,7 +26,6 @@ public static TSRandom GetRandom(this LSEntity entity) [EnableMethod] [ChildOf] - [ComponentOf] [MemoryPackable] public partial class LSWorld: Entity, IAwake, IScene {