From a503a3e1f0315a7b12ee4b595140f13ef2b0c3fa Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 24 Feb 2023 18:51:54 +0100 Subject: [PATCH 1/3] fix(AvaloniaPropertyAnalyzer): Avoid AVP1031 when Avalonia Field Accessibily in not Public Considering following case ```bash Warning AVP1031 Missing accessor: Avalonia.Controls.DefinitionBase.PrivateSharedSizeScopeProperty is writeable, but this CLR property lacks a set accessor Avalonia.Controls (net6.0) C:\GitHub\Avalonia\src\Avalonia.Controls\DefinitionBase.cs 418 Active Warning AVP1031 Missing accessor: Avalonia.Controls.TabItem.TabStripPlacementProperty is writeable, but this CLR property lacks a set accessor Avalonia.Controls (net6.0) C:\GitHub\Avalonia\src\Avalonia.Controls\TabItem.cs 45 Active ``` --- .../AvaloniaPropertyAnalyzer.CompileAnalyzer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs index 0a27602604b..af9b3673688 100644 --- a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs +++ b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs @@ -396,7 +396,7 @@ invocation.Arguments[inheritsParam.Ordinal].Value is ILiteralOperation literalOp hostTypeRef = new(_avaloniaObjectType, Location.None); // assume that an attached property applies everywhere until we find its registration } - var result = new AvaloniaPropertyDescription(inferredName, propertyType, valueType) { HostType = hostTypeRef }; + var result = new AvaloniaPropertyDescription(inferredName, propertyType, valueType) { HostType = hostTypeRef }; // assume that the property is owned by its containing type at the point of assignment, until we find its registration result.SetAssignment(s, new(s.ContainingType, Location.None)); @@ -570,7 +570,7 @@ private void AnalyzeMethodInvocation(OperationAnalysisContext context) if (_allGetSetMethods.Contains(originalMethod)) { - if (invocation.Instance is IInstanceReferenceOperation { ReferenceKind: InstanceReferenceKind.ContainingTypeInstance } && + if (invocation.Instance is IInstanceReferenceOperation { ReferenceKind: InstanceReferenceKind.ContainingTypeInstance } && GetReferencedProperty(invocation.Arguments[0]) is { } refProp && refProp.description.AssignedTo.TryGetValue(refProp.storageSymbol, out var ownerType) && !DerivesFrom(context.ContainingSymbol.ContainingType, ownerType.Type) && @@ -694,11 +694,11 @@ private void AnalyzeWrapperCrlProperty(SymbolAnalysisContext context) void VerifyAccessor(IMethodSymbol? method, string verb, string methodName) { - if (method == null) + if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public && method is null) { context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName)); } - else if (method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility) + else if (method is not null && method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility) { context.ReportDiagnostic(Diagnostic.Create(InconsistentAccessibility, method.Locations[0], "property accessor", avaloniaPropertyStorage)); } From 12d418db336efad25859fbf8566768f9a1e86152 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 1 Mar 2023 12:30:20 +0100 Subject: [PATCH 2/3] fix: Address Review --- .../AvaloniaPropertyAnalyzer.CompileAnalyzer.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs index af9b3673688..ff70edde8eb 100644 --- a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs +++ b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs @@ -694,11 +694,14 @@ private void AnalyzeWrapperCrlProperty(SymbolAnalysisContext context) void VerifyAccessor(IMethodSymbol? method, string verb, string methodName) { - if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public && method is null) + if (method is null) { - context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName)); + if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public) + { + context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName)); + } } - else if (method is not null && method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility) + else if (method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility) { context.ReportDiagnostic(Diagnostic.Create(InconsistentAccessibility, method.Locations[0], "property accessor", avaloniaPropertyStorage)); } From 9201f237541cca0eae59972f7552b36b7cef1b1c Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 1 Mar 2023 12:46:10 +0100 Subject: [PATCH 3/3] fix: Signal warnig if protected --- .../AvaloniaPropertyAnalyzer.CompileAnalyzer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs index ff70edde8eb..0c0b487dba7 100644 --- a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs +++ b/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs @@ -696,7 +696,9 @@ void VerifyAccessor(IMethodSymbol? method, string verb, string methodName) { if (method is null) { - if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public) + if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public || + (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Protected + && avaloniaPropertyStorage.ContainingSymbol.DeclaredAccessibility == Accessibility.Public)) { context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName)); }