From 5df87996f32bc0db40cdfc525d842228ce47650d Mon Sep 17 00:00:00 2001 From: Joni Savolainen Date: Sat, 8 Oct 2022 16:28:40 +0300 Subject: [PATCH] feat: add experimental UxmlNameAttribute for generating UxmlFactory --- .../Resources/UxmlNameTestComponent.uxml | 3 + .../Resources/UxmlNameTestComponent.uxml.meta | 3 + .../Roslyn/UxmlNameTestComponent.cs | 7 + .../Roslyn/UxmlNameTestComponent.cs.meta | 3 + .../Roslyn/UxmlNameTests.cs | 23 +++ .../Roslyn/UxmlNameTests.cs.meta | 3 + .../Core/Experimental/TraitAttribute.cs | 5 +- .../Core/Experimental/UxmlNameAttribute.cs | 54 ++++++ .../Experimental/UxmlNameAttribute.cs.meta | 3 + .../Roslyn/UIComponents.Roslyn.Generation.dll | Bin 18432 -> 20992 bytes .../Resources/UxmlNameAttribute.cs | 16 ++ ....Allows_Setting_Default_Value.verified.cs} | 2 +- ...s.Allows_Specifying_Uxml_Name.verified.cs} | 2 +- ...otTests.Generates_Bool_Traits.verified.cs} | 2 +- ...es_Both_Traits_And_UxmlFactory.verified.cs | 35 ++++ ...tTests.Generates_Color_Traits.verified.cs} | 2 +- ...Tests.Generates_Double_Traits.verified.cs} | 2 +- ...Enum_Trait_With_Internal_Enum.verified.cs} | 2 +- ...otTests.Generates_Enum_Traits.verified.cs} | 2 +- ...tTests.Generates_Float_Traits.verified.cs} | 2 +- ...tTests.Generates_In_Namespace.verified.cs} | 2 +- ...hotTests.Generates_Int_Traits.verified.cs} | 2 +- ...otTests.Generates_Long_Traits.verified.cs} | 2 +- ...Tests.Generates_String_Traits.verified.cs} | 2 +- ...sses.00FirstTraitClass.Uxml.g.verified.cs} | 2 +- ...ses.01SecondTraitClass.Uxml.g.verified.cs} | 2 +- ...sses.02ThirdTraitClass.Uxml.g.verified.cs} | 2 +- ...et6_0.00FirstTraitClass.Uxml.g.received.cs | 25 +++ ...t6_0.01SecondTraitClass.Uxml.g.received.cs | 26 +++ ...et6_0.02ThirdTraitClass.Uxml.g.received.cs | 23 +++ ...ates_UxmlFactory_With_UxmlName.verified.cs | 23 +++ ..._Subclass.00MyComponent.Uxml.g.verified.cs | 1 + ...01MyComponentWithTraits.Uxml.g.verified.cs | 1 + ...DotNet6_0.00MyComponent.Uxml.g.received.cs | 23 +++ ...1MyComponentWithTraits.Uxml.g.received.cs} | 2 +- ...SnapshotTests.Handles_Subclass.verified.cs | 23 +++ ...Works_On_Non_UIComponent_Type.verified.cs} | 2 +- .../TraitDescriptionTests.cs | 2 +- .../Utilities/TraitTestFixture.cs | 4 +- ...s => UxmlAugmentGeneratorSnapshotTests.cs} | 53 ++++-- .../{Traits => Uxml}/TraitDescription.cs | 48 +++++- .../UxmlAugmentGenerator.cs} | 157 +++++++++++------- .../Generators/Uxml/UxmlFactoryInfo.cs | 25 +++ .../Readers/AttributeArgumentReader.cs | 13 +- .../Readers/ClassAttributeArgumentReader.cs | 18 ++ 45 files changed, 552 insertions(+), 102 deletions(-) create mode 100644 Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml create mode 100644 Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml.meta create mode 100644 Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs create mode 100644 Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs.meta create mode 100644 Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs create mode 100644 Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs.meta create mode 100644 Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs create mode 100644 Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs.meta create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Resources/UxmlNameAttribute.cs rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs => UxmlAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs => UxmlAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs} (94%) create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Both_Traits_And_UxmlFactory.verified.cs rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs} (94%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.UxmlTraits.g.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.Uxml.g.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.UxmlTraits.g.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.Uxml.g.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.UxmlTraits.g.verified.cs => UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.Uxml.g.verified.cs} (94%) create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.00FirstTraitClass.Uxml.g.received.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.01SecondTraitClass.Uxml.g.received.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.02ThirdTraitClass.Uxml.g.received.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_UxmlFactory_With_UxmlName.verified.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.00MyComponent.Uxml.g.verified.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.01MyComponentWithTraits.Uxml.g.verified.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.00MyComponent.Uxml.g.received.cs rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs => UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.01MyComponentWithTraits.Uxml.g.received.cs} (94%) create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/{UxmlTraitsAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs => UxmlAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs} (95%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/{UxmlTraitsAugmentGeneratorSnapshotTests.cs => UxmlAugmentGeneratorSnapshotTests.cs} (78%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/{Traits => Uxml}/TraitDescription.cs (52%) rename UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/{Traits/UxmlTraitsAugmentGenerator.cs => Uxml/UxmlAugmentGenerator.cs} (59%) create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlFactoryInfo.cs create mode 100644 UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/ClassAttributeArgumentReader.cs diff --git a/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml b/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml new file mode 100644 index 00000000..97605010 --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml @@ -0,0 +1,3 @@ + + + diff --git a/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml.meta b/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml.meta new file mode 100644 index 00000000..be1635e8 --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/Resources/UxmlNameTestComponent.uxml.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 684ff9157d7145cc94696a56cab792cf +timeCreated: 1665235071 \ No newline at end of file diff --git a/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs b/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs new file mode 100644 index 00000000..290715f2 --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs @@ -0,0 +1,7 @@ +using UIComponents.Experimental; + +namespace UIComponents.Tests.Roslyn +{ + [UxmlName("UxmlNameTest")] + public partial class UxmlNameTestComponent : UIComponent {} +} diff --git a/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs.meta b/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs.meta new file mode 100644 index 00000000..5214239c --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/UxmlNameTestComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 49129b6601cc4a05bbd28dcb661e6968 +timeCreated: 1665235018 \ No newline at end of file diff --git a/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs b/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs new file mode 100644 index 00000000..04b9547b --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UnityEngine; +using UnityEngine.UIElements; + +namespace UIComponents.Tests.Roslyn +{ + [TestFixture] + public class UxmlNameTests + { + [Test] + public void Generates_Uxml_Factory_For_Name() + { + var layout = Resources.Load("UxmlNameTestComponent"); + + var container = new VisualElement(); + layout.CloneTree(container); + + var testElement = container.Q(); + + Assert.That(testElement, Is.Not.Null); + } + } +} diff --git a/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs.meta b/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs.meta new file mode 100644 index 00000000..2314d297 --- /dev/null +++ b/Assets/UIComponents.Tests/Roslyn/UxmlNameTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f21a17c118b34cb69a213df04f10e315 +timeCreated: 1665235133 \ No newline at end of file diff --git a/Assets/UIComponents/Core/Experimental/TraitAttribute.cs b/Assets/UIComponents/Core/Experimental/TraitAttribute.cs index 0d7b7b6b..27541781 100644 --- a/Assets/UIComponents/Core/Experimental/TraitAttribute.cs +++ b/Assets/UIComponents/Core/Experimental/TraitAttribute.cs @@ -6,9 +6,8 @@ namespace UIComponents.Experimental { /// /// When used in Unity 2021.2 or later, this attribute will generate - /// UxmlTraits and UxmlFactory implementations automatically when - /// applied to a field or property which has a set method. The class - /// must be partial. + /// an UxmlTraits implementation when applied to a field or property + /// which has a set method. The class must be partial. /// /// /// diff --git a/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs b/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs new file mode 100644 index 00000000..af92830a --- /dev/null +++ b/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics; +using JetBrains.Annotations; +using UnityEngine.TestTools; +using UnityEngine.UIElements; + +namespace UIComponents.Experimental +{ + /// + /// When used in Unity 2021.2 or later, this attribute will generate + /// a UxmlFactory implementation automatically when + /// applied to a partial class. + /// + /// + /// + /// [UxmlName("ListHeader")] + /// public partial class ListHeaderComponent : UIComponent {} + /// + /// // This generates: + /// + /// public partial class ListHeaderComponent + /// { + /// public new class UxmlFactory : UxmlFactory<ListHeaderComponent> + /// { + /// public override string uxmlName + /// { + /// get { return "ListHeader"; } + /// } + /// + /// public override string uxmlQualifiedName + /// { + /// get { return uxmlNamespace + "." + uxmlName; } + /// } + /// } + /// } + /// + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + [Conditional("UNITY_EDITOR")] + [BaseTypeRequired(typeof(VisualElement))] + [ExcludeFromCoverage] + public sealed class UxmlNameAttribute : Attribute + { + /// + /// The custom UXML name. + /// + public readonly string Name; + + public UxmlNameAttribute(string name) + { + Name = name; + } + } +} diff --git a/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs.meta b/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs.meta new file mode 100644 index 00000000..78b6ddd9 --- /dev/null +++ b/Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4c9fb6b9621c4989915e39dd5001ab37 +timeCreated: 1665234605 \ No newline at end of file diff --git a/Assets/UIComponents/Roslyn/UIComponents.Roslyn.Generation.dll b/Assets/UIComponents/Roslyn/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47!UB(1208zD6n>+c=YB9fmoK2Vt)1%J5@>IKvhd@<(yBSJ*V|6GQDEW&F0W>us^{xS(acgFfc#g+lvPr}?` zv`=uW{vC|=9^p9q@@yE-NPJm@9da*rnCTrNjV<5hAQ)BUS;FXZsyf-8isJx5HUImFYNXW}JX7Mp(KT>;1XKgzL19u52?b z8IF}`W^5_Xz*1$nQo#wx1xMXC!F{4NUeU%`inc+8F!;J4M%6bd3@qB$$RePV+~2j9 z2*WknYQ{F1Wz0I;BrS}`ASnTPeow;rbs{?7o!vG*{TpyEw_?n}_&MxM!}AiG7;8bQ z-V?F)_(6Src0RHLMK28BQ|>)D!bUiZs#C_1o71fGRJo&P=cWx2YY(Yu@k*+cbW~A0 zPas_P9z^y8j9`kQ^E)k=VROekYpPMPHpixoh!r*OO`JEK8B@nH{kX$WU=7DIkqz0( zdOjAgxK!SQ-{^cRgBc{kqr>j0*;VeGIcJFZ?#4L{5wARk7NGm%IfX%9ipM;`VfXzx zh3ET8i_XV*!r=^dEF8`&(_oipVL0HE;h>sote69E9RT6YSZryiOv~V02?P7)&Jy?? z4xW@ cC6*6#%>Rz&U+DdZhZoNoh%Wr2=$~l)3y2%EH~;_u diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Resources/UxmlNameAttribute.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Resources/UxmlNameAttribute.cs new file mode 100644 index 00000000..8c4c9172 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Resources/UxmlNameAttribute.cs @@ -0,0 +1,16 @@ +using System.Diagnostics.CodeAnalysis; + +namespace UIComponents.Experimental +{ + [ExcludeFromCodeCoverage] + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] + public sealed class UxmlNameAttribute : Attribute + { + public readonly string Name; + + public UxmlNameAttribute(string name) + { + Name = name; + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs index c76d1221..e6bb9460 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Setting_Default_Value.verified.cs @@ -1,4 +1,4 @@ -//HintName: ComponentWithDefaultValueTraits.UxmlTraits.g.cs +//HintName: ComponentWithDefaultValueTraits.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs index d50423bd..bf141258 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Allows_Specifying_Uxml_Name.verified.cs @@ -1,4 +1,4 @@ -//HintName: CustomNamespaceComponent.UxmlTraits.g.cs +//HintName: CustomNamespaceComponent.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs index 75d727a6..e7fe53a0 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Bool_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: BoolComponentWithUsing.UxmlTraits.g.cs +//HintName: BoolComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Both_Traits_And_UxmlFactory.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Both_Traits_And_UxmlFactory.verified.cs new file mode 100644 index 00000000..f9a85353 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Both_Traits_And_UxmlFactory.verified.cs @@ -0,0 +1,35 @@ +//HintName: ComponentWithUxmlNameAndTraits.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class ComponentWithUxmlNameAndTraits +{ + public new partial class UxmlFactory : UxmlFactory + { + public override string uxmlName + { + get { return "AwesomeUxmlName"; } + } + + public override string uxmlQualifiedName + { + get { return uxmlNamespace + "." + uxmlName; } + } + } + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlBoolAttributeDescription m_Value = new UxmlBoolAttributeDescription { name = "value" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + m_Value.defaultValue = true; + ((ComponentWithUxmlNameAndTraits)ve).Value = m_Value.GetValueFromBag(bag, cc); + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs index 67211327..99fb998e 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Color_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: ColorComponentWithUsing.UxmlTraits.g.cs +//HintName: ColorComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs index 1eedbf10..eb10695b 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Double_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: DoubleComponentWithUsing.UxmlTraits.g.cs +//HintName: DoubleComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs index 2bf17593..4a5ab4f2 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Trait_With_Internal_Enum.verified.cs @@ -1,4 +1,4 @@ -//HintName: OwnEnumComponent.UxmlTraits.g.cs +//HintName: OwnEnumComponent.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs index 9e881cba..1c18c837 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Enum_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: MyEnumComponentWithUsing.UxmlTraits.g.cs +//HintName: MyEnumComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs index f71eaa7d..9462f603 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Float_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: FloatComponentWithUsing.UxmlTraits.g.cs +//HintName: FloatComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs index 2f7d3c84..3f6c4775 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_In_Namespace.verified.cs @@ -1,4 +1,4 @@ -//HintName: CustomNamespaceComponent.UxmlTraits.g.cs +//HintName: CustomNamespaceComponent.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs index 41867a5f..e3ccb2a8 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Int_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: IntComponentWithUsing.UxmlTraits.g.cs +//HintName: IntComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs index c60050ed..ee5adbb3 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Long_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: LongComponentWithUsing.UxmlTraits.g.cs +//HintName: LongComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs index a8deaa49..8fb1b1a9 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_String_Traits.verified.cs @@ -1,4 +1,4 @@ -//HintName: StringComponentWithUsing.UxmlTraits.g.cs +//HintName: StringComponentWithUsing.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.UxmlTraits.g.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.Uxml.g.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.UxmlTraits.g.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.Uxml.g.verified.cs index 36fa3680..1de2a2b6 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.UxmlTraits.g.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.00FirstTraitClass.Uxml.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: FirstTraitClass.UxmlTraits.g.cs +//HintName: FirstTraitClass.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.UxmlTraits.g.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.Uxml.g.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.UxmlTraits.g.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.Uxml.g.verified.cs index 5ec31c8a..5860e844 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.UxmlTraits.g.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.01SecondTraitClass.Uxml.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: SecondTraitClass.UxmlTraits.g.cs +//HintName: SecondTraitClass.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.UxmlTraits.g.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.Uxml.g.verified.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.UxmlTraits.g.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.Uxml.g.verified.cs index 116a723c..990c9866 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.UxmlTraits.g.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.02ThirdTraitClass.Uxml.g.verified.cs @@ -1,4 +1,4 @@ -//HintName: ThirdTraitClass.UxmlTraits.g.cs +//HintName: ThirdTraitClass.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.00FirstTraitClass.Uxml.g.received.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.00FirstTraitClass.Uxml.g.received.cs new file mode 100644 index 00000000..f9ee5c8b --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.00FirstTraitClass.Uxml.g.received.cs @@ -0,0 +1,25 @@ +//HintName: FirstTraitClass.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class FirstTraitClass +{ + public new partial class UxmlFactory : UxmlFactory {} + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlIntAttributeDescription m_FieldTrait = new UxmlIntAttributeDescription { name = "custom-trait-name" }; + UxmlFloatAttributeDescription m_PropertyTrait = new UxmlFloatAttributeDescription { name = "my-property" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + ((FirstTraitClass)ve).FieldTrait = m_FieldTrait.GetValueFromBag(bag, cc); + ((FirstTraitClass)ve).PropertyTrait = m_PropertyTrait.GetValueFromBag(bag, cc); + } + } + } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.01SecondTraitClass.Uxml.g.received.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.01SecondTraitClass.Uxml.g.received.cs new file mode 100644 index 00000000..977954c0 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.01SecondTraitClass.Uxml.g.received.cs @@ -0,0 +1,26 @@ +//HintName: SecondTraitClass.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class SecondTraitClass +{ + public new partial class UxmlFactory : UxmlFactory {} + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlBoolAttributeDescription m_Enabled = new UxmlBoolAttributeDescription { name = "enabled" }; + UxmlLongAttributeDescription m_SomeValue = new UxmlLongAttributeDescription { name = "secret" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + m_Enabled.defaultValue = true; + ((SecondTraitClass)ve).Enabled = m_Enabled.GetValueFromBag(bag, cc); + ((SecondTraitClass)ve).SomeValue = m_SomeValue.GetValueFromBag(bag, cc); + } + } + } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.02ThirdTraitClass.Uxml.g.received.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.02ThirdTraitClass.Uxml.g.received.cs new file mode 100644 index 00000000..8434ad46 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_Traits_For_Many_Classes.DotNet6_0.02ThirdTraitClass.Uxml.g.received.cs @@ -0,0 +1,23 @@ +//HintName: ThirdTraitClass.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class ThirdTraitClass +{ + public new partial class UxmlFactory : UxmlFactory {} + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlStringAttributeDescription m_Name = new UxmlStringAttributeDescription { name = "name" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + ((ThirdTraitClass)ve).Name = m_Name.GetValueFromBag(bag, cc); + } + } + } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_UxmlFactory_With_UxmlName.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_UxmlFactory_With_UxmlName.verified.cs new file mode 100644 index 00000000..33d1a646 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Generates_UxmlFactory_With_UxmlName.verified.cs @@ -0,0 +1,23 @@ +//HintName: MyUxmlNameAttributeComponent.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class MyUxmlNameAttributeComponent +{ + public new partial class UxmlFactory : UxmlFactory + { + public override string uxmlName + { + get { return "MyUxmlNameAttribute"; } + } + + public override string uxmlQualifiedName + { + get { return uxmlNamespace + "." + uxmlName; } + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.00MyComponent.Uxml.g.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.00MyComponent.Uxml.g.verified.cs new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.00MyComponent.Uxml.g.verified.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.01MyComponentWithTraits.Uxml.g.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.01MyComponentWithTraits.Uxml.g.verified.cs new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.01MyComponentWithTraits.Uxml.g.verified.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.00MyComponent.Uxml.g.received.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.00MyComponent.Uxml.g.received.cs new file mode 100644 index 00000000..0a91a99c --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.00MyComponent.Uxml.g.received.cs @@ -0,0 +1,23 @@ +//HintName: MyComponent.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class MyComponent +{ + public new partial class UxmlFactory : UxmlFactory {} + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlDoubleAttributeDescription m_Trait = new UxmlDoubleAttributeDescription { name = "double-value" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + ((MyComponent)ve).Trait = m_Trait.GetValueFromBag(bag, cc); + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.01MyComponentWithTraits.Uxml.g.received.cs similarity index 94% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.01MyComponentWithTraits.Uxml.g.received.cs index c2ad63a3..63e147cd 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.DotNet6_0.01MyComponentWithTraits.Uxml.g.received.cs @@ -1,4 +1,4 @@ -//HintName: MyComponentWithTraits.UxmlTraits.g.cs +//HintName: MyComponentWithTraits.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs new file mode 100644 index 00000000..74876a8e --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Handles_Subclass.verified.cs @@ -0,0 +1,23 @@ +//HintName: MyComponentWithTraits.Uxml.g.cs +// +// This file has been generated automatically by UIComponents.Roslyn. +// Do not attempt to modify it. Any changes will be overridden during compilation. +// + +using UnityEngine.UIElements; + +public partial class MyComponentWithTraits +{ + public new partial class UxmlFactory : UxmlFactory {} + + public new partial class UxmlTraits : VisualElement.UxmlTraits + { + UxmlDoubleAttributeDescription m_Trait = new UxmlDoubleAttributeDescription { name = "double-value" }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + ((MyComponentWithTraits)ve).Trait = m_Trait.GetValueFromBag(bag, cc); + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs similarity index 95% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs index 025b7f9a..4ce06d4f 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlTraitsAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Snapshots/UxmlAugmentGeneratorSnapshotTests.Works_On_Non_UIComponent_Type.verified.cs @@ -1,4 +1,4 @@ -//HintName: NonUIComponentClass.UxmlTraits.g.cs +//HintName: NonUIComponentClass.Uxml.g.cs // // This file has been generated automatically by UIComponents.Roslyn. // Do not attempt to modify it. Any changes will be overridden during compilation. diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/TraitDescriptionTests.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/TraitDescriptionTests.cs index ef636a2b..9b27c895 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/TraitDescriptionTests.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/TraitDescriptionTests.cs @@ -1,6 +1,6 @@ using Microsoft.CodeAnalysis; using NSubstitute; -using UIComponents.Roslyn.Generation.Generators.Traits; +using UIComponents.Roslyn.Generation.Generators.Uxml; namespace UIComponents.Roslyn.Generation.Tests { diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Utilities/TraitTestFixture.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Utilities/TraitTestFixture.cs index c272639d..f45fa573 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Utilities/TraitTestFixture.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Utilities/TraitTestFixture.cs @@ -1,4 +1,4 @@ -using UIComponents.Roslyn.Generation.Generators.Traits; +using UIComponents.Roslyn.Generation.Generators.Uxml; namespace UIComponents.Roslyn.Generation.Tests.Utilities { @@ -26,7 +26,7 @@ public partial class {fieldTypeNameCap}ComponentWithUsing : UIComponent if (useUnityEngine) source = "using UnityEngine;\r\n" + source; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } } } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlTraitsAugmentGeneratorSnapshotTests.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlAugmentGeneratorSnapshotTests.cs similarity index 78% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlTraitsAugmentGeneratorSnapshotTests.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlAugmentGeneratorSnapshotTests.cs index 69fa49b1..1ee57798 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlTraitsAugmentGeneratorSnapshotTests.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/UxmlAugmentGeneratorSnapshotTests.cs @@ -1,5 +1,5 @@ using Microsoft.CodeAnalysis.CSharp; -using UIComponents.Roslyn.Generation.Generators.Traits; +using UIComponents.Roslyn.Generation.Generators.Uxml; using UIComponents.Roslyn.Generation.Tests.Utilities; namespace UnityEngine @@ -18,7 +18,7 @@ public enum MyEnum namespace UIComponents.Roslyn.Generation.Tests { [UsesVerify] - public class UxmlTraitsAugmentGeneratorSnapshotTests : TraitTestFixture + public class UxmlAugmentGeneratorSnapshotTests : TraitTestFixture { [Fact] public Task Generates_String_Traits() @@ -86,7 +86,7 @@ public class Test syntaxTrees: new[] { syntaxTree } ); - var generator = new UxmlTraitsAugmentGenerator(); + var generator = new UxmlAugmentGenerator(); var driver = CSharpGeneratorDriver.Create(generator).RunGenerators(compilation); @@ -111,7 +111,7 @@ public partial class NonUIComponentClass public bool PropertyWithoutSetter { get; } }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -139,7 +139,7 @@ public enum OwnEnum public OwnEnum PropertyWithoutSetter { get; } }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -173,7 +173,7 @@ public enum OwnEnum } }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -195,7 +195,7 @@ public partial class CustomNamespaceComponent : UIComponent public bool PropertyWithoutSetter { get; } }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -213,7 +213,7 @@ public partial class MyComponentWithTraits : MyComponent public double Trait; }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -244,7 +244,7 @@ public partial class ComponentWithDefaultValueTraits : UIComponent public Some.Place.Where.Enum.Is.TheEnum MyValue; }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); } [Fact] @@ -278,7 +278,40 @@ public partial class ThirdTraitClass public string Name; }"; - return GeneratorTester.Verify(source); + return GeneratorTester.Verify(source); + } + + [Fact] + public Task Generates_UxmlFactory_With_UxmlName() + { + var source = @" +using UIComponents; +using UIComponents.Experimental; + +[UxmlName(""MyUxmlNameAttribute"")] +public partial class MyUxmlNameAttributeComponent : UIComponent +{ + +} +"; + return GeneratorTester.Verify(source); + } + + [Fact] + public Task Generates_Both_Traits_And_UxmlFactory() + { + var source = @" +using UIComponents; +using UIComponents.Experimental; + +[UxmlName(""AwesomeUxmlName"")] +public partial class ComponentWithUxmlNameAndTraits : UIComponent +{ + [Trait(DefaultValue = true)] + public bool Value; +} +"; + return GeneratorTester.Verify(source); } } } \ No newline at end of file diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/TraitDescription.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/TraitDescription.cs similarity index 52% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/TraitDescription.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/TraitDescription.cs index c8d61074..dd76f93c 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/TraitDescription.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/TraitDescription.cs @@ -1,7 +1,8 @@ using Microsoft.CodeAnalysis; using System; +using System.Collections.Generic; -namespace UIComponents.Roslyn.Generation.Generators.Traits +namespace UIComponents.Roslyn.Generation.Generators.Uxml { internal readonly struct TraitDescription { @@ -11,6 +12,9 @@ internal readonly struct TraitDescription public readonly string Type; public readonly string DefaultValue; + private const string NameArgumentName = "Name"; + private const string DefaultValueArgumentName = "DefaultValue"; + public TraitDescription(string classMemberName, string uxmlName, INamedTypeSymbol typeSymbol, string defaultValue = null) { ClassMemberName = classMemberName; @@ -49,13 +53,49 @@ public TraitDescription(string classMemberName, string uxmlName, INamedTypeSymbo } } - public static TraitDescription CreateFromFieldSymbol(IFieldSymbol typeSymbol, string uxmlName, string defaultValue) + private static (string, string) GetTraitUxmlNameAndDefaultValue( + Dictionary traitArguments, + ITypeSymbol typeSymbol, + string memberName) + { + string uxmlName = null; + string defaultValue = null; + + if (traitArguments.ContainsKey(NameArgumentName)) + uxmlName = traitArguments[NameArgumentName].Value?.ToString(); + + if (string.IsNullOrEmpty(uxmlName)) + uxmlName = memberName.ToLower(); + + if (traitArguments.ContainsKey(DefaultValueArgumentName)) + { + var defaultValueString = traitArguments[DefaultValueArgumentName].Value?.ToString(); + + var defaultValueObject = traitArguments[DefaultValueArgumentName].Value; + + if (!string.IsNullOrEmpty(defaultValueString) && defaultValueObject is string) + defaultValueString = $"\"{defaultValueString}\""; + if (!string.IsNullOrEmpty(defaultValueString) && defaultValueObject is bool) + defaultValueString = defaultValueString.ToLower(); + if (!string.IsNullOrEmpty(defaultValueString) && typeSymbol.TypeKind == TypeKind.Enum) + defaultValueString = $"({typeSymbol.ToDisplayString()}) {defaultValueString}"; + defaultValue = defaultValueString; + } + + return (uxmlName, defaultValue); + } + + public static TraitDescription CreateFromFieldSymbol(IFieldSymbol typeSymbol, Dictionary arguments) { - return new TraitDescription(typeSymbol.Name, uxmlName, (INamedTypeSymbol) typeSymbol.Type, defaultValue); + var (uxmlName, defaultValue) = GetTraitUxmlNameAndDefaultValue(arguments, typeSymbol.Type, typeSymbol.Name); + + return new TraitDescription(typeSymbol.Name, uxmlName, (INamedTypeSymbol)typeSymbol.Type, defaultValue); } - public static TraitDescription CreateFromPropertySymbol(IPropertySymbol propertySymbol, string uxmlName, string defaultValue) + public static TraitDescription CreateFromPropertySymbol(IPropertySymbol propertySymbol, Dictionary arguments) { + var (uxmlName, defaultValue) = GetTraitUxmlNameAndDefaultValue(arguments, propertySymbol.Type, propertySymbol.Name); + return new TraitDescription(propertySymbol.Name, uxmlName, (INamedTypeSymbol)propertySymbol.Type, defaultValue); } } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/UxmlTraitsAugmentGenerator.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlAugmentGenerator.cs similarity index 59% rename from UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/UxmlTraitsAugmentGenerator.cs rename to UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlAugmentGenerator.cs index 642f184f..9854c5c8 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Traits/UxmlTraitsAugmentGenerator.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlAugmentGenerator.cs @@ -7,67 +7,56 @@ using UIComponents.Roslyn.Generation.Readers; using UIComponents.Roslyn.Generation.SyntaxReceivers; -namespace UIComponents.Roslyn.Generation.Generators.Traits +namespace UIComponents.Roslyn.Generation.Generators.Uxml { /// - /// A generator for TraitAttribute. Generates a UxmlFactory and UxmlTraits implementation. + /// A generator for TraitAttribute and UxmlNameAttribute. + /// Generates UxmlFactory and UxmlTraits implementations. /// [Generator] - internal class UxmlTraitsAugmentGenerator : AugmentGenerator + internal class UxmlAugmentGenerator : AugmentGenerator { private INamedTypeSymbol _traitAttributeSymbol; + private INamedTypeSymbol _uxmlNameAttributeSymbol; private readonly List _traitsToGenerate = new List(); + private UxmlFactoryInfo _uxmlFactoryInfo; protected override void OnBeforeExecute(GeneratorExecutionContext context) { _traitAttributeSymbol = context.Compilation.GetTypeByMetadataName("UIComponents.Experimental.TraitAttribute"); + _uxmlNameAttributeSymbol = + context.Compilation.GetTypeByMetadataName("UIComponents.Experimental.UxmlNameAttribute"); } protected override bool ShouldGenerateSource(AugmentGenerationContext context) { - if (_traitAttributeSymbol == null) + if (_traitAttributeSymbol == null || _uxmlNameAttributeSymbol == null) return false; _traitsToGenerate.Clear(); GetTraitFields(context, _traitsToGenerate); GetTraitProperties(context, _traitsToGenerate); + _uxmlFactoryInfo = GetUxmlFactoryInfo(context); - return _traitsToGenerate.Count > 0; + return _traitsToGenerate.Count > 0 || !string.IsNullOrEmpty(_uxmlFactoryInfo.Name); } - private (string, string) GetTraitUxmlNameAndDefaultValue( - Dictionary traitArguments, - ITypeSymbol typeSymbol, - string memberName) + private void ReadAttributeArguments( + TSyntax syntax, + AttributeArgumentReader attributeArgumentReader, + SemanticModel classSemanticModel, + Dictionary> output + ) + where TSyntax : SyntaxNode + where TSymbol : class, ISymbol { - string uxmlName = null; - string defaultValue = null; - - if (traitArguments.ContainsKey("Name")) - uxmlName = traitArguments["Name"].Value?.ToString(); - - if (string.IsNullOrEmpty(uxmlName)) - uxmlName = memberName.ToLower(); - - if (traitArguments.ContainsKey("DefaultValue")) - { - var defaultValueString = traitArguments["DefaultValue"].Value?.ToString(); - - var defaultValueObject = traitArguments["DefaultValue"].Value; - - if (!string.IsNullOrEmpty(defaultValueString) && defaultValueObject is string) - defaultValueString = $"\"{defaultValueString}\""; - if (!string.IsNullOrEmpty(defaultValueString) && defaultValueObject is bool) - defaultValueString = defaultValueString.ToLower(); - if (!string.IsNullOrEmpty(defaultValueString) && typeSymbol.TypeKind == TypeKind.Enum) - defaultValueString = $"({typeSymbol.ToDisplayString()}) {defaultValueString}"; - defaultValue = defaultValueString; - } - - return (uxmlName, defaultValue); + var arguments = new Dictionary(); + attributeArgumentReader.Read(syntax, arguments); + var fieldSymbol = classSemanticModel.GetDeclaredSymbol(syntax) as TSymbol; + output.Add(fieldSymbol, arguments); } private void GetTraitFields(AugmentGenerationContext context, IList traits) @@ -92,21 +81,11 @@ private void GetTraitFields(AugmentGenerationContext context, IList(); - variableAttributeArgumentReader.Read(variableDeclaration, arguments); - var fieldSymbol = context.ClassSemanticModel.GetDeclaredSymbol(variableDeclaration) as IFieldSymbol; - traitArguments.Add(fieldSymbol, arguments); - } + ReadAttributeArguments(variableDeclaration, variableAttributeArgumentReader, context.ClassSemanticModel, traitArguments); } foreach (var traitField in traitFields) - { - var arguments = traitArguments[traitField]; - var (uxmlName, defaultValue) = GetTraitUxmlNameAndDefaultValue(arguments, traitField.Type, traitField.Name); - - traits.Add(TraitDescription.CreateFromFieldSymbol(traitField, uxmlName, defaultValue)); - } + traits.Add(TraitDescription.CreateFromFieldSymbol(traitField, traitArguments[traitField])); } private void GetTraitProperties(AugmentGenerationContext context, IList traits) @@ -129,19 +108,60 @@ private void GetTraitProperties(AugmentGenerationContext context, IList(); - propertyAttributeArgumentReader.Read(propertyDeclaration, arguments); - var propertySymbol = context.ClassSemanticModel.GetDeclaredSymbol(propertyDeclaration) as IPropertySymbol; - traitArguments.Add(propertySymbol, arguments); + ReadAttributeArguments(propertyDeclaration, propertyAttributeArgumentReader, context.ClassSemanticModel, traitArguments); } foreach (var traitProperty in traitProperties) - { - var arguments = traitArguments[traitProperty]; - var (uxmlName, defaultValue) = GetTraitUxmlNameAndDefaultValue(arguments, traitProperty.Type, traitProperty.Name); + traits.Add(TraitDescription.CreateFromPropertySymbol(traitProperty, traitArguments[traitProperty])); + } + + private UxmlFactoryInfo GetUxmlFactoryInfo(AugmentGenerationContext context) + { + var arguments = new Dictionary(); + var classAttributeArgumentReader = new ClassAttributeArgumentReader(_uxmlNameAttributeSymbol, context.ClassSemanticModel); + + classAttributeArgumentReader.Read(context.ClassSyntax, arguments); + + if (arguments.Count == 0) + return default; + + return UxmlFactoryInfo.CreateFromArguments(arguments); + } + + private void WriteUxmlFactory(UxmlFactoryInfo info, AugmentGenerationContext context, StringBuilder stringBuilder) + { + var compilation = context.GeneratorExecutionContext.Compilation; + var uxmlTraitsMetadataName = $"{context.CurrentTypeSymbol.MetadataName}.UxmlTraits"; + + var traitsDefined = _traitsToGenerate.Count > 0 || + compilation.GetTypeByMetadataName(uxmlTraitsMetadataName) != null; + + stringBuilder.Append(" ") + .Append($"public new partial class UxmlFactory : UxmlFactory<{context.TypeName}"); - traits.Add(TraitDescription.CreateFromPropertySymbol(traitProperty, uxmlName, defaultValue)); + if (traitsDefined) + stringBuilder.Append(", UxmlTraits>"); + else + stringBuilder.Append(">"); + + if (string.IsNullOrEmpty(info.Name)) + { + stringBuilder.AppendLine(" {}"); + return; } + + stringBuilder.AppendLine($@" + {{ + public override string uxmlName + {{ + get {{ return ""{info.Name}""; }} + }} + + public override string uxmlQualifiedName + {{ + get {{ return uxmlNamespace + ""."" + uxmlName; }} + }} + }}"); } private void WriteTraitDescriptionVariables(List traits, StringBuilder stringBuilder) @@ -177,14 +197,12 @@ private void WriteTraitDescriptionInitialization(List traits, } } - protected override void GenerateSource(AugmentGenerationContext context, StringBuilder stringBuilder) + private void WriteUxmlTraits(List traits, AugmentGenerationContext context, StringBuilder stringBuilder) { - stringBuilder.AppendLine("using UnityEngine.UIElements;").AppendLine(); - - stringBuilder.AppendLine($@"public partial class {context.TypeName} -{{ - public new partial class UxmlFactory : UxmlFactory<{context.TypeName}, UxmlTraits> {{}} + if (traits.Count == 0) + return; + stringBuilder.AppendLine($@" public new partial class UxmlTraits : VisualElement.UxmlTraits {{"); WriteTraitDescriptionVariables(_traitsToGenerate, stringBuilder); @@ -198,13 +216,26 @@ public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext WriteTraitDescriptionInitialization(_traitsToGenerate, context, stringBuilder); stringBuilder.Append(" ").AppendLine($@"}} - }} -}}"); + }}"); + } + + protected override void GenerateSource(AugmentGenerationContext context, StringBuilder stringBuilder) + { + stringBuilder.AppendLine("using UnityEngine.UIElements;").AppendLine(); + + stringBuilder.AppendLine($@"public partial class {context.TypeName} +{{"); + + WriteUxmlFactory(_uxmlFactoryInfo, context, stringBuilder); + + WriteUxmlTraits(_traitsToGenerate, context, stringBuilder); + + stringBuilder.AppendLine("}"); } protected override string GetHintPostfix() { - return "UxmlTraits"; + return "Uxml"; } } } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlFactoryInfo.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlFactoryInfo.cs new file mode 100644 index 00000000..b33084d4 --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Generators/Uxml/UxmlFactoryInfo.cs @@ -0,0 +1,25 @@ +using Microsoft.CodeAnalysis; +using System.Collections.Generic; + +namespace UIComponents.Roslyn.Generation.Generators.Uxml +{ + internal readonly struct UxmlFactoryInfo + { + public readonly string Name; + + public UxmlFactoryInfo(string name) + { + Name = name; + } + + public static UxmlFactoryInfo CreateFromArguments(Dictionary arguments) + { + string name = null; + + if (arguments.TryGetValue("constructor_0", out var nameArg)) + name = nameArg.Value as string; + + return new UxmlFactoryInfo(name); + } + } +} diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/AttributeArgumentReader.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/AttributeArgumentReader.cs index de8a8b47..3a37b8ee 100644 --- a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/AttributeArgumentReader.cs +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/AttributeArgumentReader.cs @@ -11,11 +11,20 @@ public AttributeArgumentReader(INamedTypeSymbol attributeSymbol, SemanticModel s protected void GetArgumentsOfSymbol(ISymbol symbol, Dictionary arguments) { - var fieldAttributes = symbol.GetAttributes().Where(NodeHasDesiredAttribute); + var allAttributes = symbol.GetAttributes(); + var attributes = allAttributes.Where(NodeHasDesiredAttribute); + + foreach (var attribute in attributes) + { + var constructorArgs = attribute.ConstructorArguments; + + for (var i = 0; i < constructorArgs.Length; i++) + arguments.Add($"constructor_{i}", constructorArgs[i]); - foreach (var attribute in fieldAttributes) foreach (var argument in attribute.NamedArguments) arguments.Add(argument.Key, argument.Value); + } + } } } diff --git a/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/ClassAttributeArgumentReader.cs b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/ClassAttributeArgumentReader.cs new file mode 100644 index 00000000..b943481c --- /dev/null +++ b/UIComponents.Roslyn/UIComponents.Roslyn.Generation/Readers/ClassAttributeArgumentReader.cs @@ -0,0 +1,18 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; + +namespace UIComponents.Roslyn.Generation.Readers +{ + internal class ClassAttributeArgumentReader : AttributeArgumentReader + { + public ClassAttributeArgumentReader(INamedTypeSymbol attributeSymbol, SemanticModel semanticModel) : base(attributeSymbol, semanticModel) {} + + public override void Read(ClassDeclarationSyntax syntaxNode, Dictionary output) + { + var fieldSymbol = SemanticModel.GetDeclaredSymbol(syntaxNode) as INamedTypeSymbol; + + GetArgumentsOfSymbol(fieldSymbol, output); + } + } +}