Skip to content

Commit

Permalink
feat: rename TraitAttribute to UxmlTraitAttribute
Browse files Browse the repository at this point in the history
BREAKING CHANGE: TraitAttribute has been renamed to UxmlTraitAttribute.
  • Loading branch information
jonisavo committed Oct 18, 2022
1 parent ae18491 commit da47d4c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class NestParentClass
[UxmlName("NestedRoslynTest")]
public partial class NestedRoslynTestComponent : UIComponent
{
[Trait]
[UxmlTrait]
public string Trait { get; set; }
}
}
Expand Down
8 changes: 4 additions & 4 deletions Assets/UIComponents.Tests/Roslyn/RoslynTestComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public enum Greetings
Morning
}

[Trait(Name = "text-color")]
[UxmlTrait(Name = "text-color")]
public Color TextColor;

[Trait(Name = "current-time")]
[UxmlTrait(Name = "current-time")]
public double CurrentTime;

[Trait(DefaultValue = Greetings.Morning)]
[UxmlTrait(DefaultValue = Greetings.Morning)]
public Greetings Greeting;

[Trait(DefaultValue = true)]
[UxmlTrait(DefaultValue = true)]
public bool Enabled;
}
}
8 changes: 4 additions & 4 deletions Assets/UIComponents.Tests/Roslyn/RoslynTestVisualElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace UIComponents.Tests.Roslyn
{
public partial class RoslynTestVisualElement : VisualElement
{
[Trait(DefaultValue = "None set")]
[UxmlTrait(DefaultValue = "None set")]
public string Description;

[Trait]
[UxmlTrait]
public int Age;

[Trait(Name = "unix-timestamp")]
[UxmlTrait(Name = "unix-timestamp")]
public long UnixTimestamp;

[Trait(Name = "music-volume", DefaultValue = 1.0f)]
[UxmlTrait(Name = "music-volume", DefaultValue = 1.0f)]
public float MusicVolume { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UIComponents.Tests.Roslyn
{
[TestFixture]
public class TraitTests
public class UxmlTraitTests
{
[Test]
public void Generates_Traits_For_Non_UIComponent_Class()
Expand Down
2 changes: 1 addition & 1 deletion Assets/UIComponents/Core/Experimental/UxmlNameAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace UIComponents.Experimental
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[Conditional("UNITY_EDITOR")]
[Conditional("UICOMPONENTS_INCLUDE_ATTRIBUTES")]
[BaseTypeRequired(typeof(VisualElement))]
[ExcludeFromCoverage]
public sealed class UxmlNameAttribute : Attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace UIComponents.Experimental
/// <code>
/// public partial class MyComponent : UIComponent
/// {
/// [Trait]
/// [UxmlTrait]
/// public string Description;
///
/// [Trait(Name = "a-color")]
/// [UxmlTrait(Name = "a-color")]
/// public Color Color;
///
/// [Trait(DefaultValue = 3)]
/// [UxmlTrait(DefaultValue = 3)]
/// public int Lives;
/// }
///
Expand Down Expand Up @@ -48,9 +48,9 @@ namespace UIComponents.Experimental
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[Conditional("UNITY_EDITOR")]
[Conditional("UICOMPONENTS_INCLUDE_ATTRIBUTES")]
[ExcludeFromCoverage]
public sealed class TraitAttribute : Attribute
public sealed class UxmlTraitAttribute : Attribute
{
/// <summary>
/// Defines a custom UXML name for the trait.
Expand Down
Binary file modified Assets/UIComponents/Roslyn/UIComponents.Roslyn.Generation.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace UIComponents.Experimental
{
[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class TraitAttribute : Attribute
public sealed class UxmlTraitAttribute : Attribute
{
public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public Task Verify_Traits(string fieldTypeName, bool useUnityEngine = false)
public partial class {fieldTypeNameCap}ComponentWithUsing : UIComponent
{{
[Trait]
[UxmlTrait]
public {fieldTypeName} FieldTrait;
[Trait]
[UxmlTrait]
public {fieldTypeName} PropertyTrait {{ get; set; }}
[Trait]
[UxmlTrait]
public {fieldTypeName} PropertyWithoutSetter {{ get; }}
}}";
if (useUnityEngine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Task Does_Not_Generate_If_TraitAttribute_Type_IsMissing()
public class Test
{
[Trait]
[UxmlTrait]
public int Number;
}
";
Expand All @@ -91,13 +91,13 @@ public Task Works_On_Non_UIComponent_Type()
public partial class NonUIComponentClass
{
[Trait(Name = ""custom-trait-name"")]
[UxmlTrait(Name = ""custom-trait-name"")]
public int FieldTrait;
[Trait(Name = ""my-property"")]
[UxmlTrait(Name = ""my-property"")]
public float PropertyTrait { get; set; }
[Trait(Name = ""nope"")]
[UxmlTrait(Name = ""nope"")]
public bool PropertyWithoutSetter { get; }
}";

Expand All @@ -119,13 +119,13 @@ public enum OwnEnum
B
}
[Trait]
[UxmlTrait]
public OwnEnum FieldTrait;
[Trait]
[UxmlTrait]
public OwnEnum PropertyTrait { get; set; }
[Trait]
[UxmlTrait]
public OwnEnum PropertyWithoutSetter { get; }
}";

Expand All @@ -151,13 +151,13 @@ public enum OwnEnum
B
}
[Trait]
[UxmlTrait]
public OwnEnum FieldTrait;
[Trait]
[UxmlTrait]
public OwnEnum PropertyTrait { get; set; }
[Trait]
[UxmlTrait]
public OwnEnum PropertyWithoutSetter { get; }
}
}
Expand All @@ -175,13 +175,13 @@ public Task Allows_Specifying_Uxml_Name()
public partial class CustomNamespaceComponent : UIComponent
{
[Trait(Name = ""custom-trait-name"")]
[UxmlTrait(Name = ""custom-trait-name"")]
public int FieldTrait;
[Trait(Name = ""my-property"")]
[UxmlTrait(Name = ""my-property"")]
public float PropertyTrait { get; set; }
[Trait(Name = ""nope"")]
[UxmlTrait(Name = ""nope"")]
public bool PropertyWithoutSetter { get; }
}";

Expand All @@ -199,7 +199,7 @@ public class MyComponent : UIComponent {}
public partial class MyComponentWithTraits : MyComponent
{
[Trait(Name = ""double-value"")]
[UxmlTrait(Name = ""double-value"")]
public double Trait;
}";

Expand All @@ -224,13 +224,13 @@ public enum TheEnum
public partial class ComponentWithDefaultValueTraits : UIComponent
{
[Trait(Name = ""description"", DefaultValue = ""Description not set."")]
[UxmlTrait(Name = ""description"", DefaultValue = ""Description not set."")]
public string Description;
[Trait(Name = ""lives"", DefaultValue = 3)]
[UxmlTrait(Name = ""lives"", DefaultValue = 3)]
public int Lives;
[Trait(Name = ""custom-value"", DefaultValue = Some.Place.Where.Enum.Is.TheEnum.VALUE_B)]
[UxmlTrait(Name = ""custom-value"", DefaultValue = Some.Place.Where.Enum.Is.TheEnum.VALUE_B)]
public Some.Place.Where.Enum.Is.TheEnum MyValue;
}";

Expand All @@ -246,25 +246,25 @@ public Task Generates_Traits_For_Many_Classes()
public partial class FirstTraitClass
{
[Trait(Name = ""custom-trait-name"")]
[UxmlTrait(Name = ""custom-trait-name"")]
public int FieldTrait;
[Trait(Name = ""my-property"")]
[UxmlTrait(Name = ""my-property"")]
public float PropertyTrait { get; set; }
}
public partial class SecondTraitClass
{
[Trait(DefaultValue = true)]
[UxmlTrait(DefaultValue = true)]
public bool Enabled;
[Trait(Name = ""secret"")]
[UxmlTrait(Name = ""secret"")]
public long SomeValue;
}
public partial class ThirdTraitClass
{
[Trait]
[UxmlTrait]
public string Name;
}";

Expand Down Expand Up @@ -297,11 +297,11 @@ public Task Generates_Both_Traits_And_UxmlFactory()
[UxmlName(""AwesomeUxmlName"")]
public partial class ComponentWithUxmlNameAndTraits : UIComponent
{
[Trait(DefaultValue = true)]
[UxmlTrait(DefaultValue = true)]
public bool Value;
}
";
return GeneratorTester.Verify<UxmlAugmentGenerator>(source);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class UxmlAugmentGenerator : AugmentGenerator<ClassMemberSyntaxReceiver
protected override void OnBeforeExecute(GeneratorExecutionContext context)
{
_traitAttributeSymbol =
context.Compilation.GetTypeByMetadataName("UIComponents.Experimental.TraitAttribute");
context.Compilation.GetTypeByMetadataName("UIComponents.Experimental.UxmlTraitAttribute");
_uxmlNameAttributeSymbol =
context.Compilation.GetTypeByMetadataName("UIComponents.Experimental.UxmlNameAttribute");
}
Expand Down

0 comments on commit da47d4c

Please sign in to comment.