コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
ファイル: CodeGenerator.cs プロジェクト: mphome/Roslynator
        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);
            }
        }
コード例 #6
0
        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));
        }