@@ -52,49 +52,15 @@ public override void Initialize(AnalysisContext context)
5252
5353 private static void HandleCompilationStart ( CompilationStartAnalysisContext context )
5454 {
55- context . RegisterSyntaxNodeActionHonorExclusions ( HandleMethodDeclaration , SyntaxKind . MethodDeclaration ) ;
56- context . RegisterSyntaxNodeActionHonorExclusions ( HandleTypeDeclaration , SyntaxKind . ClassDeclaration ) ;
57- context . RegisterSyntaxNodeActionHonorExclusions ( HandleTypeDeclaration , SyntaxKind . StructDeclaration ) ;
58- context . RegisterSyntaxNodeActionHonorExclusions ( HandleTypeDeclaration , SyntaxKind . InterfaceDeclaration ) ;
55+ context . RegisterSyntaxNodeActionHonorExclusions ( HandleTypeParameterConstraintClause , SyntaxKind . TypeParameterConstraintClause ) ;
5956 }
6057
61- private static void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context )
58+ private static void HandleTypeParameterConstraintClause ( SyntaxNodeAnalysisContext context )
6259 {
63- var declaration = ( MethodDeclarationSyntax ) context . Node ;
64- var declarationLineSpan = declaration . GetLineSpan ( ) ;
65-
66- if ( declaration . TypeParameterList ? . Parameters . Count > 0 )
67- {
68- Analyze ( context , declarationLineSpan , declaration . ConstraintClauses ) ;
69- }
70- }
71-
72- private static void HandleTypeDeclaration ( SyntaxNodeAnalysisContext context )
73- {
74- var declaration = ( TypeDeclarationSyntax ) context . Node ;
75- var declarationLineSpan = declaration . GetLineSpan ( ) ;
76-
77- if ( declaration . TypeParameterList ? . Parameters . Count > 0 )
60+ var syntax = ( TypeParameterConstraintClauseSyntax ) context . Node ;
61+ if ( ! syntax . WhereKeyword . IsFirstInLine ( ) )
7862 {
79- Analyze ( context , declarationLineSpan , declaration . ConstraintClauses ) ;
80- }
81- }
82-
83- private static void Analyze (
84- SyntaxNodeAnalysisContext context ,
85- FileLinePositionSpan declarationLineSpan ,
86- SyntaxList < TypeParameterConstraintClauseSyntax > constraintClauses )
87- {
88- int currentLine = declarationLineSpan . StartLinePosition . Line ;
89- foreach ( var constraint in constraintClauses )
90- {
91- int constraintLine = constraint . GetLineSpan ( ) . StartLinePosition . Line ;
92- if ( currentLine == constraintLine )
93- {
94- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , constraint . GetLocation ( ) ) ) ;
95- }
96-
97- currentLine = constraintLine ;
63+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , syntax . GetLocation ( ) ) ) ;
9864 }
9965 }
10066 }
0 commit comments