diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs similarity index 83% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs index d0044ba..23c7068 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethods#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs @@ -12,14 +12,14 @@ partial class TestVM [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] private int _test2Property; /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] private ReactiveUI.ObservableAsPropertyHelper? _test2PropertyHelper; /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public int Test2Property { get => _test2Property = _test2PropertyHelper?.Value ?? _test2Property; } - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] protected void InitializeOAPH() { diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NamedFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NamedFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs similarity index 52% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs index b5a189c..f50ad02 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs @@ -8,22 +8,22 @@ namespace TestNs /// partial class TestVM { - /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] + private int _myNamedProperty; + /// + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] + private ReactiveUI.ObservableAsPropertyHelper? _myNamedPropertyHelper; + /// [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] - private int _test4Property; - /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] - private ReactiveUI.ObservableAsPropertyHelper? _test4PropertyHelper; - /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public int Test4Property { get => _test4Property = _test4PropertyHelper?.Value ?? _test4Property; } + public int MyNamedProperty { get => _myNamedProperty = _myNamedPropertyHelper?.Value ?? _myNamedProperty; } - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] protected void InitializeOAPH() { - _test4PropertyHelper = Test4!.ToProperty(this, nameof(Test4Property)); + _myNamedPropertyHelper = Test3()!.ToProperty(this, nameof(MyNamedProperty)); } } } \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NonReadOnlyFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NonReadOnlyFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs similarity index 83% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs index 2eb82b3..28c8820 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservableProp#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs @@ -12,14 +12,14 @@ partial class TestVM [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] private int _test1Property; /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] private ReactiveUI.ObservableAsPropertyHelper? _test1PropertyHelper; /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public int Test1Property { get => _test1Property = _test1PropertyHelper?.Value ?? _test1Property; } - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] protected void InitializeOAPH() { diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs new file mode 100644 index 0000000..4339d6e --- /dev/null +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.cs +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System; + +// +#pragma warning disable +#nullable enable +namespace ReactiveUI.SourceGenerators; + +/// +/// ObservableAsPropertyAttribute. +/// +/// +[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +internal sealed class ObservableAsPropertyAttribute : Attribute +{ + /// + /// Gets the name of the property. + /// + /// + /// The name of the property. + /// + public string? PropertyName { get; init; } + + /// + /// Gets the Readonly state of the OAPH property. + /// + /// + /// The is read only of the OAPH property. + /// + public bool ReadOnly { get; init; } = true; +} +#nullable restore +#pragma warning restore \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs similarity index 52% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs index 5c80135..55bc6d2 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGenerator.FromObservableMethodsWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPFromObservableGeneratorTests.FromObservablePropertiesWithName#TestNs.TestVM.ObservableAsPropertyFromObservable.g.verified.cs @@ -8,22 +8,22 @@ namespace TestNs /// partial class TestVM { - /// + /// + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] + private int _myNamedProperty; + /// + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] + private ReactiveUI.ObservableAsPropertyHelper? _myNamedPropertyHelper; + /// [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] - private int _test3Property; - /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] - private ReactiveUI.ObservableAsPropertyHelper? _test3PropertyHelper; - /// - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public int Test3Property { get => _test3Property = _test3PropertyHelper?.Value ?? _test3Property; } + public int MyNamedProperty { get => _myNamedProperty = _myNamedPropertyHelper?.Value ?? _myNamedProperty; } - [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyFromObservableGenerator", "1.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] protected void InitializeOAPH() { - _test3PropertyHelper = Test3()!.ToProperty(this, nameof(Test3Property)); + _myNamedPropertyHelper = Test4!.ToProperty(this, nameof(MyNamedProperty)); } } } \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs new file mode 100644 index 0000000..4339d6e --- /dev/null +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.cs +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System; + +// +#pragma warning disable +#nullable enable +namespace ReactiveUI.SourceGenerators; + +/// +/// ObservableAsPropertyAttribute. +/// +/// +[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +internal sealed class ObservableAsPropertyAttribute : Attribute +{ + /// + /// Gets the name of the property. + /// + /// + /// The name of the property. + /// + public string? PropertyName { get; init; } + + /// + /// Gets the Readonly state of the OAPH property. + /// + /// + /// The is read only of the OAPH property. + /// + public bool ReadOnly { get; init; } = true; +} +#nullable restore +#pragma warning restore \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.FromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.FromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.FromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NamedFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NamedFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs new file mode 100644 index 0000000..4339d6e --- /dev/null +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NamedFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.cs +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System; + +// +#pragma warning disable +#nullable enable +namespace ReactiveUI.SourceGenerators; + +/// +/// ObservableAsPropertyAttribute. +/// +/// +[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +internal sealed class ObservableAsPropertyAttribute : Attribute +{ + /// + /// Gets the name of the property. + /// + /// + /// The name of the property. + /// + public string? PropertyName { get; init; } + + /// + /// Gets the Readonly state of the OAPH property. + /// + /// + /// The is read only of the OAPH property. + /// + public bool ReadOnly { get; init; } = true; +} +#nullable restore +#pragma warning restore \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NamedFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NamedFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NamedFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NamedFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NonReadOnlyFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NonReadOnlyFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs new file mode 100644 index 0000000..4339d6e --- /dev/null +++ b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NonReadOnlyFromField#ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.verified.cs @@ -0,0 +1,39 @@ +//HintName: ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute.g.cs +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System; + +// +#pragma warning disable +#nullable enable +namespace ReactiveUI.SourceGenerators; + +/// +/// ObservableAsPropertyAttribute. +/// +/// +[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ObservableAsPropertyGenerator", "1.1.0.0")] +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +internal sealed class ObservableAsPropertyAttribute : Attribute +{ + /// + /// Gets the name of the property. + /// + /// + /// The name of the property. + /// + public string? PropertyName { get; init; } + + /// + /// Gets the Readonly state of the OAPH property. + /// + /// + /// The is read only of the OAPH property. + /// + public bool ReadOnly { get; init; } = true; +} +#nullable restore +#pragma warning restore \ No newline at end of file diff --git a/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NonReadOnlyFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NonReadOnlyFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGenerator.NonReadOnlyFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/OAPH/OAPGeneratorTests.NonReadOnlyFromField#TestNs.TestVM.ObservableAsProperties.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#TestNs.TestVM.Properties.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#TestNs.TestVM.Properties.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactiveProperties#TestNs.TestVM.Properties.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#TestNs.TestVM.Properties.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#System.Runtime.CompilerServices.IsExternalInit.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#TestNs.TestVM.Properties.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#TestNs.TestVM.Properties.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGenerator.FromReactivePropertiesWithAccess#TestNs.TestVM.Properties.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#TestNs.TestVM.Properties.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveAsyncCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommand#TestNs.TestVM.ReactiveCommands.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs b/src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs similarity index 100% rename from src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGenerator.FromReactiveCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs rename to src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithParameter#TestNs.TestVM.ReactiveCommands.g.verified.cs diff --git a/src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerator.Tests.csproj b/src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerators.Tests.csproj similarity index 88% rename from src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerator.Tests.csproj rename to src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerators.Tests.csproj index edda9b7..589d27b 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerator.Tests.csproj +++ b/src/ReactiveUI.SourceGenerator.Tests/ReactiveUI.SourceGenerators.Tests.csproj @@ -26,11 +26,17 @@ - + + + + + + + diff --git a/src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs b/src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs index 50f14e7..5ff12aa 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs @@ -3,8 +3,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System.Runtime.CompilerServices; - using FluentAssertions; using Microsoft.CodeAnalysis; @@ -18,6 +16,9 @@ using ReactiveMarbles.SourceGenerator.TestNuGetHelper.Compilation; +using ReactiveUI.SourceGenerators; +using ReactiveUI.SourceGenerators.WinForms; + using Xunit.Abstractions; namespace ReactiveUI.SourceGenerator.Tests; @@ -51,19 +52,18 @@ public sealed class TestHelper(ITestOutputHelper testOutput) : IDisposable /// /// Verifieds the file path. /// - /// the type. + /// The name. /// /// A string. /// - public static string VerifiedFilePath() - where T : Attribute + public static string VerifiedFilePath(string name) { - var name = typeof(T).Name; return name switch { - "ReactiveAttribute" => "..\\REACTIVE", - "ReactiveCommandAttribute" => "..\\REACTIVECMD", - "ObservableAsPropertyAttribute" => "..\\OAPH", + nameof(ReactiveGenerator) => "..\\REACTIVE", + nameof(ReactiveCommandGenerator) => "..\\REACTIVECMD", + nameof(RoutedControlHostGenerator) => "..\\ROUTEDHOST", + nameof(ObservableAsPropertyGenerator) => "..\\OAPH", _ => name, }; } @@ -92,23 +92,10 @@ public async Task InitializeAsync() /// /// The type of the incremental generator being tested. /// The source code to test. - /// The parameter to be used in the test. - /// The type that called this test method. - /// The path of the calling file (auto-populated). - /// The name of the calling member (auto-populated). public void TestFail( - string source, - string contractParameter, - Type callerType, - [CallerFilePath] string file = "", - [CallerMemberName] string memberName = "") + string source) where T : IIncrementalGenerator, new() { - if (callerType is null) - { - throw new ArgumentNullException(nameof(callerType)); - } - if (_eventCompiler is null) { throw new InvalidOperationException("Must have valid compiler instance."); @@ -124,14 +111,12 @@ public void TestFail( /// /// The type of the incremental generator being tested. /// The source code to test. - /// The ignore conditional. /// /// The driver. /// /// callerType. public GeneratorDriver TestPass( - string source, - Func? ignoreConditional = null) + string source) where T : IIncrementalGenerator, new() { if (_eventCompiler is null) @@ -139,7 +124,7 @@ public GeneratorDriver TestPass( throw new InvalidOperationException("Must have valid compiler instance."); } - return RunGeneratorAndCheck(source, ignoreConditional); + return RunGeneratorAndCheck(source); } /// @@ -150,7 +135,6 @@ public GeneratorDriver TestPass( /// /// The type of the source generator. /// The code to be parsed and processed by the generator. - /// Optional. A function to ignore specific diagnostics. /// Indicates whether to rerun the compilation after running the generator. /// The generator driver used to run the generator. /// @@ -158,7 +142,6 @@ public GeneratorDriver TestPass( /// public GeneratorDriver RunGeneratorAndCheck( string code, - Func? ignoreConditional = null, bool rerunCompilation = true) where T : IIncrementalGenerator, new() { @@ -187,19 +170,6 @@ public GeneratorDriver RunGeneratorAndCheck( assemblies, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, deterministic: true)); - // Validate diagnostics before running the generator. - var prediagnostics = compilation.GetDiagnostics() - .Where(d => d.Severity > DiagnosticSeverity.Warning) - .ToList(); - if (ignoreConditional is not null) - { - prediagnostics.Where(x => !ignoreConditional(x)).Should().BeEmpty(); - } - else - { - prediagnostics.Should().BeEmpty(); - } - var generator = new T(); var driver = CSharpGeneratorDriver.Create(generator).WithUpdatedParseOptions((CSharpParseOptions)syntaxTree.Options); diff --git a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGenerator.cs b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGeneratorTests.cs similarity index 85% rename from src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGenerator.cs rename to src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGeneratorTests.cs index fca2c2f..0194d0b 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGenerator.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPFromObservableGeneratorTests.cs @@ -12,7 +12,7 @@ namespace ReactiveUI.SourceGenerator.Tests; /// Unit tests for the ObservableAsProperty generator. /// /// The output helper. -public class OAPFromObservableGenerator(ITestOutputHelper output) : TestBase(output) +public class OAPFromObservableGeneratorTests(ITestOutputHelper output) : TestBase(output) { /// /// Tests that the source generator correctly generates observable properties. @@ -38,10 +38,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } /// @@ -68,10 +68,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } /// @@ -98,10 +98,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } /// @@ -128,9 +128,9 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } } diff --git a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGenerator.cs b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGeneratorTests.cs similarity index 91% rename from src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGenerator.cs rename to src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGeneratorTests.cs index 763e781..144ec94 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGenerator.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/OAPGeneratorTests.cs @@ -12,7 +12,7 @@ namespace ReactiveUI.SourceGenerator.Tests; /// Unit tests for the ObservableAsProperty generator. /// /// The output helper. -public class OAPGenerator(ITestOutputHelper output) : TestBase(output) +public class OAPGeneratorTests(ITestOutputHelper output) : TestBase(output) { /// /// Tests that the source generator correctly generates observable properties. @@ -38,10 +38,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } /// @@ -68,10 +68,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } /// @@ -98,9 +98,9 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ObservableAsPropertyGenerator))); } } diff --git a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGenerator.cs b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGeneratorTests.cs similarity index 92% rename from src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGenerator.cs rename to src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGeneratorTests.cs index 1d0dfe2..b796abc 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGenerator.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGeneratorTests.cs @@ -12,7 +12,7 @@ namespace ReactiveUI.SourceGenerator.Tests; /// Unit tests for the ReactiveCommand generator. /// /// The output helper. -public class ReactiveCMDGenerator(ITestOutputHelper output) : TestBase(output) +public class ReactiveCMDGeneratorTests(ITestOutputHelper output) : TestBase(output) { /// /// Tests that the source generator correctly generates ReactiveCommands. @@ -42,10 +42,10 @@ private void Test1() """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0616")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveCommandGenerator))); } /// @@ -76,10 +76,10 @@ private void Test3(string baseString) """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0616")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveCommandGenerator))); } /// @@ -110,10 +110,10 @@ private async Task Test1() """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0616")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveCommandGenerator))); } /// @@ -145,9 +145,9 @@ private async Task Test3(string baseString) """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0616")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveCommandGenerator))); } } diff --git a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGenerator.cs b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGeneratorTests.cs similarity index 86% rename from src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGenerator.cs rename to src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGeneratorTests.cs index 8928436..8e0f551 100644 --- a/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGenerator.cs +++ b/src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveGeneratorTests.cs @@ -12,7 +12,7 @@ namespace ReactiveUI.SourceGenerator.Tests; /// Unit tests for the Reactive generator. /// /// The output helper. -public class ReactiveGenerator(ITestOutputHelper output) : TestBase(output) +public class ReactiveGeneratorTests(ITestOutputHelper output) : TestBase(output) { /// /// Tests that the source generator correctly generates reactive properties. @@ -38,10 +38,10 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveGenerator))); } /// @@ -68,9 +68,9 @@ public partial class TestVM : ReactiveObject """; // Act: Initialize the helper and run the generator. - var driver = TestHelper.TestPass(sourceCode, d => d.Id.Equals("CS0122")); + var driver = TestHelper.TestPass(sourceCode); // Assert: Verify the generated code. - return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()); + return Verify(driver).UseDirectory(TestHelper.VerifiedFilePath(nameof(ReactiveGenerator))); } } diff --git a/src/ReactiveUI.SourceGenerators.sln b/src/ReactiveUI.SourceGenerators.sln index 840ec01..19dd8cd 100644 --- a/src/ReactiveUI.SourceGenerators.sln +++ b/src/ReactiveUI.SourceGenerators.sln @@ -20,7 +20,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Execute.Maui", "ReactiveUI.SourceGenerators.Execute.Maui\ReactiveUI.SourceGenerators.Execute.Maui.csproj", "{849CACF4-B85F-47B5-84B3-7C94DE864E7E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerator.Tests", "ReactiveUI.SourceGenerator.Tests\ReactiveUI.SourceGenerator.Tests.csproj", "{60C7C031-8765-46D7-8E0D-88CD4949F25B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Tests", "ReactiveUI.SourceGenerator.Tests\ReactiveUI.SourceGenerators.Tests.csproj", "{60C7C031-8765-46D7-8E0D-88CD4949F25B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index ba5f8c7..45e4d2a 100644 --- a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -272,7 +272,7 @@ internal static class DiagnosticDescriptors id: "RXUISG0017", title: "Invalid generated property declaration", messageFormat: "The method {0} cannot be used to generate an observable As property, as it has parameters", - category: typeof(ObservableAsPropertyFromObservableGenerator).FullName, + category: typeof(ObservableAsPropertyGenerator).FullName, defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, description: "The method annotated with [ObservableAsProperty] cannot currently initialize methods with parameters.", diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.Execute.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.Execute.cs similarity index 96% rename from src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.Execute.cs rename to src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.Execute.cs index 0fc89ad..1e1bb04 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.Execute.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.Execute.cs @@ -13,6 +13,7 @@ using ReactiveUI.SourceGenerators.Extensions; using ReactiveUI.SourceGenerators.Helpers; using ReactiveUI.SourceGenerators.ObservableAsProperty.Models; + using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace ReactiveUI.SourceGenerators; @@ -21,9 +22,9 @@ namespace ReactiveUI.SourceGenerators; /// Observable As Property From Observable Generator. /// /// -public partial class ObservableAsPropertyFromObservableGenerator +public sealed partial class ObservableAsPropertyGenerator { - internal static class Execute + internal static partial class Execute { internal static ImmutableArray GetPropertySyntax(ObservableMethodInfo propertyInfo) { @@ -66,8 +67,8 @@ internal static ImmutableArray GetPropertySyntax(Observ AttributeList(SingletonSeparatedList( Attribute(IdentifierName(AttributeDefinitions.GeneratedCode)) .AddArgumentListArguments( - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).FullName))), - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).Assembly.GetName().Version.ToString())))))) + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).FullName))), + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).Assembly.GetName().Version.ToString())))))) .WithOpenBracketToken(Token(TriviaList(Comment($"/// ")), SyntaxKind.OpenBracketToken, TriviaList()))) .AddModifiers( Token(SyntaxKind.PrivateKeyword)), @@ -76,8 +77,8 @@ internal static ImmutableArray GetPropertySyntax(Observ AttributeList(SingletonSeparatedList( Attribute(IdentifierName(AttributeDefinitions.GeneratedCode)) .AddArgumentListArguments( - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).FullName))), - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).Assembly.GetName().Version.ToString())))))) + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).FullName))), + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).Assembly.GetName().Version.ToString())))))) .WithOpenBracketToken(Token(TriviaList(Comment($"/// ")), SyntaxKind.OpenBracketToken, TriviaList())), AttributeList(SingletonSeparatedList(Attribute(IdentifierName(AttributeDefinitions.ExcludeFromCodeCoverage))))) .AddAttributeLists([.. forwardedAttributes]) @@ -112,8 +113,8 @@ internal static MethodDeclarationSyntax GetPropertyInitiliser(ObservableMethodIn AttributeList(SingletonSeparatedList( Attribute(IdentifierName(AttributeDefinitions.GeneratedCode)) .AddArgumentListArguments( - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).FullName))), - AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyFromObservableGenerator).Assembly.GetName().Version.ToString())))))), + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).FullName))), + AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).Assembly.GetName().Version.ToString())))))), AttributeList(SingletonSeparatedList(Attribute(IdentifierName(AttributeDefinitions.ExcludeFromCodeCoverage))))) .WithModifiers(TokenList(Token(SyntaxKind.ProtectedKeyword))) .WithBody(Block(propertyInitilisers.ToImmutable())); diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.cs similarity index 91% rename from src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.cs rename to src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.cs index 6aeabba..5a38437 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyFromObservableGenerator.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.FromObservableGenerator.cs @@ -5,9 +5,13 @@ using System.Collections.Immutable; using System.Linq; +using System.Text; + using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; + using ReactiveUI.SourceGenerators.Extensions; using ReactiveUI.SourceGenerators.Helpers; using ReactiveUI.SourceGenerators.Models; @@ -20,11 +24,9 @@ namespace ReactiveUI.SourceGenerators; /// /// A source generator for generating reative properties. /// -[Generator(LanguageNames.CSharp)] -public sealed partial class ObservableAsPropertyFromObservableGenerator : IIncrementalGenerator +public sealed partial class ObservableAsPropertyGenerator { - /// - public void Initialize(IncrementalGeneratorInitializationContext context) + private static void RunObservablePropertyAsFromObservable(in IncrementalGeneratorInitializationContext context) { // Gather info for all annotated command methods (starting from method declarations with at least one attribute) IncrementalValuesProvider<(HierarchyInfo Hierarchy, Result Info)> propertyInfoWithErrors = @@ -34,14 +36,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context) static (node, _) => node is MethodDeclarationSyntax or PropertyDeclarationSyntax { Parent: ClassDeclarationSyntax or RecordDeclarationSyntax, AttributeLists.Count: > 0 }, static (context, token) => { - var symbol = ModelExtensions.GetDeclaredSymbol(context.SemanticModel, context.TargetNode, token)!; + var symbol = context.TargetSymbol; token.ThrowIfCancellationRequested(); - // Skip symbols without the target attribute - if (!symbol.TryGetAttributeWithFullyQualifiedMetadataName(AttributeDefinitions.ObservableAsPropertyAttributeType, out var attributeData)) - { - return default; - } + var attributeData = context.Attributes[0]; // Get the can PropertyName member, if any attributeData.TryGetNamedArgument("PropertyName", out string? propertyName); diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.Execute.cs similarity index 99% rename from src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs rename to src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.Execute.cs index d82583b..3d8d783 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.Execute.cs @@ -24,12 +24,12 @@ namespace ReactiveUI.SourceGenerators; /// ReactiveGenerator. /// /// -public partial class ObservableAsPropertyGenerator +public sealed partial class ObservableAsPropertyGenerator { /// /// A container for all the logic for . /// - internal static class Execute + internal static partial class Execute { /// /// Gets the instance for the input field. diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.cs new file mode 100644 index 0000000..cac6de5 --- /dev/null +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Generator.cs @@ -0,0 +1,88 @@ +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; +using ReactiveUI.SourceGenerators.Extensions; +using ReactiveUI.SourceGenerators.Helpers; +using ReactiveUI.SourceGenerators.Models; + +namespace ReactiveUI.SourceGenerators; + +/// +/// A source generator for generating reative properties. +/// +public sealed partial class ObservableAsPropertyGenerator +{ + private static void RunGenerator(in IncrementalGeneratorInitializationContext context) + { + // Gather info for all annotated command methods (starting from method declarations with at least one attribute) + IncrementalValuesProvider<(HierarchyInfo Hierarchy, Result Info)> propertyInfoWithErrors = + context.SyntaxProvider + .ForAttributeWithMetadataName( + AttributeDefinitions.ObservableAsPropertyAttributeType, + static (node, _) => node is VariableDeclaratorSyntax { Parent: VariableDeclarationSyntax { Parent: FieldDeclarationSyntax { Parent: ClassDeclarationSyntax or RecordDeclarationSyntax, AttributeLists.Count: > 0 } } }, + static (context, token) => + { + var symbol = ModelExtensions.GetDeclaredSymbol(context.SemanticModel, context.TargetNode, token)!; + token.ThrowIfCancellationRequested(); + + // Skip symbols without the target attribute + if (!symbol.TryGetAttributeWithFullyQualifiedMetadataName(AttributeDefinitions.ObservableAsPropertyAttributeType, out var attributeData)) + { + return default; + } + + // Get the can PropertyName member, if any + attributeData.TryGetNamedArgument("ReadOnly", out bool? isReadonly); + + var fieldDeclaration = (FieldDeclarationSyntax)context.TargetNode.Parent!.Parent!; + var fieldSymbol = (IFieldSymbol)context.TargetSymbol; + + // Get the hierarchy info for the target symbol, and try to gather the property info + var hierarchy = HierarchyInfo.From(fieldSymbol.ContainingType); + + token.ThrowIfCancellationRequested(); + + Execute.GetFieldInfoFromClass(fieldDeclaration, fieldSymbol, context.SemanticModel, isReadonly, token, out var propertyInfo, out var diagnostics); + + token.ThrowIfCancellationRequested(); + return (Hierarchy: hierarchy, new Result(propertyInfo, diagnostics)); + }) + .Where(static item => item.Hierarchy is not null)!; + + // Output the diagnostics + context.ReportDiagnostics(propertyInfoWithErrors.Select(static (item, _) => item.Info.Errors)); + + // Get the filtered sequence to enable caching + var propertyInfo = + propertyInfoWithErrors + .Where(static item => item.Info.Value is not null)!; + + // Split and group by containing type + var groupedPropertyInfo = + propertyInfo + .GroupBy(static item => item.Left, static item => item.Right.Value); + + // Generate the requested properties and methods + context.RegisterSourceOutput(groupedPropertyInfo, static (context, item) => + { + // Generate all member declarations for the current type + var memberDeclarations = + item.Right + .Select(Execute.GetPropertySyntax) + .SelectMany(static m => m) + .ToImmutableArray(); + + // Insert all members into the same partial type declaration + var compilationUnit = item.Key.GetCompilationUnit(memberDeclarations); + context.AddSource($"{item.Key.FilenameHint}.ObservableAsProperties.g.cs", compilationUnit); + }); + } +} diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs index 6a3a02d..493bec1 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs @@ -1,22 +1,21 @@ -// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System.Collections.Immutable; -using System.Linq; +using System; +using System.Collections.Generic; using System.Text; + using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; -using ReactiveUI.SourceGenerators.Extensions; + using ReactiveUI.SourceGenerators.Helpers; -using ReactiveUI.SourceGenerators.Models; namespace ReactiveUI.SourceGenerators; /// -/// A source generator for generating reative properties. +/// Main entry point. /// [Generator(LanguageNames.CSharp)] public sealed partial class ObservableAsPropertyGenerator : IIncrementalGenerator @@ -27,67 +26,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterPostInitializationOutput(ctx => ctx.AddSource($"{AttributeDefinitions.ObservableAsPropertyAttributeType}.g.cs", SourceText.From(AttributeDefinitions.ObservableAsPropertyAttribute, Encoding.UTF8))); - // Gather info for all annotated command methods (starting from method declarations with at least one attribute) - IncrementalValuesProvider<(HierarchyInfo Hierarchy, Result Info)> propertyInfoWithErrors = - context.SyntaxProvider - .ForAttributeWithMetadataName( - AttributeDefinitions.ObservableAsPropertyAttributeType, - static (node, _) => node is VariableDeclaratorSyntax { Parent: VariableDeclarationSyntax { Parent: FieldDeclarationSyntax { Parent: ClassDeclarationSyntax or RecordDeclarationSyntax, AttributeLists.Count: > 0 } } }, - static (context, token) => - { - var symbol = ModelExtensions.GetDeclaredSymbol(context.SemanticModel, context.TargetNode, token)!; - token.ThrowIfCancellationRequested(); - - // Skip symbols without the target attribute - if (!symbol.TryGetAttributeWithFullyQualifiedMetadataName(AttributeDefinitions.ObservableAsPropertyAttributeType, out var attributeData)) - { - return default; - } - - // Get the can PropertyName member, if any - attributeData.TryGetNamedArgument("ReadOnly", out bool? isReadonly); - - var fieldDeclaration = (FieldDeclarationSyntax)context.TargetNode.Parent!.Parent!; - var fieldSymbol = (IFieldSymbol)context.TargetSymbol; - - // Get the hierarchy info for the target symbol, and try to gather the property info - var hierarchy = HierarchyInfo.From(fieldSymbol.ContainingType); - - token.ThrowIfCancellationRequested(); - - Execute.GetFieldInfoFromClass(fieldDeclaration, fieldSymbol, context.SemanticModel, isReadonly, token, out var propertyInfo, out var diagnostics); - - token.ThrowIfCancellationRequested(); - return (Hierarchy: hierarchy, new Result(propertyInfo, diagnostics)); - }) - .Where(static item => item.Hierarchy is not null)!; - - // Output the diagnostics - context.ReportDiagnostics(propertyInfoWithErrors.Select(static (item, _) => item.Info.Errors)); - - // Get the filtered sequence to enable caching - var propertyInfo = - propertyInfoWithErrors - .Where(static item => item.Info.Value is not null)!; - - // Split and group by containing type - var groupedPropertyInfo = - propertyInfo - .GroupBy(static item => item.Left, static item => item.Right.Value); - - // Generate the requested properties and methods - context.RegisterSourceOutput(groupedPropertyInfo, static (context, item) => - { - // Generate all member declarations for the current type - var memberDeclarations = - item.Right - .Select(Execute.GetPropertySyntax) - .SelectMany(static m => m) - .ToImmutableArray(); - - // Insert all members into the same partial type declaration - var compilationUnit = item.Key.GetCompilationUnit(memberDeclarations); - context.AddSource($"{item.Key.FilenameHint}.ObservableAsProperties.g.cs", compilationUnit); - }); + RunObservablePropertyAsFromObservable(context); + RunGenerator(context); } } diff --git a/src/ReactiveUI.SourceGenerators/ReactiveUI.SourceGenerators.csproj b/src/ReactiveUI.SourceGenerators/ReactiveUI.SourceGenerators.csproj index b25e2b5..c1f55e4 100644 --- a/src/ReactiveUI.SourceGenerators/ReactiveUI.SourceGenerators.csproj +++ b/src/ReactiveUI.SourceGenerators/ReactiveUI.SourceGenerators.csproj @@ -53,5 +53,6 @@ +