Skip to content

Commit 45adcdf

Browse files
Merge branch 'feature/bp-sourcegen-init' of https://github.com/stephenquan/Maui into pr/2987
2 parents 07d0087 + 1ce2b6a commit 45adcdf

File tree

8 files changed

+51
-36
lines changed

8 files changed

+51
-36
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<Project>
33
<PropertyGroup>
44
<Nullable>enable</Nullable>
5-
<NoWarn>NETSDK1023</NoWarn>
5+
<!-- Remove MCTEXP001 once the BindablePropertySourceGenerator is Released and no longer in Experimental -->
6+
<NoWarn>NETSDK1023,MCTEXP001</NoWarn>
67
<NetVersion>net10.0</NetVersion>
78
<LangVersion>preview</LangVersion>
89
<ImplicitUsings>enable</ImplicitUsings>
@@ -240,7 +241,6 @@ https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitati
240241
<SupportedPlatform Include="Tizen" />
241242
<InternalsVisibleTo Include="CommunityToolkit.Maui.UnitTests"/>
242243
<InternalsVisibleTo Include="CommunityToolkit.Maui.Analyzers.UnitTests"/>
243-
<InternalsVisibleTo Include="CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests"/>
244244
</ItemGroup>
245245

246246
<PropertyGroup Condition="('$(TF_BUILD)' == 'true' OR '$(GITHUB_ACTIONS)' == 'true') and $([MSBuild]::IsOSPlatform('windows')) == 'true'">

src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ void StopService(in BoundServiceConnection boundServiceConnection)
722722

723723
#region PlayerListener implementation method stubs
724724
public void OnAudioAttributesChanged(AudioAttributes? audioAttributes) { }
725+
public void OnAudioSessionIdChanged(int audioSessionId) { }
725726
public void OnAvailableCommandsChanged(PlayerCommands? player) { }
726727
public void OnCues(CueGroup? cues) { }
727728
public void OnDeviceInfoChanged(DeviceInfo? deviceInfo) { }

src/CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests/BaseTest.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected static async Task VerifySourceGeneratorAsync(string source, string exp
1313
const string bindablePropertyAttributeGeneratedFileName = "BindablePropertyAttribute.g.cs";
1414
var sourceGeneratorFullName = typeof(BindablePropertyAttributeSourceGenerator).FullName ?? throw new InvalidOperationException("Source Generator Type Path cannot be null");
1515

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

4747
await test.RunAsync(TestContext.Current.CancellationToken);
4848
}
49+
50+
// This class can be deleted once [Experimental] is removed from BindablePropertyAttribute
51+
sealed class ExperimentalBindablePropertyTest : CSharpSourceGeneratorTest<BindablePropertyAttributeSourceGenerator, DefaultVerifier>
52+
{
53+
protected override CompilationOptions CreateCompilationOptions()
54+
{
55+
var compilationOptions = base.CreateCompilationOptions();
56+
57+
return compilationOptions.WithSpecificDiagnosticOptions(new Dictionary<string, ReportDiagnostic>
58+
{
59+
{ BindablePropertyAttributeSourceGenerator.BindablePropertyAttributeExperimentalDiagnosticId, ReportDiagnostic.Warn }
60+
});
61+
}
62+
}
4963
}

src/CommunityToolkit.Maui.SourceGenerators.Internal.UnitTests/BindablePropertyAttributeSourceGeneratorTests/BaseBindablePropertyAttributeSourceGeneratorTest.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@ public class BaseBindablePropertyAttributeSourceGeneratorTest : BaseTest
66
protected const string defaultTestNamespace = "TestNamespace";
77

88
protected const string expectedAttribute =
9-
/* language=C#-test */
10-
//lang=csharp
11-
"""
12-
// <auto-generated>
13-
// See: CommunityToolkit.Maui.SourceGenerators.Internal.BindablePropertyAttributeSourceGenerator
9+
/* language=C#-test */
10+
//lang=csharp
11+
$$"""
12+
// <auto-generated>
13+
// See: CommunityToolkit.Maui.SourceGenerators.Internal.BindablePropertyAttributeSourceGenerator
1414
15-
#pragma warning disable
16-
#nullable enable
17-
namespace CommunityToolkit.Maui;
15+
#pragma warning disable
16+
#nullable enable
17+
namespace CommunityToolkit.Maui;
1818
19-
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
20-
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
21-
sealed partial class BindablePropertyAttribute : global::System.Attribute
22-
{
23-
public string? PropertyName { get; }
24-
public global::System.Type? DeclaringType { get; set; }
25-
public object? DefaultValue { get; set; }
26-
public global::Microsoft.Maui.Controls.BindingMode DefaultBindingMode { get; set; }
27-
public string ValidateValueMethodName { get; set; } = string.Empty;
28-
public string PropertyChangedMethodName { get; set; } = string.Empty;
29-
public string PropertyChangingMethodName { get; set; } = string.Empty;
30-
public string CoerceValueMethodName { get; set; } = string.Empty;
31-
public string DefaultValueCreatorMethodName { get; set; } = string.Empty;
32-
}
33-
""";
19+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
20+
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
21+
[global::System.Diagnostics.CodeAnalysis.Experimental("{{BindablePropertyAttributeSourceGenerator.BindablePropertyAttributeExperimentalDiagnosticId}}")]
22+
sealed partial class BindablePropertyAttribute : global::System.Attribute
23+
{
24+
public string? PropertyName { get; }
25+
public global::System.Type? DeclaringType { get; set; }
26+
public object? DefaultValue { get; set; }
27+
public global::Microsoft.Maui.Controls.BindingMode DefaultBindingMode { get; set; }
28+
public string ValidateValueMethodName { get; set; } = string.Empty;
29+
public string PropertyChangedMethodName { get; set; } = string.Empty;
30+
public string PropertyChangingMethodName { get; set; } = string.Empty;
31+
public string CoerceValueMethodName { get; set; } = string.Empty;
32+
public string DefaultValueCreatorMethodName { get; set; } = string.Empty;
33+
}
34+
""";
3435

3536
protected static Task VerifySourceGeneratorAsync(string source, string expectedGenerated) =>
3637
VerifySourceGeneratorAsync(source, expectedAttribute, ($"{defaultTestClassName}.g.cs", expectedGenerated));

src/CommunityToolkit.Maui.SourceGenerators.Internal/CommunityToolkit.Maui.SourceGenerators.Internal.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" PrivateAssets="all" />
19-
<PackageReference Include="PolySharp" Version="1.15.0">
20-
<PrivateAssets>all</PrivateAssets>
21-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22-
</PackageReference>
19+
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
2320
</ItemGroup>
2421

2522
</Project>

src/CommunityToolkit.Maui.SourceGenerators.Internal/Generators/BindablePropertyAttributeSourceGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ namespace CommunityToolkit.Maui.SourceGenerators.Internal;
1515
[Generator]
1616
public class BindablePropertyAttributeSourceGenerator : IIncrementalGenerator
1717
{
18+
public const string BindablePropertyAttributeExperimentalDiagnosticId = "MCTEXP001";
19+
1820
static readonly SemanticValues emptySemanticValues = new(default, []);
1921

2022
const string bpFullName = "global::Microsoft.Maui.Controls.BindableProperty";
21-
2223
const string bpAttribute =
2324
/* language=C#-test */
2425
//lang=csharp
@@ -32,6 +33,7 @@ namespace CommunityToolkit.Maui;
3233
3334
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
3435
[global::System.AttributeUsage(global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
36+
[global::System.Diagnostics.CodeAnalysis.Experimental("{{BindablePropertyAttributeExperimentalDiagnosticId}}")]
3537
sealed partial class BindablePropertyAttribute : global::System.Attribute
3638
{
3739
public string? PropertyName { get; }

src/CommunityToolkit.Maui.SourceGenerators.Internal/Helpers/EquatableArray{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public static EquatableArray<T> AsEquatableArray<T>(this ImmutableArray<T> array
2929
}
3030

3131
/// <summary>
32-
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
32+
/// An immutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
3333
/// </summary>
3434
/// <typeparam name="T">The type of values in the array.</typeparam>
35-
readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
35+
public readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
3636
where T : IEquatable<T>
3737
{
3838
/// <summary>

src/CommunityToolkit.Maui.SourceGenerators.Internal/Models/Records.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace CommunityToolkit.Maui.SourceGenerators.Internal.Models;
55

6-
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, bool HasInitializer)
6+
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, bool HasInitializer)
77
{
88
// When both a DefaultValueCreatorMethodName and an initializer are provided, we implement the DefaultValueCreator method and the ignore the partial Property initializer
99
public bool ShouldUsePropertyInitializer => HasInitializer && DefaultValueCreatorMethodName is "null";
@@ -14,6 +14,6 @@ record BindablePropertyModel(string PropertyName, ITypeSymbol ReturnType, ITypeS
1414

1515
}
1616

17-
record SemanticValues(ClassInformation ClassInformation, EquatableArray<BindablePropertyModel> BindableProperties);
17+
public record SemanticValues(ClassInformation ClassInformation, EquatableArray<BindablePropertyModel> BindableProperties);
1818

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

0 commit comments

Comments
 (0)