Skip to content

Commit 6d8f6e2

Browse files
committed
Remove workaround for unit test runner
1 parent 2ae6c2a commit 6d8f6e2

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.CodeFixers/UseGeneratedDependencyPropertyOnManualPropertyCodeFixer.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,6 @@ bool TryExtractAdditionalLocation(AdditionalLocationKind currentLocationKind, [N
536536
// Ensure the current kind is present and that we can extract an additional location
537537
if (!additionalLocationKind.HasFlag(currentLocationKind))
538538
{
539-
// Special case for the unit test runner. If we have 3 diagnostics (see details on the contract in the analyzer),
540-
// it means we're running in the test runner, which does not remove 'None' diagnostics. In this case, we need to
541-
// increment the current index, or otherwise we'll read incorrect locations after this one.
542-
if (diagnostic.AdditionalLocations.Count == 3)
543-
{
544-
currentLocationIndex++;
545-
}
546-
547539
fieldLocation = null;
548540

549541
return false;
@@ -552,16 +544,6 @@ bool TryExtractAdditionalLocation(AdditionalLocationKind currentLocationKind, [N
552544
// Parse the additional location
553545
fieldLocation = diagnostic.AdditionalLocations[currentLocationIndex++];
554546

555-
// Special case: if the location is 'None', we should ignore it. This is because while the location is
556-
// available when running tests, it will be removed when running in the IDE, because the serialization
557-
// logic that Roslyn uses will filter out all 'None' locations. This step is needed to match that logic.
558-
if (fieldLocation == Location.None)
559-
{
560-
fieldLocation = null;
561-
562-
return false;
563-
}
564-
565547
return true;
566548
}
567549

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/UseGeneratedDependencyPropertyOnManualPropertyAnalyzer.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,24 +597,25 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
597597
// 1) The field location (this is always present)
598598
// 2) The location of the 'typeof(...)' expression for the property type, if present
599599
// 3) The location of the default value expression, if it should be directly carried over
600-
Location[] additionalLocations =
600+
Location?[] additionalLocations =
601601
[
602602
fieldLocation,
603-
fieldFlags.PropertyTypeExpressionLocation ?? Location.None,
604-
fieldFlags.DefaultValueExpressionLocation ?? Location.None
603+
fieldFlags.PropertyTypeExpressionLocation,
604+
fieldFlags.DefaultValueExpressionLocation
605605
];
606606

607607
// Track the available locations, so we can extract them back. We cannot rely on the length
608-
// of the supplied array, because Roslyn will remove all 'None' locations from the array.
608+
// of the supplied array, because Roslyn will remove all 'None' locations from the array. To
609+
// match this behavior in tests too, we'll just filter out all 'null' elements below as well.
609610
AdditionalLocationKind additionalLocationKind =
610611
AdditionalLocationKind.FieldLocation |
611-
(additionalLocations[1] != Location.None ? AdditionalLocationKind.PropertyTypeExpressionLocation : 0) |
612-
(additionalLocations[2] != Location.None ? AdditionalLocationKind.DefaultValueExpressionLocation : 0);
612+
(additionalLocations[1] is not null ? AdditionalLocationKind.PropertyTypeExpressionLocation : 0) |
613+
(additionalLocations[2] is not null ? AdditionalLocationKind.DefaultValueExpressionLocation : 0);
613614

614615
context.ReportDiagnostic(Diagnostic.Create(
615616
UseGeneratedDependencyPropertyForManualProperty,
616617
pair.Key.Locations.FirstOrDefault(),
617-
additionalLocations,
618+
additionalLocations.OfType<Location>(),
618619
ImmutableDictionary.Create<string, string?>()
619620
.Add(DefaultValuePropertyName, fieldFlags.DefaultValue?.ToString())
620621
.Add(DefaultValueTypeReferenceIdPropertyName, fieldFlags.DefaultValueTypeReferenceId)

0 commit comments

Comments
 (0)