@@ -14,42 +14,35 @@ namespace CSharpGuidelinesAnalyzer.Test.RoslynTestFramework
1414{
1515 public abstract class AnalysisTestFixture
1616 {
17- [ NotNull ]
1817 protected abstract string DiagnosticId { get ; }
1918
20- [ NotNull ]
2119 protected abstract DiagnosticAnalyzer CreateAnalyzer ( ) ;
2220
23- protected async Task AssertDiagnosticsAsync ( [ NotNull ] AnalyzerTestContext context , [ NotNull ] [ ItemNotNull ] params string [ ] messages )
21+ protected async Task AssertDiagnosticsAsync ( AnalyzerTestContext context , params string [ ] messages )
2422 {
2523 FrameworkGuard . NotNull ( context , nameof ( context ) ) ;
2624 FrameworkGuard . NotNull ( messages , nameof ( messages ) ) ;
2725
2826 await RunDiagnosticsAsync ( context , messages ) ;
2927 }
3028
31- private async Task RunDiagnosticsAsync ( [ NotNull ] AnalyzerTestContext context ,
32- [ NotNull ] [ ItemNotNull ] params string [ ] messages )
29+ private async Task RunDiagnosticsAsync ( AnalyzerTestContext context , params string [ ] messages )
3330 {
3431 AnalysisResult result = await GetAnalysisResultAsync ( context , messages ) ;
3532
3633 VerifyDiagnosticCount ( result ) ;
3734 VerifyDiagnostics ( result ) ;
3835 }
3936
40- [ NotNull ]
41- [ ItemNotNull ]
42- private async Task < AnalysisResult > GetAnalysisResultAsync ( [ NotNull ] AnalyzerTestContext context , [ NotNull ] [ ItemNotNull ] string [ ] messages )
37+ private async Task < AnalysisResult > GetAnalysisResultAsync ( AnalyzerTestContext context , string [ ] messages )
4338 {
4439 var document = DocumentFactory . ToDocument ( context . SourceCode , context ) ;
4540
4641 IList < Diagnostic > diagnostics = await GetSortedAnalyzerDiagnosticsAsync ( document , context ) ;
4742 return new AnalysisResult ( diagnostics , context . SourceSpans , messages ) ;
4843 }
4944
50- [ NotNull ]
51- [ ItemNotNull ]
52- private async Task < IList < Diagnostic > > GetSortedAnalyzerDiagnosticsAsync ( [ NotNull ] Document document , [ NotNull ] AnalyzerTestContext context )
45+ private async Task < IList < Diagnostic > > GetSortedAnalyzerDiagnosticsAsync ( Document document , AnalyzerTestContext context )
5346 {
5447 var diagnostics = new List < Diagnostic > ( ) ;
5548
@@ -64,30 +57,24 @@ private async Task<IList<Diagnostic>> GetSortedAnalyzerDiagnosticsAsync([NotNull
6457 return diagnostics . OrderBy ( diagnostic => diagnostic . Location . SourceSpan ) . ToImmutableArray ( ) ;
6558 }
6659
67- [ NotNull ]
68- [ ItemNotNull ]
69- private async IAsyncEnumerable < Diagnostic > EnumerateDiagnosticsForDocumentAsync ( [ NotNull ] Document document ,
70- [ NotNull ] AnalyzerTestContext context )
60+ private async IAsyncEnumerable < Diagnostic > EnumerateDiagnosticsForDocumentAsync ( Document document , AnalyzerTestContext context )
7161 {
7262 CompilationWithAnalyzers compilationWithAnalyzers =
7363 await GetCompilationWithAnalyzersAsync ( document , context . ValidationMode , context . Options ) ;
7464
75- SyntaxTree tree = await document . GetSyntaxTreeAsync ( ) ;
65+ SyntaxTree ? tree = await document . GetSyntaxTreeAsync ( ) ;
7666
7767 await foreach ( Diagnostic diagnostic in EnumerateAnalyzerDiagnosticsAsync ( compilationWithAnalyzers , tree ! ) )
7868 {
7969 yield return diagnostic ;
8070 }
8171 }
8272
83- [ NotNull ]
84- [ ItemNotNull ]
85- private async Task < CompilationWithAnalyzers > GetCompilationWithAnalyzersAsync ( [ NotNull ] Document document ,
86- TestValidationMode validationMode , [ NotNull ] AnalyzerOptions options )
73+ private async Task < CompilationWithAnalyzers > GetCompilationWithAnalyzersAsync ( Document document , TestValidationMode validationMode , AnalyzerOptions options )
8774 {
8875 DiagnosticAnalyzer analyzer = CreateAnalyzer ( ) ;
8976
90- Compilation compilation = await document . Project . GetCompilationAsync ( ) ;
77+ Compilation ? compilation = await document . Project . GetCompilationAsync ( ) ;
9178 compilation = EnsureAnalyzerIsEnabled ( analyzer , compilation ! ) ;
9279
9380 ImmutableArray < Diagnostic > compilerDiagnostics = compilation . GetDiagnostics ( CancellationToken . None ) ;
@@ -101,9 +88,7 @@ private async Task<CompilationWithAnalyzers> GetCompilationWithAnalyzersAsync([N
10188 return compilation . WithAnalyzers ( analyzers , options ) ;
10289 }
10390
104- [ NotNull ]
105- private static Compilation EnsureAnalyzerIsEnabled ( [ NotNull ] DiagnosticAnalyzer analyzer ,
106- [ NotNull ] Compilation compilation )
91+ private static Compilation EnsureAnalyzerIsEnabled ( DiagnosticAnalyzer analyzer , Compilation compilation )
10792 {
10893 ImmutableDictionary < string , ReportDiagnostic > diagnosticOptions = compilation . Options . SpecificDiagnosticOptions ;
10994
@@ -119,18 +104,15 @@ private static Compilation EnsureAnalyzerIsEnabled([NotNull] DiagnosticAnalyzer
119104 return compilation . WithOptions ( compilationWithSpecificOptions ) ;
120105 }
121106
122- private void ValidateCompileErrors ( [ ItemNotNull ] ImmutableArray < Diagnostic > compilerDiagnostics )
107+ private void ValidateCompileErrors ( ImmutableArray < Diagnostic > compilerDiagnostics )
123108 {
124109 Diagnostic [ ] compilerErrors = compilerDiagnostics . Where ( diagnostic => diagnostic . Severity == DiagnosticSeverity . Error )
125110 . ToArray ( ) ;
126111
127112 compilerErrors . Should ( ) . BeEmpty ( "test should not have compile errors" ) ;
128113 }
129114
130- [ NotNull ]
131- [ ItemNotNull ]
132- private static async IAsyncEnumerable < Diagnostic > EnumerateAnalyzerDiagnosticsAsync ( [ NotNull ] CompilationWithAnalyzers compilationWithAnalyzers ,
133- [ NotNull ] SyntaxTree tree )
115+ private static async IAsyncEnumerable < Diagnostic > EnumerateAnalyzerDiagnosticsAsync ( CompilationWithAnalyzers compilationWithAnalyzers , SyntaxTree tree )
134116 {
135117 foreach ( Diagnostic diagnostic in await compilationWithAnalyzers . GetAnalyzerDiagnosticsAsync ( ) )
136118 {
@@ -145,7 +127,7 @@ private static async IAsyncEnumerable<Diagnostic> EnumerateAnalyzerDiagnosticsAs
145127 }
146128 }
147129
148- private static void ThrowForCrashingAnalyzer ( [ NotNull ] Diagnostic diagnostic )
130+ private static void ThrowForCrashingAnalyzer ( Diagnostic diagnostic )
149131 {
150132 if ( diagnostic . Id == "AD0001" )
151133 {
@@ -154,19 +136,19 @@ private static void ThrowForCrashingAnalyzer([NotNull] Diagnostic diagnostic)
154136 }
155137 }
156138
157- private static void VerifyDiagnosticCount ( [ NotNull ] AnalysisResult result )
139+ private static void VerifyDiagnosticCount ( AnalysisResult result )
158140 {
159141 result . DiagnosticsWithLocation . Should ( ) . HaveSameCount ( result . SpansExpected ) ;
160142 result . Diagnostics . Should ( ) . HaveSameCount ( result . MessagesExpected ) ;
161143 }
162144
163- private static void VerifyDiagnostics ( [ NotNull ] AnalysisResult result )
145+ private static void VerifyDiagnostics ( AnalysisResult result )
164146 {
165147 VerifyDiagnosticMessages ( result ) ;
166148 VerifyDiagnosticLocations ( result ) ;
167149 }
168150
169- private static void VerifyDiagnosticMessages ( [ NotNull ] AnalysisResult result )
151+ private static void VerifyDiagnosticMessages ( AnalysisResult result )
170152 {
171153 int messageIndex = 0 ;
172154
@@ -180,7 +162,7 @@ private static void VerifyDiagnosticMessages([NotNull] AnalysisResult result)
180162 }
181163 }
182164
183- private static void VerifyDiagnosticLocations ( [ NotNull ] AnalysisResult result )
165+ private static void VerifyDiagnosticLocations ( AnalysisResult result )
184166 {
185167 int spanIndex = 0 ;
186168
@@ -195,23 +177,16 @@ private static void VerifyDiagnosticLocations([NotNull] AnalysisResult result)
195177
196178 private sealed class AnalysisResult
197179 {
198- [ NotNull ]
199- [ ItemNotNull ]
200180 public IList < Diagnostic > Diagnostics { get ; }
201181
202- [ NotNull ]
203- [ ItemNotNull ]
204182 public IList < Diagnostic > DiagnosticsWithLocation => Diagnostics . Where ( diagnostic => diagnostic . Location . IsInSource ) . ToArray ( ) ;
205183
206- [ NotNull ]
207184 public IList < TextSpan > SpansExpected { get ; }
208185
209- [ NotNull ]
210- [ ItemNotNull ]
211186 public IList < string > MessagesExpected { get ; }
212187
213- public AnalysisResult ( [ NotNull ] [ ItemNotNull ] IList < Diagnostic > diagnostics , [ NotNull ] IList < TextSpan > spansExpected ,
214- [ NotNull ] [ ItemNotNull ] IList < string > messagesExpected )
188+ public AnalysisResult ( IList < Diagnostic > diagnostics , IList < TextSpan > spansExpected ,
189+ IList < string > messagesExpected )
215190 {
216191 FrameworkGuard . NotNull ( diagnostics , nameof ( diagnostics ) ) ;
217192 FrameworkGuard . NotNull ( spansExpected , nameof ( spansExpected ) ) ;
0 commit comments