@@ -6,7 +6,6 @@ namespace DocumentationAnalyzers.Status.Generator
66 using System ;
77 using System . Collections . Generic ;
88 using System . Collections . Immutable ;
9- using System . IO ;
109 using System . Linq ;
1110 using System . Reflection ;
1211 using System . Text . RegularExpressions ;
@@ -24,28 +23,28 @@ namespace DocumentationAnalyzers.Status.Generator
2423 /// </summary>
2524 public class SolutionReader
2625 {
27- private static Regex diagnosticPathRegex = new Regex ( @"(?<type>[A-Za-z]+)Rules\\(?<name>[A-Za-z0-9]+)\.cs$" ) ;
28- private INamedTypeSymbol diagnosticAnalyzerTypeSymbol ;
29- private INamedTypeSymbol noCodeFixAttributeTypeSymbol ;
30-
31- private Solution solution ;
32- private Project analyzerProject ;
33- private Project codeFixProject ;
34- private MSBuildWorkspace workspace ;
35- private Assembly analyzerAssembly ;
36- private Assembly codeFixAssembly ;
37- private Compilation analyzerCompilation ;
38- private Compilation codeFixCompilation ;
39- private ITypeSymbol booleanType ;
40- private Type batchFixerType ;
26+ private static Regex _diagnosticPathRegex = new Regex ( @"(?<type>[A-Za-z]+)Rules\\(?<name>[A-Za-z0-9]+)\.cs$" ) ;
27+ private INamedTypeSymbol _diagnosticAnalyzerTypeSymbol ;
28+ private INamedTypeSymbol _noCodeFixAttributeTypeSymbol ;
29+
30+ private Solution _solution ;
31+ private Project _analyzerProject ;
32+ private Project _codeFixProject ;
33+ private MSBuildWorkspace _workspace ;
34+ private Assembly _analyzerAssembly ;
35+ private Assembly _codeFixAssembly ;
36+ private Compilation _analyzerCompilation ;
37+ private Compilation _codeFixCompilation ;
38+ private ITypeSymbol _booleanType ;
39+ private Type _batchFixerType ;
4140
4241 private SolutionReader ( )
4342 {
4443 AppDomain . CurrentDomain . AssemblyResolve += ( s , e ) =>
4544 {
46- if ( e . Name . Contains ( this . AnalyzerProjectName ) )
45+ if ( e . Name . Contains ( AnalyzerProjectName ) )
4746 {
48- return this . analyzerAssembly ;
47+ return _analyzerAssembly ;
4948 }
5049
5150 return null ;
@@ -74,7 +73,7 @@ public static async Task<SolutionReader> CreateAsync(string pathToSln, string an
7473 reader . SlnPath = pathToSln ;
7574 reader . AnalyzerProjectName = analyzerProjectName ;
7675 reader . CodeFixProjectName = codeFixProjectName ;
77- reader . workspace = MSBuildWorkspace . Create ( ) ;
76+ reader . _workspace = MSBuildWorkspace . Create ( ) ;
7877
7978 await reader . InitializeAsync ( ) . ConfigureAwait ( false ) ;
8079
@@ -89,11 +88,11 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
8988 {
9089 var diagnostics = ImmutableList . CreateBuilder < DocumentationDiagnostic > ( ) ;
9190
92- var syntaxTrees = this . analyzerCompilation . SyntaxTrees ;
91+ var syntaxTrees = _analyzerCompilation . SyntaxTrees ;
9392
9493 foreach ( var syntaxTree in syntaxTrees )
9594 {
96- var match = diagnosticPathRegex . Match ( syntaxTree . FilePath ) ;
95+ var match = _diagnosticPathRegex . Match ( syntaxTree . FilePath ) ;
9796 if ( ! match . Success )
9897 {
9998 continue ;
@@ -104,7 +103,7 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
104103
105104 // Check if this syntax tree represents a diagnostic
106105 SyntaxNode syntaxRoot = await syntaxTree . GetRootAsync ( ) . ConfigureAwait ( false ) ;
107- SemanticModel semanticModel = this . analyzerCompilation . GetSemanticModel ( syntaxTree ) ;
106+ SemanticModel semanticModel = _analyzerCompilation . GetSemanticModel ( syntaxTree ) ;
108107 SyntaxNode classSyntaxNode = syntaxRoot . DescendantNodes ( ) . FirstOrDefault ( x => x . IsKind ( SyntaxKind . ClassDeclaration ) ) ;
109108
110109 if ( classSyntaxNode == null )
@@ -114,7 +113,7 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
114113
115114 INamedTypeSymbol classSymbol = semanticModel . GetDeclaredSymbol ( classSyntaxNode ) as INamedTypeSymbol ;
116115
117- if ( ! this . InheritsFrom ( classSymbol , this . diagnosticAnalyzerTypeSymbol ) )
116+ if ( ! InheritsFrom ( classSymbol , _diagnosticAnalyzerTypeSymbol ) )
118117 {
119118 continue ;
120119 }
@@ -126,12 +125,12 @@ public async Task<ImmutableList<DocumentationDiagnostic>> GetDiagnosticsAsync()
126125
127126 bool hasImplementation = HasImplementation ( syntaxRoot ) ;
128127
129- IEnumerable < DiagnosticDescriptor > descriptorInfos = this . GetDescriptor ( classSymbol ) ;
128+ IEnumerable < DiagnosticDescriptor > descriptorInfos = GetDescriptor ( classSymbol ) ;
130129
131130 foreach ( var descriptorInfo in descriptorInfos )
132131 {
133- var ( codeFixStatus , fixAllStatus ) = this . GetCodeFixAndFixAllStatus ( descriptorInfo . Id , classSymbol , out noCodeFixReason ) ;
134- string status = this . GetStatus ( classSymbol , syntaxRoot , semanticModel , descriptorInfo ) ;
132+ var ( codeFixStatus , fixAllStatus ) = GetCodeFixAndFixAllStatus ( descriptorInfo . Id , classSymbol , out noCodeFixReason ) ;
133+ string status = GetStatus ( classSymbol , syntaxRoot , semanticModel , descriptorInfo ) ;
135134 if ( descriptorInfo . CustomTags . Contains ( WellKnownDiagnosticTags . NotConfigurable ) )
136135 {
137136 continue ;
@@ -176,33 +175,33 @@ private static bool HasImplementation(SyntaxNode syntaxRoot)
176175
177176 private async Task InitializeAsync ( )
178177 {
179- this . solution = await this . workspace . OpenSolutionAsync ( this . SlnPath ) . ConfigureAwait ( false ) ;
178+ _solution = await _workspace . OpenSolutionAsync ( SlnPath ) . ConfigureAwait ( false ) ;
180179
181- this . analyzerProject = this . solution . Projects . First ( x => x . Name == this . AnalyzerProjectName || x . AssemblyName == this . AnalyzerProjectName ) ;
182- this . analyzerCompilation = await this . analyzerProject . GetCompilationAsync ( ) . ConfigureAwait ( false ) ;
183- this . analyzerCompilation = this . analyzerCompilation . WithOptions ( this . analyzerCompilation . Options . WithOutputKind ( OutputKind . DynamicallyLinkedLibrary ) ) ;
180+ _analyzerProject = _solution . Projects . First ( x => x . Name == AnalyzerProjectName || x . AssemblyName == AnalyzerProjectName ) ;
181+ _analyzerCompilation = await _analyzerProject . GetCompilationAsync ( ) . ConfigureAwait ( false ) ;
182+ _analyzerCompilation = _analyzerCompilation . WithOptions ( _analyzerCompilation . Options . WithOutputKind ( OutputKind . DynamicallyLinkedLibrary ) ) ;
184183
185- this . codeFixProject = this . solution . Projects . First ( x => x . Name == this . CodeFixProjectName || x . AssemblyName == this . CodeFixProjectName ) ;
186- this . codeFixCompilation = await this . codeFixProject . GetCompilationAsync ( ) . ConfigureAwait ( false ) ;
187- this . codeFixCompilation = this . codeFixCompilation . WithOptions ( this . codeFixCompilation . Options . WithOutputKind ( OutputKind . DynamicallyLinkedLibrary ) ) ;
184+ _codeFixProject = _solution . Projects . First ( x => x . Name == CodeFixProjectName || x . AssemblyName == CodeFixProjectName ) ;
185+ _codeFixCompilation = await _codeFixProject . GetCompilationAsync ( ) . ConfigureAwait ( false ) ;
186+ _codeFixCompilation = _codeFixCompilation . WithOptions ( _codeFixCompilation . Options . WithOutputKind ( OutputKind . DynamicallyLinkedLibrary ) ) ;
188187
189- this . booleanType = this . analyzerCompilation . GetSpecialType ( SpecialType . System_Boolean ) ;
188+ _booleanType = _analyzerCompilation . GetSpecialType ( SpecialType . System_Boolean ) ;
190189
191- this . LoadAssemblies ( ) ;
190+ LoadAssemblies ( ) ;
192191
193- this . noCodeFixAttributeTypeSymbol = this . analyzerCompilation . GetTypeByMetadataName ( "DocumentationAnalyzers.NoCodeFixAttribute" ) ;
194- this . diagnosticAnalyzerTypeSymbol = this . analyzerCompilation . GetTypeByMetadataName ( typeof ( DiagnosticAnalyzer ) . FullName ) ;
192+ _noCodeFixAttributeTypeSymbol = _analyzerCompilation . GetTypeByMetadataName ( "DocumentationAnalyzers.NoCodeFixAttribute" ) ;
193+ _diagnosticAnalyzerTypeSymbol = _analyzerCompilation . GetTypeByMetadataName ( typeof ( DiagnosticAnalyzer ) . FullName ) ;
195194
196- this . batchFixerType = this . codeFixAssembly . GetType ( "DocumentationAnalyzers.Helpers.CustomBatchFixAllProvider" ) ;
195+ _batchFixerType = _codeFixAssembly . GetType ( "DocumentationAnalyzers.Helpers.CustomBatchFixAllProvider" ) ;
197196
198- this . InitializeCodeFixTypes ( ) ;
197+ InitializeCodeFixTypes ( ) ;
199198 }
200199
201200 private void InitializeCodeFixTypes ( )
202201 {
203- var codeFixTypes = this . codeFixAssembly . GetTypes ( ) . Where ( x => x . FullName . EndsWith ( "CodeFixProvider" ) ) ;
202+ var codeFixTypes = _codeFixAssembly . GetTypes ( ) . Where ( x => x . FullName . EndsWith ( "CodeFixProvider" ) ) ;
204203
205- this . CodeFixProviders = ImmutableArray . Create (
204+ CodeFixProviders = ImmutableArray . Create (
206205 codeFixTypes
207206 . Select ( t => Activator . CreateInstance ( t , true ) )
208207 . OfType < CodeFixProvider > ( )
@@ -212,8 +211,8 @@ private void InitializeCodeFixTypes()
212211
213212 private void LoadAssemblies ( )
214213 {
215- this . analyzerAssembly = this . GetAssembly ( this . analyzerProject ) ;
216- this . codeFixAssembly = this . GetAssembly ( this . codeFixProject ) ;
214+ _analyzerAssembly = GetAssembly ( _analyzerProject ) ;
215+ _codeFixAssembly = GetAssembly ( _codeFixProject ) ;
217216 }
218217
219218 private Assembly GetAssembly ( Project project )
@@ -261,7 +260,7 @@ private string GetStatus(INamedTypeSymbol classSymbol, SyntaxNode root, Semantic
261260
262261 // We use the fact that the only parameter that returns a boolean is the one we are interested in
263262 var enabledByDefaultParameter = from argument in initializer . ArgumentList . Arguments
264- where Equals ( model . GetTypeInfo ( argument . Expression ) . Type , this . booleanType )
263+ where Equals ( model . GetTypeInfo ( argument . Expression ) . Type , _booleanType )
265264 select argument . Expression ;
266265 var parameter = enabledByDefaultParameter . FirstOrDefault ( ) ;
267266 string parameterString = parameter . ToString ( ) ;
@@ -280,7 +279,7 @@ where Equals(model.GetTypeInfo(argument.Expression).Type, this.booleanType)
280279
281280 private IEnumerable < DiagnosticDescriptor > GetDescriptor ( INamedTypeSymbol classSymbol )
282281 {
283- var analyzer = ( DiagnosticAnalyzer ) Activator . CreateInstance ( this . analyzerAssembly . GetType ( classSymbol . ToString ( ) ) ) ;
282+ var analyzer = ( DiagnosticAnalyzer ) Activator . CreateInstance ( _analyzerAssembly . GetType ( classSymbol . ToString ( ) ) ) ;
284283
285284 // This currently only supports one diagnostic for each analyzer.
286285 return analyzer . SupportedDiagnostics ;
@@ -295,7 +294,7 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
295294
296295 var noCodeFixAttribute = classSymbol
297296 . GetAttributes ( )
298- . SingleOrDefault ( x => Equals ( x . AttributeClass , this . noCodeFixAttributeTypeSymbol ) ) ;
297+ . SingleOrDefault ( x => Equals ( x . AttributeClass , _noCodeFixAttributeTypeSymbol ) ) ;
299298
300299 bool hasCodeFix = noCodeFixAttribute == null ;
301300 if ( ! hasCodeFix )
@@ -310,9 +309,9 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
310309 else
311310 {
312311 // Check if the code fix actually exists
313- var codeFixes = this . CodeFixProviders
312+ var codeFixes = CodeFixProviders
314313 . Where ( x => x . FixableDiagnosticIds . Contains ( diagnosticId ) )
315- . Select ( x => this . IsBatchFixer ( x ) )
314+ . Select ( x => IsBatchFixer ( x ) )
316315 . Where ( x => x != null )
317316 . Select ( x => ( bool ) x ) . ToArray ( ) ;
318317
@@ -347,7 +346,7 @@ private IEnumerable<DiagnosticDescriptor> GetDescriptor(INamedTypeSymbol classSy
347346 }
348347 else
349348 {
350- return fixAllProvider . GetType ( ) == this . batchFixerType ;
349+ return fixAllProvider . GetType ( ) == _batchFixerType ;
351350 }
352351 }
353352
0 commit comments