Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<NoWarn>NETSDK1023</NoWarn>
<!-- Remove MCTEXP001 once the BindablePropertySourceGenerator is Released and no longer in Experimental -->
<NoWarn>NETSDK1023,MCTEXP001</NoWarn>
<NetVersion>net10.0</NetVersion>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -240,7 +241,6 @@ https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitati
<SupportedPlatform Include="Tizen" />
<InternalsVisibleTo Include="CommunityToolkit.Maui.UnitTests"/>
<InternalsVisibleTo Include="CommunityToolkit.Maui.Analyzers.UnitTests"/>
<InternalsVisibleTo Include="CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests"/>
</ItemGroup>

<PropertyGroup Condition="('$(TF_BUILD)' == 'true' OR '$(GITHUB_ACTIONS)' == 'true') and $([MSBuild]::IsOSPlatform('windows')) == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected static async Task VerifySourceGeneratorAsync(string source, string exp
const string bindablePropertyAttributeGeneratedFileName = "BindablePropertyAttribute.g.cs";
var sourceGeneratorFullName = typeof(BindablePropertyAttributeSourceGenerator).FullName ?? throw new InvalidOperationException("Source Generator Type Path cannot be null");

var test = new CSharpSourceGeneratorTest<BindablePropertyAttributeSourceGenerator, DefaultVerifier>
var test = new ExperimentalBindablePropertyTest
{
#if NET10_0
ReferenceAssemblies = Microsoft.CodeAnalysis.Testing.ReferenceAssemblies.Net.Net100,
Expand Down Expand Up @@ -46,4 +46,18 @@ protected static async Task VerifySourceGeneratorAsync(string source, string exp

await test.RunAsync(TestContext.Current.CancellationToken);
}

// This class can be deleted once [Experimental] is removed from BindablePropertyAttribute
sealed class ExperimentalBindablePropertyTest : CSharpSourceGeneratorTest<BindablePropertyAttributeSourceGenerator, DefaultVerifier>
{
protected override CompilationOptions CreateCompilationOptions()
{
var compilationOptions = base.CreateCompilationOptions();

return compilationOptions.WithSpecificDiagnosticOptions(new Dictionary<string, ReportDiagnostic>
{
{ BindablePropertyAttributeSourceGenerator.BindablePropertyAttributeExperimentalDiagnosticId, ReportDiagnostic.Warn }
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@ public class BaseBindablePropertyAttributeSourceGeneratorTest : BaseTest
protected const string defaultTestNamespace = "TestNamespace";

protected const string expectedAttribute =
/* language=C#-test */
//lang=csharp
"""
// <auto-generated>
// See: CommunityToolkit.Maui.SourceGenerators.Internal.BindablePropertyAttributeSourceGenerator
/* language=C#-test */
//lang=csharp
$$"""
// <auto-generated>
// See: CommunityToolkit.Maui.SourceGenerators.Internal.BindablePropertyAttributeSourceGenerator

#pragma warning disable
#nullable enable
namespace CommunityToolkit.Maui;
#pragma warning disable
#nullable enable
namespace CommunityToolkit.Maui;

[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
sealed partial class BindablePropertyAttribute : global::System.Attribute
{
public string? PropertyName { get; }
public global::System.Type? DeclaringType { get; set; }
public object? DefaultValue { get; set; }
public global::Microsoft.Maui.Controls.BindingMode DefaultBindingMode { get; set; }
public string ValidateValueMethodName { get; set; } = string.Empty;
public string PropertyChangedMethodName { get; set; } = string.Empty;
public string PropertyChangingMethodName { get; set; } = string.Empty;
public string CoerceValueMethodName { get; set; } = string.Empty;
public string DefaultValueCreatorMethodName { get; set; } = string.Empty;
}
""";
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.Experimental("{{BindablePropertyAttributeSourceGenerator.BindablePropertyAttributeExperimentalDiagnosticId}}")]
sealed partial class BindablePropertyAttribute : global::System.Attribute
{
public string? PropertyName { get; }
public global::System.Type? DeclaringType { get; set; }
public object? DefaultValue { get; set; }
public global::Microsoft.Maui.Controls.BindingMode DefaultBindingMode { get; set; }
public string ValidateValueMethodName { get; set; } = string.Empty;
public string PropertyChangedMethodName { get; set; } = string.Empty;
public string PropertyChangingMethodName { get; set; } = string.Empty;
public string CoerceValueMethodName { get; set; } = string.Empty;
public string DefaultValueCreatorMethodName { get; set; } = string.Empty;
}
""";

protected static Task VerifySourceGeneratorAsync(string source, string expectedGenerated) =>
VerifySourceGeneratorAsync(source, expectedAttribute, ($"{defaultTestClassName}.g.cs", expectedGenerated));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ namespace CommunityToolkit.Maui.SourceGenerators.Internal;
[Generator]
public class BindablePropertyAttributeSourceGenerator : IIncrementalGenerator
{
public const string BindablePropertyAttributeExperimentalDiagnosticId = "MCTEXP001";

static readonly SemanticValues emptySemanticValues = new(default, []);

const string bpFullName = "global::Microsoft.Maui.Controls.BindableProperty";

const string bpAttribute =
/* language=C#-test */
//lang=csharp
Expand All @@ -32,6 +33,7 @@ namespace CommunityToolkit.Maui;

[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.Experimental("{{BindablePropertyAttributeExperimentalDiagnosticId}}")]
sealed partial class BindablePropertyAttribute : global::System.Attribute
{
public string? PropertyName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public static EquatableArray<T> AsEquatableArray<T>(this ImmutableArray<T> array
}

/// <summary>
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
/// An immutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
/// </summary>
/// <typeparam name="T">The type of values in the array.</typeparam>
readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
public readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
where T : IEquatable<T>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace CommunityToolkit.Maui.SourceGenerators.Internal.Models;

record BindablePropertyModel(string PropertyName, ITypeSymbol ReturnType, ITypeSymbol DeclaringType, string DefaultValue, string DefaultBindingMode, string ValidateValueMethodName, string PropertyChangedMethodName, string PropertyChangingMethodName, string CoerceValueMethodName, string DefaultValueCreatorMethodName, string NewKeywordText, bool IsReadOnlyBindableProperty, string? SetterAccessibility)
public record BindablePropertyModel(string PropertyName, ITypeSymbol ReturnType, ITypeSymbol DeclaringType, string DefaultValue, string DefaultBindingMode, string ValidateValueMethodName, string PropertyChangedMethodName, string PropertyChangingMethodName, string CoerceValueMethodName, string DefaultValueCreatorMethodName, string NewKeywordText, bool IsReadOnlyBindableProperty, string? SetterAccessibility)
{
public string BindablePropertyName => $"{PropertyName}Property";
public string BindablePropertyKeyName => $"{char.ToLower(PropertyName[0])}{PropertyName[1..]}PropertyKey";
}

record SemanticValues(ClassInformation ClassInformation, EquatableArray<BindablePropertyModel> BindableProperties);
public record SemanticValues(ClassInformation ClassInformation, EquatableArray<BindablePropertyModel> BindableProperties);

readonly record struct ClassInformation(string ClassName, string DeclaredAccessibility, string ContainingNamespace, string ContainingTypes = "", string GenericTypeParameters = "");
public readonly record struct ClassInformation(string ClassName, string DeclaredAccessibility, string ContainingNamespace, string ContainingTypes = "", string GenericTypeParameters = "");
Loading