private static void Main(string[] args) { string rootPath = args[0]; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; foreach (string id in args.Skip(1)) { if (_analyzerIdRegex.IsMatch(id)) { AnalyzerMetadata analyzer = analyzers.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (analyzer == null) { Console.WriteLine($"Analyzer '{id}' not found"); continue; } string className = $"{analyzer.Id}{analyzer.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Analyzers.Tests\{className}.cs", AnalyzerTestGenerator.Generate(analyzer, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else if (_refactoringIdRegex.IsMatch(id)) { RefactoringMetadata refactoring = refactorings.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (refactoring == null) { Console.WriteLine($"Refactoring '{id}' not found"); continue; } string className = $"{refactoring.Id}{refactoring.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Refactorings.Tests\{className}.cs", RefactoringTestGenerator.Generate(refactoring, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else if (_codeFixIdRegex.IsMatch(id)) { CompilerDiagnosticMetadata compilerDiagnostic = compilerDiagnostics.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (compilerDiagnostic == null) { Console.WriteLine($"Compiler diagnostic '{id}' not found"); continue; } string className = $"{compilerDiagnostic.Id}{compilerDiagnostic.Identifier}Tests"; WriteCompilationUnit( $@"Tests\CodeFixes.Tests\{className}.cs", CodeFixTestGenerator.Generate(compilerDiagnostic, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else { Console.WriteLine($"Id '{id}' not recognized"); } } void WriteCompilationUnit( string path, CompilationUnitSyntax compilationUnit, bool autoGenerated = true, bool normalizeWhitespace = true, bool fileMustExist = true, bool overwrite = true) { CodeGenerationHelpers.WriteCompilationUnit( path: Path.Combine(rootPath, path), compilationUnit: compilationUnit, banner: CodeGenerationHelpers.CopyrightBanner, autoGenerated: autoGenerated, normalizeWhitespace: normalizeWhitespace, fileMustExist: fileMustExist, overwrite: overwrite); } }
public void Generate() { WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Generated.cs", RefactoringIdentifiersGenerator.Generate(Refactorings, obsolete: false, comparer: Comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Deprecated.Generated.cs", RefactoringIdentifiersGenerator.Generate(Refactorings, obsolete: true, comparer: Comparer)); WriteCompilationUnit( @"VisualStudio.Common\RefactoringsOptionsPage.Generated.cs", RefactoringsOptionsPageGenerator.Generate(Refactorings.Where(f => !f.IsObsolete), Comparer)); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticDescriptors.Generated.cs", DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer), normalizeWhitespace: false); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticDescriptors.Deprecated.Generated.cs", DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer), normalizeWhitespace: false); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticIdentifiers.Generated.cs", DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer)); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticIdentifiers.Deprecated.Generated.cs", DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer)); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs", CodeFixIdentifiersGenerator.Generate(CodeFixes, Comparer)); WriteCompilationUnit( @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs", CodeFixesOptionsPageGenerator.Generate(CodeFixes, Comparer)); WriteCompilationUnit( @"VisualStudio.Common\GlobalSuppressionsOptionsPage.Generated.cs", GlobalSuppressionsOptionsPageGenerator.Generate(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteCompilationUnit( @"CSharp\CSharp\CompilerDiagnosticIdentifiers.Generated.cs", CompilerDiagnosticIdentifiersGenerator.Generate(CompilerDiagnostics, Comparer)); WriteCompilationUnit( @"Tools\CodeGeneration\CSharp\Symbols.Generated.cs", SymbolsGetKindsGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\SyntaxWalkers\CSharpSyntaxNodeWalker.cs", CSharpSyntaxNodeWalkerGenerator.Generate()); foreach (AnalyzerDescriptor analyzer in Analyzers.Where(f => f.IsDevelopment)) { string className = $"{analyzer.Id}{analyzer.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Analyzers.Tests\{className}.cs", AnalyzerTestGenerator.Generate(analyzer, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } foreach (RefactoringDescriptor refactoring in Refactorings.Where(f => f.IsDevelopment)) { string className = $"{refactoring.Id}{refactoring.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Refactorings.Tests\{className}.cs", RefactoringTestGenerator.Generate(refactoring, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } }