From 12ac998c270768ffe2b1d541f70120cbed884abd Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:01:51 +0900 Subject: [PATCH 1/7] Add : Support AlchemySerialization to generics and inheritance --- .../AlchemySerializeGenerator.cs | 147 ++++++++++++++---- .../Editor/Internal/InspectorHelper.cs | 12 +- .../Generator/Alchemy.SourceGenerator.dll | Bin 17408 -> 18944 bytes .../Assets/Tests/InheritedSerializeTest.cs | 11 ++ .../Tests/InheritedSerializeTest.cs.meta | 11 ++ .../Tests/InheritedSerializeTestBase.cs | 13 ++ .../Tests/InheritedSerializeTestBase.cs.meta | 3 + 7 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 Alchemy/Assets/Tests/InheritedSerializeTest.cs create mode 100644 Alchemy/Assets/Tests/InheritedSerializeTest.cs.meta create mode 100644 Alchemy/Assets/Tests/InheritedSerializeTestBase.cs create mode 100644 Alchemy/Assets/Tests/InheritedSerializeTestBase.cs.meta diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 98d9e7f..11a5cc4 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -31,20 +31,21 @@ public void Execute(GeneratorExecutionContext context) if (!IsPartial(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, + typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } if (IsNested(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, + typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } var fieldSymbols = new List(); var fields = typeSyntax.Members - .Where(x => x is FieldDeclarationSyntax) - .Select(x => (FieldDeclarationSyntax)x); + .OfType(); foreach (var field in fields) { var model = context.Compilation.GetSemanticModel(field.SyntaxTree); @@ -54,22 +55,24 @@ public void Execute(GeneratorExecutionContext context) var alchemySerializeAttribute = fieldSymbol.GetAttributes() .FirstOrDefault(x => x.AttributeClass.Name is "AlchemySerializeField" - or "AlchemySerializeFieldAttribute" - or "Alchemy.Serialization.AlchemySerializeField" - or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); + or "AlchemySerializeFieldAttribute" + or "Alchemy.Serialization.AlchemySerializeField" + or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); var nonSerializedAttribute = fieldSymbol.GetAttributes() .FirstOrDefault(x => x.AttributeClass.Name is "NonSerialized" - or "NonSerializedAttribute" - or "System.NonSerialized" - or "System.NonSerializedAttribute"); + or "NonSerializedAttribute" + or "System.NonSerialized" + or "System.NonSerializedAttribute"); if (alchemySerializeAttribute != null) { if (nonSerializedAttribute == null) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), fieldSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create( + DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), + fieldSymbol.Name)); } fieldSymbols.Add(fieldSymbol); @@ -88,16 +91,76 @@ x.AttributeClass.Name is "NonSerialized" } catch (Exception ex) { - var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); - context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, DiagnosticSeverity.Error)); + var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", + "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", + "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); + context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, + DiagnosticSeverity.Error)); } } + static string ReplaceGenericsToCount( string typeName,int count) + { + if(count == 0) return typeName; + var builder = new StringBuilder(); + bool skip = false; + foreach (var c in typeName) + { + if (c == '<') + { + skip = true; + builder.Append(count); + } + else if (c == '>') + { + skip = false; + } + else if (!skip) + { + builder.Append(c); + } + } + return builder.ToString(); + } static string ProcessClass(INamedTypeSymbol typeSymbol, List fieldSymbols) { var onAfterDeserializeCodeBuilder = new StringBuilder(); var onBeforeSerializeCodeBuilder = new StringBuilder(); var serializationDataCodeBuilder = new StringBuilder(); + bool hasInheritedImplementation = false; + var baseType = typeSymbol.BaseType; + while (baseType != null) + { + if (baseType.GetAttributes().Any(x => x.AttributeClass!.Name + is "AlchemySerialize" + or "AlchemySerializeAttribute" + or "Alchemy.Serialization.AlchemySerialize" + or "Alchemy.Serialization.AlchemySerializeAttribute")) + { + hasInheritedImplementation = true; + break; + } + + baseType = baseType.BaseType; + } + + var genericsCount = 0; + if (typeSymbol.IsGenericType) + { + genericsCount = typeSymbol.TypeParameters.Length; + + } + var typeGenerics = typeSymbol.IsGenericType + ? "<" + string.Join(", ", typeSymbol.TypeParameters.Select(x => x.Name)) + ">" + : ""; + + var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) + .Replace("global::", ""); + alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) + "_alchemySerializationData"; + + var inheritedSerializationCallback = hasInheritedImplementation + ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" + : string.Empty; var hasShowSerializationData = typeSymbol.GetAttributes().Any(x => x.AttributeClass.Name is "ShowAlchemySerializationData" @@ -105,18 +168,22 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field or "Alchemy.Serialization.ShowAlchemySerializationData" or "Alchemy.Serialization.ShowAlchemySerializationDataAttribute"); - var serializationDataAttibutesCode = hasShowSerializationData ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; + var serializationDataAttributesCode = hasShowSerializationData + ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" + : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; // target class namespace - var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace ? string.Empty : $"namespace {typeSymbol.ContainingNamespace} {{"; + var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace + ? string.Empty + : $"namespace {typeSymbol.ContainingNamespace} {{"; foreach (var field in fieldSymbols) { var serializeCode = -@$"try + @$"try {{ - alchemySerializationData.{field.Name}.data = global::Alchemy.Serialization.Internal.SerializationHelper.ToJson(this.{field.Name} , alchemySerializationData.UnityObjectReferences); - alchemySerializationData.{field.Name}.isCreated = true; + {alchemySerializationDataName}.{field.Name}.data = global::Alchemy.Serialization.Internal.SerializationHelper.ToJson(this.{field.Name} , {alchemySerializationDataName}.UnityObjectReferences); + {alchemySerializationDataName}.{field.Name}.isCreated = true; }} catch (global::System.Exception ex) {{ @@ -124,11 +191,11 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field }}"; var deserializeCode = -@$"try + @$"try {{ - if (alchemySerializationData.{field.Name}.isCreated) + if ({alchemySerializationDataName}.{field.Name}.isCreated) {{ - this.{field.Name} = global::Alchemy.Serialization.Internal.SerializationHelper.FromJson<{field.Type.ToDisplayString()}>(alchemySerializationData.{field.Name}.data, alchemySerializationData.UnityObjectReferences); + this.{field.Name} = global::Alchemy.Serialization.Internal.SerializationHelper.FromJson<{field.Type.ToDisplayString()}>({alchemySerializationDataName}.{field.Name}.data, {alchemySerializationDataName}.UnityObjectReferences); }} }} catch (global::System.Exception ex) @@ -143,23 +210,37 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field } return -@$" + @$" // {ns} - partial class {typeSymbol.Name} : global::UnityEngine.ISerializationCallbackReceiver + partial class {typeSymbol.Name}{typeGenerics} : global::UnityEngine.ISerializationCallbackReceiver {{ void global::UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize() {{ - {onAfterDeserializeCodeBuilder} + SerializationCallback_AlchemyImpl(false); if (this is global::Alchemy.Serialization.IAlchemySerializationCallbackReceiver receiver) receiver.OnAfterDeserialize(); }} void global::UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize() {{ if (this is global::Alchemy.Serialization.IAlchemySerializationCallbackReceiver receiver) receiver.OnBeforeSerialize(); - alchemySerializationData.UnityObjectReferences.Clear(); - {onBeforeSerializeCodeBuilder} + SerializationCallback_AlchemyImpl(true); + }} + + protected {(hasInheritedImplementation ? "new" : "")} void SerializationCallback_AlchemyImpl(bool isBeforeSerialize = false) + {{ + {inheritedSerializationCallback} + if (isBeforeSerialize) + {{ + {alchemySerializationDataName}.UnityObjectReferences.Clear(); + {onBeforeSerializeCodeBuilder} + + }} + else + {{ + {onAfterDeserializeCodeBuilder} + }} }} [global::System.Serializable] @@ -178,7 +259,7 @@ public sealed class Item }} }} - {serializationDataAttibutesCode} private AlchemySerializationData alchemySerializationData = new(); + {serializationDataAttributesCode} private AlchemySerializationData {alchemySerializationDataName} = new(); }} {(string.IsNullOrEmpty(ns) ? "" : "}")} @@ -209,12 +290,12 @@ public void OnVisitSyntaxNode(SyntaxNode syntaxNode) if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax) { var hasAttribute = typeDeclarationSyntax.AttributeLists - .SelectMany(x => x.Attributes) - .Any(x => x.Name.ToString() - is "AlchemySerialize" - or "AlchemySerializeAttribute" - or "Alchemy.Serialization.AlchemySerialize" - or "Alchemy.Serialization.AlchemySerializeAttribute"); + .SelectMany(x => x.Attributes) + .Any(x => x.Name.ToString() + is "AlchemySerialize" + or "AlchemySerializeAttribute" + or "Alchemy.Serialization.AlchemySerialize" + or "Alchemy.Serialization.AlchemySerializeAttribute"); if (hasAttribute) { TargetTypes.Add(typeDeclarationSyntax); diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs index 372f926..600a684 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs @@ -235,13 +235,21 @@ public static VisualElement CreateMemberElement(SerializedObject serializedObjec #if ALCHEMY_SUPPORT_SERIALIZATION if (serializedObject.targetObject != null && - serializedObject.targetObject.GetType().HasCustomAttribute() && + memberInfo.DeclaringType.HasCustomAttribute() && memberInfo.HasCustomAttribute()) { var element = default(VisualElement); if (memberInfo is FieldInfo fieldInfo) { - SerializedProperty GetProperty() => findPropertyFunc?.Invoke("alchemySerializationData").FindPropertyRelative(memberInfo.Name); + var declaredType = fieldInfo.DeclaringType; + if (declaredType.IsConstructedGenericType) + { + declaredType = declaredType.GetGenericTypeDefinition(); + } + var dataName = declaredType.FullName.Replace("`","").Replace(".", "_") + "_alchemySerializationData"; + + SerializedProperty GetProperty() => findPropertyFunc?.Invoke(dataName) + .FindPropertyRelative(memberInfo.Name); var p = GetProperty(); if (p != null) diff --git a/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll b/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll index e7145a8f73ebaa1d43fdc2ed2bd27be10ede6875..8436b83ba3984d61e878dc008d8879b89ff60eea 100644 GIT binary patch literal 18944 zcmeHP3v?9MdH(P0?(9R-qFo{0kHtK^Mre@`V1WUn7gz>~hlFivh*+%#v0=3%W>$bq zz)KQ4#kCugoVIZrHwN2Dh@09uiO+GISM4^b-PlfY8mCVDNPO(N$8D3wIcX9%G4%WI z%X7K1S@F`~Uae|NifL@9ZpHzjrseh{%o4g$qQF;m+4aSx#JJ(Hxxrc#yu} ze|EuRV(YUDdJiPc$grUg8u6h>BA!m`nMl7DF-FpnWIEE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heritedSerializeTest.cs b/Alchemy/Assets/Tests/InheritedSerializeTest.cs new file mode 100644 index 0000000..864437b --- /dev/null +++ b/Alchemy/Assets/Tests/InheritedSerializeTest.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using Alchemy.Serialization; +using UnityEngine; + + +[AlchemySerialize] +public partial class InheritedSerializeTest : InheritedSerializeTestBase +{ + [AlchemySerializeField, NonSerialized] int? nullableInt; +} \ No newline at end of file diff --git a/Alchemy/Assets/Tests/InheritedSerializeTest.cs.meta b/Alchemy/Assets/Tests/InheritedSerializeTest.cs.meta new file mode 100644 index 0000000..e2f03de --- /dev/null +++ b/Alchemy/Assets/Tests/InheritedSerializeTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 54b828d414a20a74b92a3ec43f78f187 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs new file mode 100644 index 0000000..4459c8e --- /dev/null +++ b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using Alchemy.Serialization; +using UnityEngine; + + +[AlchemySerialize] +public partial class InheritedSerializeTestBase : MonoBehaviour +{ + [AlchemySerializeField, NonSerialized] HashSet set; + +} + diff --git a/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs.meta b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs.meta new file mode 100644 index 0000000..7427156 --- /dev/null +++ b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 74b376952c9a4c42a10525c553c6e044 +timeCreated: 1709000968 \ No newline at end of file From 3b4d8ba52e11c454c50d35eec19e75b55f7c4b8a Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:10:50 +0900 Subject: [PATCH 2/7] Fix : Replace "." to "_" --- .../AlchemySerializeGenerator.cs | 2 +- .../Generator/Alchemy.SourceGenerator.dll | Bin 18944 -> 18944 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 11a5cc4..16224ed 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -155,7 +155,7 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field : ""; var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - .Replace("global::", ""); + .Replace("global::", "").Replace(".", "_"); alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) + "_alchemySerializationData"; var inheritedSerializationCallback = hasInheritedImplementation diff --git a/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll b/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll index 8436b83ba3984d61e878dc008d8879b89ff60eea..07002ddacd245006c41c8175b836766e7eb70a3e 100644 GIT binary patch delta 810 zcmXw%T}TvB6vzK}c6MiX^J7OVw@~sEH%*(FR(JP7!EMWr5)}fAO59I+2zJ>rst4Ug zG>amKSww;!vWGCRhRkXdS~5{0EEFAdS23EdpIUqXlBe9nHuU2^`aKu@)CFJOiN zr%5;T3D;}K)O@pXYZZ%pBQM~UMU$+NcjBE%v)+de2VD46%z2j`ExZe3KBG><2G>rM zG-=kkNAMG6O!~$Sa9u>3#hls2jUAIzvx^(T)Ip<7afBNllcwQDgm)uh(G{XyShc8u zs01Y~M%^^-Vt_BjZi^~egfGJdi_T(%FUN#Q#ep8=O)Adw;ATr{u}u#~c@Gx#V`6tX zXKUBJFya2db^$eDCvz|hwTHh5{-vK!MGBT0-eEBDyhWe zM2BBa1teLK;<02R81zSD34o_hZOMl>xoNP$VdE8UkZz8XYWKrc_B8!FY3+Hq!GlM~ z!y~s!POe;S&0Stw$ZK2S>xvcp+hzrgMv>vQvem+z>I>a_@RG{^%X?#AtJdvh>)O+! zLwZ?c%r+!LK@@R>Xa&hD2tXq3BuddrQX~c$33R|uK4s>ODv3_VD4(E{LCQsm655O2 OL2gUd#l9a*m4tuBFR@kt delta 802 zcmY+CTSyd97{~u-c6MiX^RnAgN@!|o+NL%$yF2bYXla5M(CwmV1nH`~5(I8O71_$0GYnhWaFYiE8vEE1Vkt<`=V$iUCgWzY> zVbB7};VKx-C2PhMC%ze!Fs3;1EB;>*+w`Gl;Y1DZM6*f#jMm|fN%@RYuxip}H1Mh5 zy~#cgso~SmX3|0I<dYqfc+eoJ9 zv)v)Oi@3D3nnRXQ1Yt-}*;1Gf8dijeZj>_)zz4sfL6%e4E{QD}QKq`@WRbq3i*-iy SES;`x Date: Sun, 3 Mar 2024 13:01:00 +0900 Subject: [PATCH 3/7] Fix : Format Code --- .../AlchemySerializeGenerator.cs | 77 ++++++++----------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 16224ed..fa33747 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -26,26 +26,22 @@ public void Execute(GeneratorExecutionContext context) { foreach (var typeSyntax in receiver.TargetTypes) { - var typeSymbol = context.Compilation.GetSemanticModel(typeSyntax.SyntaxTree) - .GetDeclaredSymbol(typeSyntax); + var typeSymbol = context.Compilation.GetSemanticModel(typeSyntax.SyntaxTree).GetDeclaredSymbol(typeSyntax); if (!IsPartial(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } if (IsNested(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } var fieldSymbols = new List(); - var fields = typeSyntax.Members - .OfType(); + var fields = typeSyntax.Members.OfType(); foreach (var field in fields) { var model = context.Compilation.GetSemanticModel(field.SyntaxTree); @@ -53,26 +49,24 @@ public void Execute(GeneratorExecutionContext context) { var fieldSymbol = model.GetDeclaredSymbol(variable) as IFieldSymbol; var alchemySerializeAttribute = fieldSymbol.GetAttributes() - .FirstOrDefault(x => - x.AttributeClass.Name is "AlchemySerializeField" - or "AlchemySerializeFieldAttribute" - or "Alchemy.Serialization.AlchemySerializeField" - or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); + .FirstOrDefault(x => x.AttributeClass.Name + is "AlchemySerializeField" + or "AlchemySerializeFieldAttribute" + or "Alchemy.Serialization.AlchemySerializeField" + or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); var nonSerializedAttribute = fieldSymbol.GetAttributes() - .FirstOrDefault(x => - x.AttributeClass.Name is "NonSerialized" - or "NonSerializedAttribute" - or "System.NonSerialized" - or "System.NonSerializedAttribute"); + .FirstOrDefault(x => x.AttributeClass.Name + is "NonSerialized" + or "NonSerializedAttribute" + or "System.NonSerialized" + or "System.NonSerializedAttribute"); if (alchemySerializeAttribute != null) { if (nonSerializedAttribute == null) { - context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), - fieldSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), fieldSymbol.Name)); } fieldSymbols.Add(fieldSymbol); @@ -91,16 +85,14 @@ x.AttributeClass.Name is "NonSerialized" } catch (Exception ex) { - var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", - "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", - "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); - context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, - DiagnosticSeverity.Error)); + var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); + context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, DiagnosticSeverity.Error)); } } - static string ReplaceGenericsToCount( string typeName,int count) + + static string ReplaceGenericsToCount(string typeName, int count) { - if(count == 0) return typeName; + if (count == 0) return typeName; var builder = new StringBuilder(); bool skip = false; foreach (var c in typeName) @@ -119,6 +111,7 @@ static string ReplaceGenericsToCount( string typeName,int count) builder.Append(c); } } + return builder.ToString(); } @@ -148,19 +141,16 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field if (typeSymbol.IsGenericType) { genericsCount = typeSymbol.TypeParameters.Length; - } + var typeGenerics = typeSymbol.IsGenericType ? "<" + string.Join(", ", typeSymbol.TypeParameters.Select(x => x.Name)) + ">" : ""; - var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - .Replace("global::", "").Replace(".", "_"); - alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) + "_alchemySerializationData"; + var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat).Replace("global::", "").Replace(".", "_"); + alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName, genericsCount) + "_alchemySerializationData"; - var inheritedSerializationCallback = hasInheritedImplementation - ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" - : string.Empty; + var inheritedSerializationCallback = hasInheritedImplementation ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" : string.Empty; var hasShowSerializationData = typeSymbol.GetAttributes().Any(x => x.AttributeClass.Name is "ShowAlchemySerializationData" @@ -168,19 +158,14 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field or "Alchemy.Serialization.ShowAlchemySerializationData" or "Alchemy.Serialization.ShowAlchemySerializationDataAttribute"); - var serializationDataAttributesCode = hasShowSerializationData - ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" - : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; + var serializationDataAttributesCode = hasShowSerializationData ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; // target class namespace - var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace - ? string.Empty - : $"namespace {typeSymbol.ContainingNamespace} {{"; + var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace ? string.Empty : $"namespace {typeSymbol.ContainingNamespace} {{"; foreach (var field in fieldSymbols) { - var serializeCode = - @$"try + var serializeCode = @$"try {{ {alchemySerializationDataName}.{field.Name}.data = global::Alchemy.Serialization.Internal.SerializationHelper.ToJson(this.{field.Name} , {alchemySerializationDataName}.UnityObjectReferences); {alchemySerializationDataName}.{field.Name}.isCreated = true; @@ -190,8 +175,7 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field global::UnityEngine.Debug.LogException(ex); }}"; - var deserializeCode = - @$"try + var deserializeCode = @$"try {{ if ({alchemySerializationDataName}.{field.Name}.isCreated) {{ @@ -209,8 +193,7 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field serializationDataCodeBuilder.Append("public Item ").Append(field.Name).Append(" = new();"); } - return - @$" + return @$" // {ns} From 19e3054f3c01cd49e21aa1c8992a54054dcbb25c Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Sun, 3 Mar 2024 13:01:00 +0900 Subject: [PATCH 4/7] Fix : Format Code --- .../AlchemySerializeGenerator.cs | 94 ++++++++----------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 16224ed..8d17a6f 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -26,26 +26,22 @@ public void Execute(GeneratorExecutionContext context) { foreach (var typeSyntax in receiver.TargetTypes) { - var typeSymbol = context.Compilation.GetSemanticModel(typeSyntax.SyntaxTree) - .GetDeclaredSymbol(typeSyntax); + var typeSymbol = context.Compilation.GetSemanticModel(typeSyntax.SyntaxTree).GetDeclaredSymbol(typeSyntax); if (!IsPartial(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } if (IsNested(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } var fieldSymbols = new List(); - var fields = typeSyntax.Members - .OfType(); + var fields = typeSyntax.Members.OfType(); foreach (var field in fields) { var model = context.Compilation.GetSemanticModel(field.SyntaxTree); @@ -55,24 +51,22 @@ public void Execute(GeneratorExecutionContext context) var alchemySerializeAttribute = fieldSymbol.GetAttributes() .FirstOrDefault(x => x.AttributeClass.Name is "AlchemySerializeField" - or "AlchemySerializeFieldAttribute" - or "Alchemy.Serialization.AlchemySerializeField" - or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); + or "AlchemySerializeFieldAttribute" + or "Alchemy.Serialization.AlchemySerializeField" + or "Alchemy.Serialization.AlchemySerializeFieldAttribute"); var nonSerializedAttribute = fieldSymbol.GetAttributes() .FirstOrDefault(x => x.AttributeClass.Name is "NonSerialized" - or "NonSerializedAttribute" - or "System.NonSerialized" - or "System.NonSerializedAttribute"); + or "NonSerializedAttribute" + or "System.NonSerialized" + or "System.NonSerializedAttribute"); if (alchemySerializeAttribute != null) { if (nonSerializedAttribute == null) { - context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), - fieldSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), fieldSymbol.Name)); } fieldSymbols.Add(fieldSymbol); @@ -91,16 +85,14 @@ x.AttributeClass.Name is "NonSerialized" } catch (Exception ex) { - var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", - "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", - "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); - context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, - DiagnosticSeverity.Error)); + var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); + context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, DiagnosticSeverity.Error)); } } - static string ReplaceGenericsToCount( string typeName,int count) + + static string ReplaceGenericsToCount(string typeName, int count) { - if(count == 0) return typeName; + if (count == 0) return typeName; var builder = new StringBuilder(); bool skip = false; foreach (var c in typeName) @@ -119,6 +111,7 @@ static string ReplaceGenericsToCount( string typeName,int count) builder.Append(c); } } + return builder.ToString(); } @@ -131,11 +124,11 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field var baseType = typeSymbol.BaseType; while (baseType != null) { - if (baseType.GetAttributes().Any(x => x.AttributeClass!.Name - is "AlchemySerialize" - or "AlchemySerializeAttribute" - or "Alchemy.Serialization.AlchemySerialize" - or "Alchemy.Serialization.AlchemySerializeAttribute")) + if (baseType.GetAttributes().Any(x => + x.AttributeClass!.Name is "AlchemySerialize" + or "AlchemySerializeAttribute" + or "Alchemy.Serialization.AlchemySerialize" + or "Alchemy.Serialization.AlchemySerializeAttribute")) { hasInheritedImplementation = true; break; @@ -148,39 +141,32 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field if (typeSymbol.IsGenericType) { genericsCount = typeSymbol.TypeParameters.Length; - } + var typeGenerics = typeSymbol.IsGenericType ? "<" + string.Join(", ", typeSymbol.TypeParameters.Select(x => x.Name)) + ">" : ""; - var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - .Replace("global::", "").Replace(".", "_"); - alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) + "_alchemySerializationData"; + var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat).Replace("global::", "").Replace(".", "_"); + alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName, genericsCount) + "_alchemySerializationData"; - var inheritedSerializationCallback = hasInheritedImplementation - ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" - : string.Empty; + var inheritedSerializationCallback = hasInheritedImplementation ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" : string.Empty; - var hasShowSerializationData = typeSymbol.GetAttributes().Any(x => x.AttributeClass.Name - is "ShowAlchemySerializationData" - or "ShowAlchemySerializationDataAttribute" - or "Alchemy.Serialization.ShowAlchemySerializationData" - or "Alchemy.Serialization.ShowAlchemySerializationDataAttribute"); + var hasShowSerializationData = typeSymbol.GetAttributes().Any(x => + x.AttributeClass.Name is "ShowAlchemySerializationData" + or "ShowAlchemySerializationDataAttribute" + or "Alchemy.Serialization.ShowAlchemySerializationData" + or "Alchemy.Serialization.ShowAlchemySerializationDataAttribute"); - var serializationDataAttributesCode = hasShowSerializationData - ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" - : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; + var serializationDataAttributesCode = hasShowSerializationData ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; // target class namespace - var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace - ? string.Empty - : $"namespace {typeSymbol.ContainingNamespace} {{"; + var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace ? string.Empty : $"namespace {typeSymbol.ContainingNamespace} {{"; foreach (var field in fieldSymbols) { - var serializeCode = - @$"try + var serializeCode = +@$"try {{ {alchemySerializationDataName}.{field.Name}.data = global::Alchemy.Serialization.Internal.SerializationHelper.ToJson(this.{field.Name} , {alchemySerializationDataName}.UnityObjectReferences); {alchemySerializationDataName}.{field.Name}.isCreated = true; @@ -190,8 +176,8 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field global::UnityEngine.Debug.LogException(ex); }}"; - var deserializeCode = - @$"try + var deserializeCode = +@$"try {{ if ({alchemySerializationDataName}.{field.Name}.isCreated) {{ @@ -209,8 +195,8 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field serializationDataCodeBuilder.Append("public Item ").Append(field.Name).Append(" = new();"); } - return - @$" + return +@$" // {ns} @@ -291,7 +277,7 @@ public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { var hasAttribute = typeDeclarationSyntax.AttributeLists .SelectMany(x => x.Attributes) - .Any(x => x.Name.ToString() + .Any(x => x.Name.ToString() is "AlchemySerialize" or "AlchemySerializeAttribute" or "Alchemy.Serialization.AlchemySerialize" From d9c9f4f809230ca37b34c372fcc77e2b46d826f8 Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:29:46 +0900 Subject: [PATCH 5/7] Change: naming of generated fields and functions. --- .../AlchemySerializeGenerator.cs | 37 +++++++++--------- .../Editor/Internal/InspectorHelper.cs | 2 +- .../Generator/Alchemy.SourceGenerator.dll | Bin 18944 -> 18944 bytes .../Alchemy.SourceGenerator.dll.meta | 19 --------- 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 16224ed..5fbd1ee 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -156,12 +156,14 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) .Replace("global::", "").Replace(".", "_"); - alchemySerializationDataName = ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) + "_alchemySerializationData"; + alchemySerializationDataName ="__alchemySerializationData_"+ ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) ; - var inheritedSerializationCallback = hasInheritedImplementation - ? "base.SerializationCallback_AlchemyImpl(isBeforeSerialize);" + var inheritedOnBeforeSerialize = hasInheritedImplementation + ? "base.__AlchemyOnBeforeSerialize();" + : string.Empty; + var inheritedOnAfterDeserialize = hasInheritedImplementation + ? "base.__AlchemyOnAfterDeserialize();" : string.Empty; - var hasShowSerializationData = typeSymbol.GetAttributes().Any(x => x.AttributeClass.Name is "ShowAlchemySerializationData" or "ShowAlchemySerializationDataAttribute" @@ -218,31 +220,30 @@ partial class {typeSymbol.Name}{typeGenerics} : global::UnityEngine.ISerializati {{ void global::UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize() {{ - SerializationCallback_AlchemyImpl(false); + __AlchemyOnAfterDeserialize(); if (this is global::Alchemy.Serialization.IAlchemySerializationCallbackReceiver receiver) receiver.OnAfterDeserialize(); }} void global::UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize() {{ if (this is global::Alchemy.Serialization.IAlchemySerializationCallbackReceiver receiver) receiver.OnBeforeSerialize(); - SerializationCallback_AlchemyImpl(true); + __AlchemyOnBeforeSerialize(); }} - protected {(hasInheritedImplementation ? "new" : "")} void SerializationCallback_AlchemyImpl(bool isBeforeSerialize = false) + + protected {(hasInheritedImplementation ? "new" : "")} void __AlchemyOnAfterDeserialize() {{ - {inheritedSerializationCallback} - if (isBeforeSerialize) - {{ - {alchemySerializationDataName}.UnityObjectReferences.Clear(); - {onBeforeSerializeCodeBuilder} - - }} - else - {{ - {onAfterDeserializeCodeBuilder} - }} + {inheritedOnAfterDeserialize} + {onAfterDeserializeCodeBuilder} }} + protected {(hasInheritedImplementation ? "new" : "")} void __AlchemyOnBeforeSerialize() + {{ + {inheritedOnBeforeSerialize} + {alchemySerializationDataName}.UnityObjectReferences.Clear(); + {onBeforeSerializeCodeBuilder} + }} + [global::System.Serializable] sealed class AlchemySerializationData {{ diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs index 600a684..598d56b 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs @@ -246,7 +246,7 @@ public static VisualElement CreateMemberElement(SerializedObject serializedObjec { declaredType = declaredType.GetGenericTypeDefinition(); } - var dataName = declaredType.FullName.Replace("`","").Replace(".", "_") + "_alchemySerializationData"; + var dataName ="__alchemySerializationData_"+ declaredType.FullName.Replace("`","").Replace(".", "_") ; SerializedProperty GetProperty() => findPropertyFunc?.Invoke(dataName) .FindPropertyRelative(memberInfo.Name); diff --git a/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll b/Alchemy/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/Alchemy/Generator/Alchemy.SourceGenerator.dll.meta b/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll.meta index 823c6bd..8affc7b 100644 --- a/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll.meta +++ b/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll.meta @@ -18,21 +18,11 @@ PluginImporter: second: enabled: 0 settings: - Exclude Android: 1 Exclude Editor: 1 Exclude Linux64: 1 Exclude OSXUniversal: 1 - Exclude WebGL: 1 Exclude Win: 1 Exclude Win64: 1 - Exclude iOS: 1 - - first: - Android: Android - second: - enabled: 0 - settings: - AndroidSharedLibraryType: Executable - CPU: ARMv7 - first: Any: second: @@ -76,15 +66,6 @@ PluginImporter: enabled: 0 settings: CPU: AnyCPU - - first: - iPhone: iOS - second: - enabled: 0 - settings: - AddToEmbeddedBinaries: false - CPU: AnyCPU - CompileFlags: - FrameworkDependencies: userData: assetBundleName: assetBundleVariant: From af4832ea10818431bcc5a98ee47f3ee1d169f20b Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:48:50 +0900 Subject: [PATCH 6/7] Change: DisplayName of field with ShowAlchemySerializationData --- .../AlchemySerializeGenerator.cs | 9 ++++----- .../Generator/Alchemy.SourceGenerator.dll | Bin 18944 -> 19456 bytes .../Assets/Tests/InheritedSerializeTest.cs | 12 +++++++----- .../Tests/InheritedSerializeTestBase.cs | 3 +-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index 5fbd1ee..eac340a 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -153,9 +153,8 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field var typeGenerics = typeSymbol.IsGenericType ? "<" + string.Join(", ", typeSymbol.TypeParameters.Select(x => x.Name)) + ">" : ""; - - var alchemySerializationDataName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - .Replace("global::", "").Replace(".", "_"); + var displayName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat).Replace("global::", ""); + var alchemySerializationDataName = displayName.Replace(".", "_"); alchemySerializationDataName ="__alchemySerializationData_"+ ReplaceGenericsToCount(alchemySerializationDataName,genericsCount) ; var inheritedOnBeforeSerialize = hasInheritedImplementation @@ -171,9 +170,9 @@ static string ProcessClass(INamedTypeSymbol typeSymbol, List field or "Alchemy.Serialization.ShowAlchemySerializationDataAttribute"); var serializationDataAttributesCode = hasShowSerializationData - ? "[global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" + ? $"[global::Alchemy.Inspector.LabelText(\"Alchemy Serialization Data ({displayName})\"),global::Alchemy.Inspector.ReadOnly, global::UnityEngine.TextArea(3, 999), global::UnityEngine.SerializeField]" : "[global::UnityEngine.HideInInspector, global::UnityEngine.SerializeField]"; - + // target class namespace var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace ? string.Empty diff --git a/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll b/Alchemy/Assets/Alchemy/Generator/Alchemy.SourceGenerator.dll index 2a4effd83e2c2e884b3fb943fd81fc54a836c6d6..13908882796d10096a1758a4f7311f21aaca9b1e 100644 GIT binary patch delta 2474 zcma)84{RG(9sb_Cvwe5|6QARxv7OegQzy=nCT@}?&dOSvWKFgvTTB1IltPy{4INwS z>}barP-p70j+Sa$^&ZFpQP!*9k*HFzhZ@OU|^`aGLD0UZJn#dNI|_vs90fy_H~Pz&fR1te_;@ zWIma;+@oY~6K-Gn76t@-$qj;)MZHIEruq|=*6TEHCb7iSW)fAh#Qj)5zgQ}RZRLodrJtj$17c6QN6GYu5d(>lH5SC=WSl1sdTU_^tj!#_ow=%rA zY;Gn|ZH1kMb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z(;H6TGLU$-K^J#yWhTp44FSi%ihD>YoiTg+0k^#9pHUM$4S zyR@i&Mq?dWC0kN>4pz$7+pIA|R(%p4)LazfUxV9fLrg8gSlq`(bWb{V@BaPEmSpq2 zbQ3^Ecp_>S)ey!xEj!J8e{Dw1Ysj4AO=CSeY=!|>hJL`6i6^V3;46Sf9dnJb$+(@o zKLg)Nq_~ZE22K-K%{HTZ9@fXifcCnXan881UVS=cRABE0J2G>iHqVFs_-j}}E=G^;eS zmX^VGaabsWas$I{WLOvr2gpgZi^ypq9SD4hxQ3&HV=sJ*ib9wkfQvlx2Dg7iJOqCU zjoG*a+#p_25(zvRXKv9fQaF^$e0}h)oFWPlkn>_RN4ASP_@E%h_K7Z0f?ILcOo%bGYu}$B4j%`>y^`_Qe^u$yFr}v5oFeJEH73?fk-Z= zeY}hUMGrXxoNWdLYD5Kg#MuU9Mz|VhxyVf5AJ2+zhF73oG{clQOCdF)1$M{T5@-^W z-~eZ_^{g4Bi3a8@iZCDX~&32tc1bT*KD>CheW3-F(!wo5uE`W&m z6fA{7eHxr0&&!kOEwWO#6fr12fw)XrOJ628$`^OWD{7H*qhBUwvKJmwcjk_9XmP<(=&eo88YD&mrY!aUML7YG&*VZGo1BWw^o zkb+;z0~v4-F&ExMEQH%)!~;Gs={ztQ?1#K&%ClExBiF>_e01$(T8@+beTWYhi1#?KAKTsKI7j$U;+F_};?RuM2CMDV&~s(yB9-rV`GRTrcb8~+ z)f-FVV&k2-h>Mm@*mibZuqhb&WU^W@D-^51u$|f2ePh!}i*~d6bks8Aaba#7wBlix zKsk7!f?Iw(sA9Zs0?>g<2(b)fLTCr@m^(1mk9I4RqV0zjsQED4kNH?jJ6YF2pDm8s KX5A)zUg>Y?bkmmr diff --git a/Alchemy/Assets/Tests/InheritedSerializeTest.cs b/Alchemy/Assets/Tests/InheritedSerializeTest.cs index 864437b..c116dd1 100644 --- a/Alchemy/Assets/Tests/InheritedSerializeTest.cs +++ b/Alchemy/Assets/Tests/InheritedSerializeTest.cs @@ -1,11 +1,13 @@ using System; -using System.Collections.Generic; using Alchemy.Serialization; using UnityEngine; - -[AlchemySerialize] -public partial class InheritedSerializeTest : InheritedSerializeTestBase +namespace Test { - [AlchemySerializeField, NonSerialized] int? nullableInt; + [ShowAlchemySerializationData] + [AlchemySerialize] + public partial class InheritedSerializeTest : InheritedSerializeTestBase + { + [AlchemySerializeField, NonSerialized] int? nullableInt; + } } \ No newline at end of file diff --git a/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs index 4459c8e..f750970 100644 --- a/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs +++ b/Alchemy/Assets/Tests/InheritedSerializeTestBase.cs @@ -3,11 +3,10 @@ using Alchemy.Serialization; using UnityEngine; - +[ShowAlchemySerializationData] [AlchemySerialize] public partial class InheritedSerializeTestBase : MonoBehaviour { [AlchemySerializeField, NonSerialized] HashSet set; - } From c91f1d6e2f4ebe53ca4eb3d484e609e4617c2313 Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:01:06 +0900 Subject: [PATCH 7/7] Fix: Format --- .../AlchemySerializeGenerator.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs index eac340a..1f70e14 100644 --- a/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs +++ b/Alchemy.SourceGenerator/AlchemySerializeGenerator.cs @@ -31,15 +31,13 @@ public void Execute(GeneratorExecutionContext context) if (!IsPartial(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } if (IsNested(typeSyntax)) { - context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, - typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, typeSyntax.Identifier.GetLocation(), typeSymbol.Name)); continue; } @@ -70,9 +68,7 @@ x.AttributeClass.Name is "NonSerialized" { if (nonSerializedAttribute == null) { - context.ReportDiagnostic(Diagnostic.Create( - DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), - fieldSymbol.Name)); + context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.ShouldBeNonSerialized, variable.Identifier.GetLocation(), fieldSymbol.Name)); } fieldSymbols.Add(fieldSymbol); @@ -91,11 +87,8 @@ x.AttributeClass.Name is "NonSerialized" } catch (Exception ex) { - var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", - "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", - "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); - context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, - DiagnosticSeverity.Error)); + var diagnosticDescriptor = new DiagnosticDescriptor("AlchemySerializeGeneratorError", "AlchemySerializeGeneratorError", $"Generation failed with:\n {ex}", "AlchemySerializeGeneratorError", DiagnosticSeverity.Error, true); + context.ReportDiagnostic(Diagnostic.Create(diagnosticDescriptor, Location.None, DiagnosticSeverity.Error)); } } static string ReplaceGenericsToCount( string typeName,int count)