diff --git a/src/Directory.build.props b/src/Directory.build.props index 61da8ea..64b1bbc 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -17,7 +17,7 @@ https://github.com/reactiveui/ReactiveUI.SourceGenerators/releases https://github.com/reactiveui/reactiveui.sourcegenerators git - $(NoWarn);IDE0060;IDE1006;VSSpell001 + $(NoWarn);IDE0060;IDE1006;IDE0130;VSSpell001 true diff --git a/src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs b/src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs index 9e379e1..6d7c138 100644 --- a/src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs +++ b/src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs @@ -33,8 +33,6 @@ public partial class TestViewModel : ReactiveObject /// public TestViewModel() { - InitializeCommands(); - Console.Out.WriteLine(Test1Command); Console.Out.WriteLine(Test2Command); Console.Out.WriteLine(Test3AsyncCommand); diff --git a/src/ReactiveUI.SourceGenerators/Extensions/AttributeDataExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/AttributeDataExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/AttributeDataExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/AttributeDataExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/CompilationExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/CompilationExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/CompilationExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/CompilationExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/DiagnosticsExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/DiagnosticsExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/DiagnosticsExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/DiagnosticsExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/INamedTypeSymbolExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/INamedTypeSymbolExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/INamedTypeSymbolExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/INamedTypeSymbolExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/ISymbolExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/ISymbolExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/ISymbolExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/ISymbolExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/ITypeSymbolExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/ITypeSymbolExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/ITypeSymbolExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/ITypeSymbolExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/IncrementalGeneratorInitializationContextExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/IncrementalGeneratorInitializationContextExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/IncrementalGeneratorInitializationContextExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/IncrementalGeneratorInitializationContextExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/IncrementalValuesProviderExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/IncrementalValuesProviderExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/IncrementalValuesProviderExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/IncrementalValuesProviderExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/MemberDeclarationSyntaxExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/MemberDeclarationSyntaxExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/MemberDeclarationSyntaxExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/MemberDeclarationSyntaxExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/MethodDeclarationSyntaxExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/MethodDeclarationSyntaxExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/MethodDeclarationSyntaxExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/MethodDeclarationSyntaxExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/SourceProductionContextExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/SourceProductionContextExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/SourceProductionContextExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/SourceProductionContextExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/SymbolInfoExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/SymbolInfoExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/SymbolInfoExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/SymbolInfoExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/SyntaxNodeExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/SyntaxNodeExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/SyntaxNodeExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/SyntaxNodeExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/SyntaxTokenExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/SyntaxTokenExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/SyntaxTokenExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/SyntaxTokenExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Extensions/TypeDeclarationSyntaxExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Extensions/TypeDeclarationSyntaxExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Extensions/TypeDeclarationSyntaxExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Extensions/TypeDeclarationSyntaxExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/AttributeDefinitions.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/AttributeDefinitions.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/AttributeInfo.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeInfo.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/AttributeInfo.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeInfo.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/EquatableArray{T}.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/EquatableArray{T}.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/EquatableArray{T}.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/EquatableArray{T}.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/HashCode.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/HashCode.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/HashCode.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/HashCode.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/ImmutableArrayBuilder{T}.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/ImmutableArrayBuilder{T}.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/ImmutableArrayBuilder{T}.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/ImmutableArrayBuilder{T}.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/TypedConstantInfo.Factory.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/TypedConstantInfo.Factory.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/TypedConstantInfo.Factory.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/TypedConstantInfo.Factory.cs diff --git a/src/ReactiveUI.SourceGenerators/Helpers/TypedConstantInfo.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/TypedConstantInfo.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Helpers/TypedConstantInfo.cs rename to src/ReactiveUI.SourceGenerators/Core/Helpers/TypedConstantInfo.cs diff --git a/src/ReactiveUI.SourceGenerators/Models/DiagnosticInfo.cs b/src/ReactiveUI.SourceGenerators/Core/Models/DiagnosticInfo.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Models/DiagnosticInfo.cs rename to src/ReactiveUI.SourceGenerators/Core/Models/DiagnosticInfo.cs diff --git a/src/ReactiveUI.SourceGenerators/Models/HierarchyInfo.Syntax.cs b/src/ReactiveUI.SourceGenerators/Core/Models/HierarchyInfo.Syntax.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Models/HierarchyInfo.Syntax.cs rename to src/ReactiveUI.SourceGenerators/Core/Models/HierarchyInfo.Syntax.cs diff --git a/src/ReactiveUI.SourceGenerators/Models/HierarchyInfo.cs b/src/ReactiveUI.SourceGenerators/Core/Models/HierarchyInfo.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Models/HierarchyInfo.cs rename to src/ReactiveUI.SourceGenerators/Core/Models/HierarchyInfo.cs diff --git a/src/ReactiveUI.SourceGenerators/Models/Result.cs b/src/ReactiveUI.SourceGenerators/Core/Models/Result.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Models/Result.cs rename to src/ReactiveUI.SourceGenerators/Core/Models/Result.cs diff --git a/src/ReactiveUI.SourceGenerators/Models/TypeInfo.cs b/src/ReactiveUI.SourceGenerators/Core/Models/TypeInfo.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Models/TypeInfo.cs rename to src/ReactiveUI.SourceGenerators/Core/Models/TypeInfo.cs diff --git a/src/ReactiveUI.SourceGenerators/Polyfills/GeneratorAttributeSyntaxContext.cs b/src/ReactiveUI.SourceGenerators/Core/Polyfills/GeneratorAttributeSyntaxContext.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Polyfills/GeneratorAttributeSyntaxContext.cs rename to src/ReactiveUI.SourceGenerators/Core/Polyfills/GeneratorAttributeSyntaxContext.cs diff --git a/src/ReactiveUI.SourceGenerators/Polyfills/SyntaxValueProviderExtensions.cs b/src/ReactiveUI.SourceGenerators/Core/Polyfills/SyntaxValueProviderExtensions.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Polyfills/SyntaxValueProviderExtensions.cs rename to src/ReactiveUI.SourceGenerators/Core/Polyfills/SyntaxValueProviderExtensions.cs diff --git a/src/ReactiveUI.SourceGenerators/Diagnostics/Analyzers/AsyncVoidReturningReactiveCommandMethodAnalyzer.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/AsyncVoidReturningReactiveCommandMethodAnalyzer.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Diagnostics/Analyzers/AsyncVoidReturningReactiveCommandMethodAnalyzer.cs rename to src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/AsyncVoidReturningReactiveCommandMethodAnalyzer.cs diff --git a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs similarity index 94% rename from src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs rename to src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs index c6fb054..e12b97b 100644 --- a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs +++ b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs @@ -45,8 +45,12 @@ public override void Initialize(AnalysisContext context) } private void AnalyzeNode(SyntaxNodeAnalysisContext context) + { + if (context.Node is not PropertyDeclarationSyntax propertyDeclaration) { - var propertyDeclaration = (PropertyDeclarationSyntax)context.Node; + return; + } + var isAutoProperty = propertyDeclaration.ExpressionBody == null && (propertyDeclaration.AccessorList?.Accessors.All(a => a.Body == null && a.ExpressionBody == null) != false); if (isAutoProperty && propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword) && !propertyDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword)) diff --git a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs similarity index 93% rename from src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs rename to src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs index 89713cf..313e9cf 100644 --- a/src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs +++ b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs @@ -28,7 +28,8 @@ public class PropertyToReactiveFieldCodeFixProvider : CodeFixProvider /// /// Gets a list of diagnostic IDs that this provider can provide fixes for. /// - public sealed override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create(DiagnosticDescriptors.PropertyToReactiveFieldRule.Id); + public sealed override ImmutableArray FixableDiagnosticIds => + ImmutableArray.Create(DiagnosticDescriptors.PropertyToReactiveFieldRule.Id); /// /// Gets an optional that can fix all/multiple occurrences of diagnostics fixed by this code fix provider. @@ -77,7 +78,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) // Apply the code fix context.RegisterCodeFix( - CodeAction.Create("Convert to Reactive field", c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!)), "Convert to Reactive field"), + CodeAction.Create( + "Convert to Reactive field", + c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!)), + "Convert to Reactive field"), diagnostic); } } diff --git a/src/ReactiveUI.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs similarity index 100% rename from src/ReactiveUI.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs rename to src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs diff --git a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index e876a32..ba5f8c7 100644 --- a/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -259,7 +259,7 @@ internal static class DiagnosticDescriptors id: "RXUISG0016", title: "Property To Reactive Field, change to [Reactive] private type _fieldName;", messageFormat: "Replace the property with a INPC Reactive Property for ReactiveUI", - category: typeof(PropertyToReactiveFieldCodeFixProvider).FullName, + category: typeof(PropertyToReactiveFieldAnalyzer).FullName, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: true, description: "Used to create a Read Write INPC Reactive Property for ReactiveUI, annotated with [Reactive].", diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs index 89505ff..af1d4b1 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.Execute.cs @@ -25,8 +25,6 @@ namespace ReactiveUI.SourceGenerators; /// public partial class ObservableAsPropertyGenerator { - private const string GeneratedCode = "global::System.CodeDom.Compiler.GeneratedCode"; - private const string ExcludeFromCodeCoverage = "global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage"; /// /// A container for all the logic for . /// @@ -88,7 +86,7 @@ internal static ImmutableArray GetPropertySyntax(Proper .AddDeclarationVariables(VariableDeclarator(getterFieldIdentifierName + "Helper")) .AddAttributeLists( AttributeList(SingletonSeparatedList( - Attribute(IdentifierName(GeneratedCode)) + Attribute(IdentifierName(AttributeDefinitions.GeneratedCode)) .AddArgumentListArguments( AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).FullName))), AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ObservableAsPropertyGenerator).Assembly.GetName().Version.ToString())))))) @@ -99,12 +97,12 @@ internal static ImmutableArray GetPropertySyntax(Proper PropertyDeclaration(propertyType, Identifier(propertyInfo.PropertyName)) .AddAttributeLists( AttributeList(SingletonSeparatedList( - Attribute(IdentifierName(GeneratedCode)) + Attribute(IdentifierName(AttributeDefinitions.GeneratedCode)) .AddArgumentListArguments( 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(ExcludeFromCodeCoverage))))) + AttributeList(SingletonSeparatedList(Attribute(IdentifierName(AttributeDefinitions.ExcludeFromCodeCoverage))))) .AddAttributeLists([.. forwardedAttributes]) .AddModifiers(Token(SyntaxKind.PublicKeyword)) .AddAccessorListAccessors( diff --git a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs index 496cb09..0e239e0 100644 --- a/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs +++ b/src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator.cs @@ -21,19 +21,17 @@ namespace ReactiveUI.SourceGenerators; [Generator(LanguageNames.CSharp)] public sealed partial class ObservableAsPropertyGenerator : IIncrementalGenerator { - private const string ObservableAsPropertyAttribute = "ReactiveUI.SourceGenerators.ObservableAsPropertyAttribute"; - /// public void Initialize(IncrementalGeneratorInitializationContext context) { context.RegisterPostInitializationOutput(ctx => - ctx.AddSource($"{ObservableAsPropertyAttribute}.g.cs", SourceText.From(AttributeDefinitions.ObservableAsPropertyAttribute, Encoding.UTF8))); + 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( - ObservableAsPropertyAttribute, + AttributeDefinitions.ObservableAsPropertyAttributeType, static (node, _) => node is VariableDeclaratorSyntax { Parent: VariableDeclarationSyntax { Parent: FieldDeclarationSyntax { Parent: ClassDeclarationSyntax or RecordDeclarationSyntax, AttributeLists.Count: > 0 } } }, static (context, token) => {