Skip to content

Commit 5ad460b

Browse files
committed
Improve locations of some diagnostics
1 parent b631a6c commit 5ad460b

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override void Initialize(AnalysisContext context)
6767
{
6868
context.ReportDiagnostic(Diagnostic.Create(
6969
UnnecessaryDependencyPropertyExplicitMetadataType,
70-
attributeData.GetLocation(),
70+
attributeData.GetNamedArgumentOrAttributeLocation("PropertyType"),
7171
propertySymbol,
7272
propertySymbol.Type));
7373

@@ -79,7 +79,7 @@ public override void Initialize(AnalysisContext context)
7979
{
8080
context.ReportDiagnostic(Diagnostic.Create(
8181
IncompatibleDependencyPropertyExplicitMetadataType,
82-
attributeData.GetLocation(),
82+
attributeData.GetNamedArgumentOrAttributeLocation("PropertyType"),
8383
propertySymbol,
8484
typeSymbol,
8585
propertySymbol.Type));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override void Initialize(AnalysisContext context)
7777
{
7878
context.ReportDiagnostic(Diagnostic.Create(
7979
InvalidPropertyDeclarationDefaultValueCallbackNoMethodFound,
80-
attributeData.GetLocation(),
80+
attributeData.GetNamedArgumentOrAttributeLocation("DefaultValueCallback"),
8181
propertySymbol,
8282
defaultValueCallback));
8383
}
@@ -86,7 +86,7 @@ public override void Initialize(AnalysisContext context)
8686
// Emit a diagnostic if the candidate method is not valid
8787
context.ReportDiagnostic(Diagnostic.Create(
8888
InvalidPropertyDeclarationDefaultValueCallbackInvalidMethod,
89-
attributeData.GetLocation(),
89+
attributeData.GetNamedArgumentOrAttributeLocation("DefaultValueCallback"),
9090
propertySymbol,
9191
defaultValueCallback));
9292
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public override void Initialize(AnalysisContext context)
9595
{
9696
context.ReportDiagnostic(Diagnostic.Create(
9797
InvalidPropertyDefaultValueNull,
98-
attributeData.GetLocation(),
98+
attributeData.GetNamedArgumentOrAttributeLocation("DefaultValue"),
9999
propertySymbol,
100100
propertySymbol.Type));
101101
}
@@ -112,7 +112,7 @@ public override void Initialize(AnalysisContext context)
112112
{
113113
context.ReportDiagnostic(Diagnostic.Create(
114114
InvalidPropertyDefaultValueType,
115-
attributeData.GetLocation(),
115+
attributeData.GetNamedArgumentOrAttributeLocation("DefaultValue"),
116116
propertySymbol,
117117
propertySymbol.Type,
118118
defaultValue.Value,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Immutable;
6+
using System.Linq;
67
using CommunityToolkit.GeneratedDependencyProperty.Constants;
78
using CommunityToolkit.GeneratedDependencyProperty.Extensions;
89
using Microsoft.CodeAnalysis;
@@ -78,7 +79,7 @@ public override void Initialize(AnalysisContext context)
7879
{
7980
context.ReportDiagnostic(Diagnostic.Create(
8081
NotNullResilientAccessorsForNullablePropertyDeclaration,
81-
attributeData.GetLocation(),
82+
propertySymbol.Locations.FirstOrDefault(),
8283
propertySymbol));
8384
}
8485
}
@@ -104,7 +105,7 @@ public override void Initialize(AnalysisContext context)
104105
{
105106
context.ReportDiagnostic(Diagnostic.Create(
106107
NotNullResilientAccessorsForNotNullablePropertyDeclaration,
107-
attributeData.GetLocation(),
108+
propertySymbol.Locations.FirstOrDefault(),
108109
propertySymbol));
109110
}
110111

@@ -114,7 +115,7 @@ public override void Initialize(AnalysisContext context)
114115
{
115116
context.ReportDiagnostic(Diagnostic.Create(
116117
NonNullablePropertyDeclarationIsNotEnforced,
117-
attributeData.GetLocation(),
118+
propertySymbol.Locations.FirstOrDefault(),
118119
propertySymbol));
119120
}
120121
}

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Test_Analyzers.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,8 @@ namespace MyApp;
825825
826826
public partial class MyControl : Control
827827
{
828-
[{|WCTDP0009:GeneratedDependencyProperty|}]
829-
public partial string {|CS9248:Name|} { get; set; }
828+
[GeneratedDependencyProperty]
829+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
830830
}
831831
""";
832832

@@ -846,8 +846,8 @@ namespace MyApp;
846846
847847
public partial class MyControl : Control
848848
{
849-
[{|WCTDP0009:GeneratedDependencyProperty(DefaultValue = null)|}]
850-
public partial string {|CS9248:Name|} { get; set; }
849+
[GeneratedDependencyProperty(DefaultValue = null)]
850+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
851851
}
852852
""";
853853

@@ -867,8 +867,8 @@ namespace MyApp;
867867
868868
public partial class MyControl : Control
869869
{
870-
[{|WCTDP0009:GeneratedDependencyProperty(DefaultValueCallback = nameof(GetDefaultName))|}]
871-
public partial string {|CS9248:Name|} { get; set; }
870+
[GeneratedDependencyProperty(DefaultValueCallback = nameof(GetDefaultName))]
871+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
872872
873873
private static string? GetDefaultName() => "Bob";
874874
}
@@ -891,8 +891,8 @@ namespace MyApp;
891891
892892
public partial class MyControl : Control
893893
{
894-
[{|WCTDP0009:GeneratedDependencyProperty(DefaultValueCallback = nameof(GetDefaultName))|}]
895-
public partial string {|CS9248:Name|} { get; set; }
894+
[GeneratedDependencyProperty(DefaultValueCallback = nameof(GetDefaultName))]
895+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
896896
897897
[return: MaybeNull]
898898
private static string GetDefaultName() => "Bob";
@@ -916,9 +916,9 @@ namespace MyApp;
916916
917917
public partial class MyControl : Control
918918
{
919-
[{|WCTDP0009:GeneratedDependencyProperty|}]
919+
[GeneratedDependencyProperty]
920920
[AllowNull]
921-
public partial string {|CS9248:Name|} { get; set; }
921+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
922922
923923
partial void {|CS0759:OnNameSet|}([NotNull] ref object? propertyValue)
924924
{
@@ -972,9 +972,9 @@ namespace MyApp;
972972
973973
public partial class MyControl : Control
974974
{
975-
[{|WCTDP0009:GeneratedDependencyProperty|}]
975+
[GeneratedDependencyProperty]
976976
[AllowNull]
977-
public partial string {|CS9248:Name|} { get; set; }
977+
public partial string {|WCTDP0009:{|CS9248:Name|}|} { get; set; }
978978
979979
partial void {|CS0759:OnNameSet|}([NotNull] ref string? propertyValue)
980980
{
@@ -1028,9 +1028,9 @@ namespace MyApp;
10281028
10291029
public partial class MyControl : Control
10301030
{
1031-
[{|WCTDP0009:{|WCTDP0024:GeneratedDependencyProperty|}|}]
1031+
[GeneratedDependencyProperty]
10321032
[AllowNull]
1033-
public partial string {|CS9248:Name|} { get; set; }
1033+
public partial string {|WCTDP0009:{|WCTDP0024:{|CS9248:Name|}|}|} { get; set; }
10341034
10351035
partial void {|CS0759:OnNameGet|}(ref string? propertyValue)
10361036
{
@@ -1055,9 +1055,9 @@ namespace MyApp;
10551055
10561056
public partial class MyControl : Control
10571057
{
1058-
[{|WCTDP0009:{|WCTDP0024:GeneratedDependencyProperty|}|}]
1058+
[GeneratedDependencyProperty]
10591059
[AllowNull]
1060-
public partial string {|CS9248:Name|} { get; set; }
1060+
public partial string {|WCTDP0009:{|WCTDP0024:{|CS9248:Name|}|}|} { get; set; }
10611061
}
10621062
""";
10631063

@@ -1303,9 +1303,9 @@ namespace MyApp;
13031303
13041304
public partial class MyControl : Control
13051305
{
1306-
[{|WCTDP0025:GeneratedDependencyProperty|}]
1306+
[GeneratedDependencyProperty]
13071307
[NotNull]
1308-
public partial string? {|CS9248:Name|} { get; set; }
1308+
public partial string? {|WCTDP0025:{|CS9248:Name|}|} { get; set; }
13091309
}
13101310
""";
13111311

@@ -1326,9 +1326,9 @@ namespace MyApp;
13261326
13271327
public partial class MyControl : Control
13281328
{
1329-
[{|WCTDP0025:GeneratedDependencyProperty|}]
1329+
[GeneratedDependencyProperty]
13301330
[NotNull]
1331-
public partial string? {|CS9248:Name|} { get; set; }
1331+
public partial string? {|WCTDP0025:{|CS9248:Name|}|} { get; set; }
13321332
13331333
partial void {|CS0759:OnNameSet|}(ref string? propertyValue)
13341334
{
@@ -1354,10 +1354,10 @@ namespace MyApp;
13541354
13551355
public partial class MyControl : Control
13561356
{
1357-
[{|WCTDP0025:GeneratedDependencyProperty|}]
1357+
[GeneratedDependencyProperty]
13581358
[NotNull]
13591359
[DisallowNull]
1360-
public partial string? {|CS9248:Name|} { get; set; }
1360+
public partial string? {|WCTDP0025:{|CS9248:Name|}|} { get; set; }
13611361
}
13621362
""";
13631363

@@ -1378,9 +1378,9 @@ namespace MyApp;
13781378
13791379
public partial class MyControl : Control
13801380
{
1381-
[{|WCTDP0025:GeneratedDependencyProperty|}]
1381+
[GeneratedDependencyProperty]
13821382
[NotNull]
1383-
public partial string? {|CS9248:Name|} { get; set; }
1383+
public partial string? {|WCTDP0025:{|CS9248:Name|}|} { get; set; }
13841384
13851385
partial void {|CS0759:OnNameSet|}([NotNull] ref string? propertyValue)
13861386
{
@@ -1407,9 +1407,9 @@ namespace MyApp;
14071407
public abstract partial class Animation<TValue, TKeyFrame> : DependencyObject
14081408
where TKeyFrame : unmanaged
14091409
{
1410-
[{|WCTDP0025:GeneratedDependencyProperty|}]
1410+
[GeneratedDependencyProperty]
14111411
[NotNull]
1412-
public partial KeyFrameCollection<TValue, TKeyFrame>? {|CS9248:KeyFrames|} { get; set; }
1412+
public partial KeyFrameCollection<TValue, TKeyFrame>? {|WCTDP0025:{|CS9248:KeyFrames|}|} { get; set; }
14131413
14141414
partial void {|CS0759:OnKeyFramesGet|}(ref KeyFrameCollection<TValue, TKeyFrame>? propertyValue)
14151415
{
@@ -1442,9 +1442,9 @@ namespace MyApp;
14421442
public abstract partial class Animation<TValue, TKeyFrame> : DependencyObject
14431443
where TKeyFrame : unmanaged
14441444
{
1445-
[{|WCTDP0009:{|WCTDP0024:GeneratedDependencyProperty|}|}]
1445+
[GeneratedDependencyProperty]
14461446
[AllowNull]
1447-
public partial KeyFrameCollection<TValue, TKeyFrame> {|CS9248:KeyFrames|} { get; set; }
1447+
public partial KeyFrameCollection<TValue, TKeyFrame> {|WCTDP0009:{|WCTDP0024:{|CS9248:KeyFrames|}|}|} { get; set; }
14481448
14491449
partial void {|CS0759:OnKeyFramesGet|}(ref KeyFrameCollection<TValue, TKeyFrame>? propertyValue)
14501450
{
@@ -1477,9 +1477,9 @@ namespace MyApp;
14771477
public abstract partial class Animation<TValue, TKeyFrame> : DependencyObject
14781478
where TKeyFrame : unmanaged
14791479
{
1480-
[{|WCTDP0024:GeneratedDependencyProperty|}]
1480+
[GeneratedDependencyProperty]
14811481
[AllowNull]
1482-
public required partial KeyFrameCollection<TValue, TKeyFrame> {|CS9248:KeyFrames|} { get; set; }
1482+
public required partial KeyFrameCollection<TValue, TKeyFrame> {|WCTDP0024:{|CS9248:KeyFrames|}|} { get; set; }
14831483
}
14841484
14851485
public sealed partial class KeyFrameCollection<TValue, TKeyFrame> : DependencyObjectCollection
@@ -1642,7 +1642,7 @@ namespace MyApp;
16421642
16431643
public partial class MyControl : Control
16441644
{
1645-
[{|WCTDP0010:GeneratedDependencyProperty(DefaultValue = null)|}]
1645+
[GeneratedDependencyProperty({|WCTDP0010:DefaultValue = null|})]
16461646
public partial int {|CS9248:Name|} { get; set; }
16471647
}
16481648
""";
@@ -1675,7 +1675,7 @@ public partial class MyObject<T1, T2, T3, T4, T5> : DependencyObject
16751675
where T4 : unmanaged
16761676
where T5 : IDisposable
16771677
{
1678-
[{|WCTDP0010:GeneratedDependencyProperty(DefaultValue = null)|}]
1678+
[GeneratedDependencyProperty({|WCTDP0010:DefaultValue = null|})]
16791679
public partial {{propertyType}} {|CS9248:Name|} { get; set; }
16801680
}
16811681
""";
@@ -1700,7 +1700,7 @@ namespace MyApp;
17001700
17011701
public partial class MyControl : Control
17021702
{
1703-
[{|WCTDP0011:GeneratedDependencyProperty(DefaultValue = {{defaultValueType}})|}]
1703+
[GeneratedDependencyProperty({|WCTDP0011:DefaultValue = {{defaultValueType}}|})]
17041704
public partial {{propertyType}} {|CS9248:Name|} { get; set; }
17051705
}
17061706
""";
@@ -1862,7 +1862,7 @@ namespace MyApp;
18621862
18631863
public partial class MyControl : Control
18641864
{
1865-
[{|WCTDP0014:GeneratedDependencyProperty(DefaultValueCallback = "MissingMethod")|}]
1865+
[GeneratedDependencyProperty({|WCTDP0014:DefaultValueCallback = "MissingMethod"|})]
18661866
public partial string? {|CS9248:Name|} { get; set; }
18671867
}
18681868
""";
@@ -1883,7 +1883,7 @@ namespace MyApp;
18831883
18841884
public partial class MyControl : Control, IGetDefaultValue
18851885
{
1886-
[{|WCTDP0014:GeneratedDependencyProperty(DefaultValueCallback = "GetDefaultValue")|}]
1886+
[GeneratedDependencyProperty({|WCTDP0014:DefaultValueCallback = "GetDefaultValue"|})]
18871887
public partial string? {|CS9248:Name|} { get; set; }
18881888
18891889
static string? IGetDefaultValue.GetDefaultValue() => "Bob";
@@ -1915,7 +1915,7 @@ namespace MyApp;
19151915
19161916
public partial class MyControl : Control
19171917
{
1918-
[{|WCTDP0015:GeneratedDependencyProperty(DefaultValueCallback = "GetDefaultName")|}]
1918+
[GeneratedDependencyProperty({|WCTDP0015:DefaultValueCallback = "GetDefaultName"|})]
19191919
public partial string? {|CS9248:Name|} { get; set; }
19201920
19211921
{{methodSignature}} => default!;
@@ -2853,7 +2853,7 @@ public async Task ExplicitPropertyMetadataTypeAnalyzer_SameType_Warns(string typ
28532853
28542854
public class MyObject : DependencyObject, IMyInterface
28552855
{
2856-
[{|WCTDP0022:GeneratedDependencyProperty(PropertyType = typeof({{type}}))|}]
2856+
[GeneratedDependencyProperty({|WCTDP0022:PropertyType = typeof({{type}})|})]
28572857
public {{type}} Name { get; set; }
28582858
}
28592859
@@ -2879,7 +2879,7 @@ public async Task ExplicitPropertyMetadataTypeAnalyzer_IncompatibleType_Warns(st
28792879
28802880
public class MyObject : DependencyObject
28812881
{
2882-
[{|WCTDP0023:GeneratedDependencyProperty(PropertyType = typeof({{propertyType}}))|}]
2882+
[GeneratedDependencyProperty({|WCTDP0023:PropertyType = typeof({{propertyType}})|})]
28832883
public {{declaredType}} Name { get; set; }
28842884
}
28852885

0 commit comments

Comments
 (0)