示例#1
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());
        }
示例#2
0
        public void Generate()
        {
            WriteCompilationUnit(
                @"Refactorings\RefactoringIdentifiers.Generated.cs",
                RefactoringIdentifiersGenerator.Generate(Refactorings, Comparer));

            WriteCompilationUnit(
                @"VisualStudio.Core\RefactoringsOptionsPage.Generated.cs",
                RefactoringsOptionsPageGenerator.Generate(Refactorings, Comparer));

            WriteCompilationUnit(
                @"Analyzers\DiagnosticDescriptors.Generated.cs",
                DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer));

            WriteCompilationUnit(
                @"Analyzers\DiagnosticDescriptors.Deprecated.Generated.cs",
                DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer));

            WriteCompilationUnit(
                @"Analyzers\DiagnosticIdentifiers.Generated.cs",
                DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer));

            WriteCompilationUnit(
                @"Analyzers\DiagnosticIdentifiers.Deprecated.Generated.cs",
                DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer));

            WriteCompilationUnit(
                @"CodeFixes\CodeFixIdentifiers.Generated.cs",
                CodeFixIdentifiersGenerator.Generate(CodeFixes, Comparer));

            WriteCompilationUnit(
                @"VisualStudio.Core\CodeFixesOptionsPage.Generated.cs",
                CodeFixesOptionsPageGenerator.Generate(CodeFixes, Comparer));

            WriteCompilationUnit(
                @"Core\CSharp\CompilerDiagnosticIdentifiers.cs",
                CompilerDiagnosticIdentifiersGenerator.Generate(CompilerDiagnostics, Comparer));
        }
示例#3
0
        private static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
#if DEBUG
                args = new[] { @"..\..\..\..\.." };
#else
                args = new string[] { Environment.CurrentDirectory };
#endif
            }

            string rootPath = args[0];

            StringComparer comparer = StringComparer.InvariantCulture;

            var metadata = new RoslynatorMetadata(rootPath);

            ImmutableArray <AnalyzerMetadata>           analyzers             = metadata.Analyzers;
            ImmutableArray <AnalyzerMetadata>           codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers;
            ImmutableArray <AnalyzerMetadata>           formattingAnalyzers   = metadata.FormattingAnalyzers;
            ImmutableArray <RefactoringMetadata>        refactorings          = metadata.Refactorings;
            ImmutableArray <CodeFixMetadata>            codeFixes             = metadata.CodeFixes;
            ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics   = metadata.CompilerDiagnostics;

            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));

            WriteDiagnostics(@"Analyzers\CSharp", analyzers, @namespace: "Roslynator.CSharp");

            WriteDiagnostics(@"CodeAnalysis.Analyzers\CSharp", codeAnalysisAnalyzers, @namespace: "Roslynator.CodeAnalysis.CSharp");

            WriteDiagnostics(@"Formatting.Analyzers\CSharp", formattingAnalyzers, @namespace: "Roslynator.Formatting.CSharp");

            WriteCompilationUnit(
                @"CodeFixes\CSharp\CompilerDiagnosticDescriptors.Generated.cs",
                CompilerDiagnosticDescriptorsGenerator.Generate(compilerDiagnostics, comparer: comparer, @namespace: "Roslynator.CSharp"),
                normalizeWhitespace: false);

            WriteCompilationUnit(
                @"CodeFixes\CSharp\CodeFixDescriptors.Generated.cs",
                CodeFixDescriptorsGenerator.Generate(codeFixes.Where(f => !f.IsObsolete), comparer: comparer, @namespace: "Roslynator.CSharp"),
                normalizeWhitespace: false);

            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());

            string ruleSetXml = File.ReadAllText(Path.Combine(rootPath, @"Tools\CodeGeneration\DefaultRuleSet.xml"));

            WriteCompilationUnit(
                @"VisualStudio.Common\RuleSetHelpers.Generated.cs",
                RuleSetGenerator.Generate(ruleSetXml));

            File.WriteAllText(
                Path.Combine(rootPath, @"VisualStudioCode\package\src\configurationFiles.generated.ts"),
                @"export const configurationFileContent = {
	ruleset: `"
                + ruleSetXml
                + @"`,
	config: `<?xml version=""1.0"" encoding=""utf-8""?>
<Roslynator>
  <Settings>
    <General>
      <!-- <PrefixFieldIdentifierWithUnderscore>true</PrefixFieldIdentifierWithUnderscore> -->
    </General>
    <Refactorings>
      <!-- <Refactoring Id=""RRxxxx"" IsEnabled=""false"" /> -->
    </Refactorings>
    <CodeFixes>
      <!-- <CodeFix Id=""CSxxxx.RCFxxxx"" IsEnabled=""false"" /> -->
      <!-- <CodeFix Id=""CSxxxx"" IsEnabled=""false"" /> -->
      <!-- <CodeFix Id=""RCFxxxx"" IsEnabled=""false"" /> -->
    </CodeFixes>
  </Settings>
</Roslynator>`
};",
                new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

            Console.WriteLine($"number of analyzers: {analyzers.Count(f => !f.IsObsolete)}");
            Console.WriteLine($"number of code analysis analyzers: {codeAnalysisAnalyzers.Count(f => !f.IsObsolete)}");
            Console.WriteLine($"number of formatting analyzers: {formattingAnalyzers.Count(f => !f.IsObsolete)}");
            Console.WriteLine($"number of refactorings: {refactorings.Length}");
            Console.WriteLine($"number of code fixes: {codeFixes.Length}");
            Console.WriteLine($"number of fixable compiler diagnostics: {codeFixes.SelectMany(f => f.FixableDiagnosticIds).Distinct().Count()}");

            void WriteDiagnostics(
                string dirPath,
                ImmutableArray <AnalyzerMetadata> analyzers,
                string @namespace,
                string descriptorsClassName = "DiagnosticDescriptors",
                string identifiersClassName = "DiagnosticIdentifiers")
            {
                WriteCompilationUnit(
                    Path.Combine(dirPath, $"{descriptorsClassName}.Generated.cs"),
                    DiagnosticDescriptorsGenerator.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName),
                    normalizeWhitespace: false);

                WriteCompilationUnit(
                    Path.Combine(dirPath, $"{descriptorsClassName}.Deprecated.Generated.cs"),
                    DiagnosticDescriptorsGenerator.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName),
                    normalizeWhitespace: false);

                WriteCompilationUnit(
                    Path.Combine(dirPath, $"{identifiersClassName}.Generated.cs"),
                    DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: identifiersClassName));

                WriteCompilationUnit(
                    Path.Combine(dirPath, $"{identifiersClassName}.Deprecated.Generated.cs"),
                    DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: identifiersClassName));

                IEnumerable <AnalyzerMetadata> optionAnalyzers = analyzers.SelectMany(f => f.OptionAnalyzers);

                if (optionAnalyzers.Any())
                {
                    WriteCompilationUnit(
                        Path.Combine(dirPath, "AnalyzerOptions.Generated.cs"),
                        DiagnosticDescriptorsGenerator.Generate(optionAnalyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: "AnalyzerOptions", identifiersClassName: "AnalyzerOptionIdentifiers"),
                        normalizeWhitespace: false,
                        fileMustExist: false);

                    WriteCompilationUnit(
                        Path.Combine(dirPath, "AnalyzerOptionIdentifiers.Generated.cs"),
                        DiagnosticIdentifiersGenerator.Generate(optionAnalyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: "AnalyzerOptionIdentifiers"),
                        fileMustExist: false);
                }

                IEnumerable <string> analyzerOptionIdentifiers = analyzers
                                                                 .SelectMany(f => f.OptionAnalyzers)
                                                                 .Select(f => f.Identifier);

                WriteCompilationUnit(
                    Path.Combine(dirPath, "AnalyzerOptionsAnalyzer.Generated.cs"),
                    AnalyzerOptionsAnalyzerGenerator.Generate(analyzerOptionIdentifiers, @namespace: @namespace),
                    fileMustExist: false);
            }

            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: "Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.",
                    autoGenerated: autoGenerated,
                    normalizeWhitespace: normalizeWhitespace,
                    fileMustExist: fileMustExist,
                    overwrite: overwrite);
            }
        }
示例#4
0
        private static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
#if DEBUG
                args = new string[] { @"..\..\..\..\.." };
#else
                args = new string[] { Environment.CurrentDirectory };
#endif
            }

            string rootPath = args[0];

            StringComparer comparer = StringComparer.InvariantCulture;

            var metadata = new RoslynatorMetadata(rootPath);

            ImmutableArray <AnalyzerMetadata>           analyzers             = metadata.Analyzers;
            ImmutableArray <AnalyzerMetadata>           codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers;
            ImmutableArray <RefactoringMetadata>        refactorings          = metadata.Refactorings;
            ImmutableArray <CodeFixMetadata>            codeFixes             = metadata.CodeFixes;
            ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics   = metadata.CompilerDiagnostics;

            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));

            WriteDiagnostics(@"Analyzers\CSharp", analyzers, @namespace: "Roslynator.CSharp");

            WriteDiagnostics(@"CodeAnalysis.Analyzers\CSharp", codeAnalysisAnalyzers, @namespace: "Roslynator.CodeAnalysis.CSharp");

            WriteCompilationUnit(
                @"CodeFixes\CSharp\CompilerDiagnosticDescriptors.Generated.cs",
                CompilerDiagnosticDescriptorsGenerator.Generate(compilerDiagnostics, comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false);

            WriteCompilationUnit(
                @"CodeFixes\CSharp\CodeFixDescriptors.Generated.cs",
                CodeFixDescriptorsGenerator.Generate(codeFixes.Where(f => !f.IsObsolete), comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false);

            WriteCompilationUnit(
                @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs",
                CodeFixIdentifiersGenerator.Generate(codeFixes, comparer));

            WriteCompilationUnit(
                @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs",
                CodeFixesOptionsPageGenerator.Generate(codeFixes, compilerDiagnostics, 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());

            Console.WriteLine($"number of analyzers: {analyzers.Count(f => !f.IsObsolete)}");
            Console.WriteLine($"number of code analysis analyzers: {codeAnalysisAnalyzers.Count(f => !f.IsObsolete)}");
            Console.WriteLine($"number of refactorings: {refactorings.Length}");
            Console.WriteLine($"number of code fixes: {codeFixes.Length}");
            Console.WriteLine($"number of fixable compiler diagnostics: {codeFixes.SelectMany(f => f.FixableDiagnosticIds).Distinct().Count()}");

            void WriteDiagnostics(string dirPath, ImmutableArray <AnalyzerMetadata> analyzers2, string @namespace)
            {
                WriteCompilationUnit(
                    Path.Combine(dirPath, "DiagnosticDescriptors.Generated.cs"),
                    DiagnosticDescriptorsGenerator.Generate(analyzers2, obsolete: false, comparer: comparer, @namespace: @namespace), normalizeWhitespace: false);

                WriteCompilationUnit(
                    Path.Combine(dirPath, "DiagnosticDescriptors.Deprecated.Generated.cs"),
                    DiagnosticDescriptorsGenerator.Generate(analyzers2, obsolete: true, comparer: comparer, @namespace: @namespace), normalizeWhitespace: false);

                WriteCompilationUnit(
                    Path.Combine(dirPath, "DiagnosticIdentifiers.Generated.cs"),
                    DiagnosticIdentifiersGenerator.Generate(analyzers2, obsolete: false, comparer: comparer, @namespace: @namespace));

                WriteCompilationUnit(
                    Path.Combine(dirPath, "DiagnosticIdentifiers.Deprecated.Generated.cs"),
                    DiagnosticIdentifiersGenerator.Generate(analyzers2, obsolete: true, comparer: comparer, @namespace: @namespace));
            }

            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: "Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.",
                    autoGenerated: autoGenerated,
                    normalizeWhitespace: normalizeWhitespace,
                    fileMustExist: fileMustExist,
                    overwrite: overwrite);
            }
        }
示例#5
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(
                @"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);
            }
        }