Browse Source

Merge pull request #10468 from workgroupengineering/fixes/core/tools/AvaloniaPropertyAnalyzer/AVP1031

fix(AvaloniaPropertyAnalyzer): Avoid AVP1031 when Avalonia Field Acce…
pull/10530/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
24ad4af49b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs

13
src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs

@ -396,7 +396,7 @@ public partial class AvaloniaPropertyAnalyzer
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 @@ public partial class AvaloniaPropertyAnalyzer
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,9 +694,14 @@ public partial class AvaloniaPropertyAnalyzer
void VerifyAccessor(IMethodSymbol? method, string verb, string methodName)
{
if (method == null)
if (method is null)
{
context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName));
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));
}
}
else if (method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility)
{

Loading…
Cancel
Save