22using Microsoft . CodeAnalysis . CSharp ;
33using Microsoft . CodeAnalysis . Diagnostics ;
44using System . Collections . Immutable ;
5+ using System . Linq ;
56
67namespace 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 ) ;
0 commit comments