Skip to content

Commit 38d02aa

Browse files
committed
更改提示语
1 parent b5b5b48 commit 38d02aa

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

WebApiClient.Analyzers/AttributeCtorAnalyzer.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.CodeAnalysis.CSharp;
33
using Microsoft.CodeAnalysis.Diagnostics;
44
using System.Collections.Immutable;
5+
using System.Linq;
56

67
namespace WebApiClient.Analyzers
78
{
@@ -20,8 +21,8 @@ public class AttributeCtorAnalyzer : DiagnosticAnalyzer
2021
/// <summary>
2122
/// 方法返回类型诊断描述器
2223
/// </summary>
23-
private static readonly DiagnosticDescriptor returnDescriptor =
24-
Rule("RT1001", "不支持的返回类型", "返回类型必须为ITask<>或Task<T>");
24+
private static readonly DiagnosticDescriptor returnTypeDescriptor =
25+
Rule("RT1001", "不支持的返回类型", "返回类型必须为ITask<>或Task<>");
2526

2627

2728
/// <summary>
@@ -47,7 +48,7 @@ private static DiagnosticDescriptor Rule(string id, string title, string message
4748
/// </summary>
4849
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
4950
{
50-
get => ImmutableArray.Create(attributeDescriptor, returnDescriptor);
51+
get => ImmutableArray.Create(attributeDescriptor, returnTypeDescriptor);
5152
}
5253

5354
/// <summary>
@@ -59,20 +60,20 @@ public override void Initialize(AnalysisContext context)
5960
context.RegisterSyntaxNodeAction(syntaxNodeContext =>
6061
{
6162
var httpApi = new WebApiClientHtttApi(syntaxNodeContext);
62-
var diagnosticReturnSyntaxs = httpApi.GetDiagnosticReturnSyntaxs();
63+
var diagnosticAttributeSyntaxs = httpApi.GetDiagnosticAttributeSyntaxs();
64+
var diagnosticReturnTypeSyntaxs = httpApi.GetDiagnosticReturnTypeSyntaxs();
6365

64-
foreach (var item in diagnosticReturnSyntaxs)
66+
foreach (var node in diagnosticAttributeSyntaxs)
6567
{
66-
var location = item.GetLocation();
67-
var diagnostic = Diagnostic.Create(returnDescriptor, location);
68+
var location = node.GetLocation();
69+
var diagnostic = Diagnostic.Create(attributeDescriptor, location);
6870
syntaxNodeContext.ReportDiagnostic(diagnostic);
6971
}
7072

71-
var diagnosticAttributes = httpApi.GetDiagnosticAttributes();
72-
foreach (var item in diagnosticAttributes)
73+
foreach (var node in diagnosticReturnTypeSyntaxs)
7374
{
74-
var location = item.ApplicationSyntaxReference.GetSyntax().GetLocation();
75-
var diagnostic = Diagnostic.Create(attributeDescriptor, location);
75+
var location = node.GetLocation();
76+
var diagnostic = Diagnostic.Create(returnTypeDescriptor, location);
7677
syntaxNodeContext.ReportDiagnostic(diagnostic);
7778
}
7879
}, SyntaxKind.InterfaceDeclaration);

WebApiClient.Analyzers/WebApiClientHtttApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,29 @@ private bool GetIsHtttApiInterface()
7272
/// 获取诊断的特性
7373
/// </summary>
7474
/// <returns></returns>
75-
public IEnumerable<AttributeData> GetDiagnosticAttributes()
75+
public IEnumerable<SyntaxNode> GetDiagnosticAttributeSyntaxs()
7676
{
7777
if (this.IsHtttApiInterface == false)
7878
{
79-
return Enumerable.Empty<AttributeData>();
79+
return Enumerable.Empty<SyntaxNode>();
8080
}
8181

8282
var interfaceSymbol = this.syntaxNodeContext.SemanticModel.GetDeclaredSymbol(this.interfaceDeclaration);
8383
if (interfaceSymbol == null)
8484
{
85-
return Enumerable.Empty<AttributeData>();
85+
return Enumerable.Empty<SyntaxNode>();
8686
}
8787

8888
var interfaceAttributes = this.GetInterfaceDiagnosticAttributes(interfaceSymbol);
8989
var methodAttributes = this.GetHttpApiMethodSymbols().SelectMany(item => this.GetMethodDiagnosticAttributes(item));
90-
return interfaceAttributes.Concat(methodAttributes);
90+
return interfaceAttributes.Concat(methodAttributes).Select(item => item.ApplicationSyntaxReference.GetSyntax());
9191
}
9292

9393
/// <summary>
94-
/// 获取诊断的接口返回
94+
/// 获取诊断的接口返回类型
9595
/// </summary>
9696
/// <returns></returns>
97-
public IEnumerable<TypeSyntax> GetDiagnosticReturnSyntaxs()
97+
public IEnumerable<SyntaxNode> GetDiagnosticReturnTypeSyntaxs()
9898
{
9999
if (this.IsHtttApiInterface == false)
100100
{

0 commit comments

Comments
 (0)