internal void Save(string path) { var settings = new XElement("Settings", new XElement("General", new XElement("PrefixFieldIdentifierWithUnderscore", PrefixFieldIdentifierWithUnderscore))); if (Analyzers.Count > 0) { settings.Add( new XElement("Analyzers", Analyzers .OrderBy(f => f.Key) .Select(f => new XElement("Analyzer", new XAttribute("Id", f.Key), new XAttribute("Value", f.Value))) )); } if (Refactorings.Any(f => !f.Value)) { settings.Add( new XElement("Refactorings", Refactorings .Where(f => !f.Value) .OrderBy(f => f.Key) .Select(f => new XElement("Refactoring", new XAttribute("Id", f.Key), new XAttribute("IsEnabled", f.Value))) )); } if (CodeFixes.Any(f => !f.Value)) { settings.Add( new XElement("CodeFixes", CodeFixes .Where(f => !f.Value) .OrderBy(f => f.Key) .Select(f => new XElement("CodeFix", new XAttribute("Id", f.Key), new XAttribute("IsEnabled", f.Value))) )); } if (RuleSets.Any()) { settings.Add( new XElement("RuleSets", RuleSets.Select(f => new XElement("RuleSet", new XAttribute("Path", f))))); } var doc = new XDocument(new XElement("Roslynator", settings)); var xmlWriterSettings = new XmlWriterSettings() { OmitXmlDeclaration = false, NewLineChars = Environment.NewLine, IndentChars = " ", Indent = true, }; using (var fileStream = new FileStream(path, FileMode.Create)) using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8)) using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter, xmlWriterSettings)) doc.WriteTo(xmlWriter); }
public string CreateReadMeMarkDown() { using (var sw = new StringWriter()) { sw.WriteLine(File.ReadAllText(@"..\text\ReadMe.txt", Encoding.UTF8)); sw.WriteLine("### List of Analyzers"); sw.WriteLine(); foreach (AnalyzerInfo info in Analyzers .OrderBy(f => f.Id, StringComparer)) { sw.WriteLine("* " + info.Id + " - " + info.Title.TrimEnd('.')); } sw.WriteLine(); sw.WriteLine("### List of Refactorings"); sw.WriteLine(); foreach (RefactoringInfo info in Refactorings .OrderBy(f => f.Title, StringComparer)) { sw.WriteLine("* [" + info.Title.TrimEnd('.') + "](source/Refactorings/README.md#" + info.GetGitHubHref() + ")"); } return(sw.ToString()); } }
public void FindFilesToDelete() { foreach (string path in Directory.EnumerateFiles(GetPath(@"..\docs\refactorings"))) { if (Path.GetFileName(path) != "Refactorings.md" && Refactorings.FirstOrDefault(f => f.Id == Path.GetFileNameWithoutExtension(path)) == null) { Console.WriteLine($"FILE TO DELETE: {path}"); } } }
public void Generate() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkDown(Analyzers.Where(f => !f.IsObsolete), Comparer)); foreach (AnalyzerDescriptor analyzer in Analyzers) { WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkDown(analyzer), fileMustExists: false); } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkDown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer)); foreach (RefactoringDescriptor refactoring in Refactorings) { WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkDown(refactoring), fileMustExists: false); } WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CodeFixes, CompilerDiagnostics, Comparer)); WriteAllText( @"CodeFixes\CodeFixesByDiagnosticId.md", MarkdownGenerator.CreateCodeFixesByDiagnosticId(CodeFixes, CompilerDiagnostics)); WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( @"VisualStudio\description.txt", File.ReadAllText(@"..\text\RoslynatorDescription.txt", Encoding.UTF8)); WriteAllText( @"VisualStudio.Refactorings\description.txt", File.ReadAllText(@"..\text\RoslynatorRefactoringsDescription.txt", Encoding.UTF8)); }
public void Generate() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(Analyzers.Where(f => !f.IsObsolete), Comparer)); foreach (AnalyzerDescriptor analyzer in Analyzers) { WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkdown(analyzer), fileMustExists: false); } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkdown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer)); foreach (RefactoringDescriptor refactoring in Refactorings) { WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkdown(refactoring), fileMustExists: false); } WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CompilerDiagnostics, Comparer)); foreach (CompilerDiagnosticDescriptor diagnostic in CompilerDiagnostics) { WriteAllText( $@"..\docs\cs\{diagnostic.Id}.md", MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, CodeFixes, Comparer), fileMustExists: false); } WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( "DefaultRuleSet.ruleset", XmlGenerator.CreateDefaultRuleSet(Analyzers)); }
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( @"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()); }
public IEnumerable <string> FindMissingImages(string imagesDirPath) { foreach (RefactoringInfo info in Refactorings .OrderBy(f => f.Title, StringComparer)) { foreach (ImageInfo image in info.Images) { string imagePath = Path.Combine(imagesDirPath, image.Name + ".png"); if (!File.Exists(imagePath)) { yield return(imagePath); } } } }
public string CreateRefactoringsMarkDown() { using (var sw = new StringWriter()) { sw.WriteLine("## " + "Roslynator Refactorings"); foreach (RefactoringInfo info in Refactorings .OrderBy(f => f.Title, StringComparer)) { sw.WriteLine(""); sw.WriteLine("#### " + info.Title); sw.WriteLine(""); sw.WriteLine("* **Syntax**: " + string.Join(", ", info.Syntaxes.Select(f => f.Name))); if (!string.IsNullOrEmpty(info.Scope)) { sw.WriteLine("* **Scope**: " + info.Scope); } sw.WriteLine(""); if (info.Images.Count > 0) { bool isFirst = true; foreach (ImageInfo image in info.Images) { if (!isFirst) { sw.WriteLine(); } sw.WriteLine(CreateImageMarkDown(info, image.Name)); isFirst = false; } } else { sw.WriteLine(CreateImageMarkDown(info, info.Identifier)); } } return(sw.ToString()); } }
public virtual void Update(Settings settings) { PrefixFieldIdentifierWithUnderscore = settings.PrefixFieldIdentifierWithUnderscore; Refactorings.Clear(); foreach (KeyValuePair <string, bool> kvp in settings.Refactorings) { Refactorings[kvp.Key] = kvp.Value; } CodeFixes.Clear(); foreach (KeyValuePair <string, bool> kvp in settings.CodeFixes) { CodeFixes[kvp.Key] = kvp.Value; } }
private void WriteRefactoringsExtensionDescription(XmlWriter xw) { xw.WriteElementString("h3", "List of Refactorings"); xw.WriteStartElement("ul"); foreach (RefactoringInfo info in Refactorings .OrderBy(f => f.Title, StringComparer)) { string href = "http://github.com/JosefPihrt/Roslynator/blob/master/source/Refactorings/README.md#" + info.GetGitHubHref(); xw.WriteStartElement("li"); xw.WriteStartElement("a"); xw.WriteAttributeString("href", href); xw.WriteString(info.Title); xw.WriteEndElement(); xw.WriteEndElement(); } xw.WriteEndElement(); }
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); } }
public async Task GenerateAsync() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(Analyzers.Where(f => !f.IsObsolete), Comparer)); VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().Single(); MSBuildLocator.RegisterInstance(instance); using (MSBuildWorkspace workspace = MSBuildWorkspace.Create()) { workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); string solutionPath = Path.Combine(RootPath, "Roslynator.sln"); Console.WriteLine($"Loading solution '{solutionPath}'"); Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false); Console.WriteLine($"Finished loading solution '{solutionPath}'"); RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false); IOrderedEnumerable <SourceFile> sourceFiles = Analyzers .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result)) .Concat(Refactorings .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result))) .OrderBy(f => f.Id); MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml"); foreach (AnalyzerDescriptor analyzer in Analyzers) { //IEnumerable<string> filePaths = await roslynatorInfo.GetAnalyzerFilesAsync(analyzer.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkdown(analyzer, Array.Empty <string>()), fileMustExists: false); } foreach (RefactoringDescriptor refactoring in Refactorings) { //IEnumerable<string> filePaths = await roslynatorInfo.GetRefactoringFilesAsync(refactoring.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkdown(refactoring, Array.Empty <string>()), fileMustExists: false); } foreach (CompilerDiagnosticDescriptor diagnostic in CompilerDiagnostics) { //IEnumerable<string> filePaths = await roslynatorInfo.GetCompilerDiagnosticFilesAsync(diagnostic.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\cs\{diagnostic.Id}.md", MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, CodeFixes, Comparer, Array.Empty <string>()), fileMustExists: false); } } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkdown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CompilerDiagnostics, Comparer)); WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( "DefaultRuleSet.ruleset", XmlGenerator.CreateDefaultRuleSet(Analyzers)); }