Esempio n. 1
0
        public static CompilationUnitSyntax Generate(IEnumerable <AnalyzerDescriptor> analyzers, bool obsolete, IComparer <string> comparer)
        {
            return(CompilationUnit(
                       UsingDirectives("System"),
                       NamespaceDeclaration("Roslynator.CSharp",
                                            ClassDeclaration(
                                                Modifiers.PublicStaticPartial(),
                                                "DiagnosticIdentifiers",
                                                analyzers
                                                .Where(f => f.IsObsolete == obsolete)
                                                .OrderBy(f => f.Id, comparer)
                                                .Select(f =>
            {
                FieldDeclarationSyntax fieldDeclaration = FieldDeclaration(
                    Modifiers.PublicConst(),
                    PredefinedStringType(),
                    f.Identifier,
                    StringLiteralExpression(f.Id));

                if (f.IsObsolete)
                {
                    fieldDeclaration = fieldDeclaration.AddObsoleteAttributeIf(f.IsObsolete, error: true);
                }

                return fieldDeclaration;
            })
                                                .ToSyntaxList <MemberDeclarationSyntax>()))));
        }
        private static FieldDeclarationSyntax CreateMember(AnalyzerOptionMetadata analyzer, AnalyzerMetadata parent)
        {
            string optionKey = analyzer.OptionKey;

            if (!optionKey.StartsWith("roslynator.", System.StringComparison.Ordinal))
            {
                optionKey = $"roslynator.{analyzer.ParentId}.{optionKey}";
            }

            FieldDeclarationSyntax fieldDeclaration = FieldDeclaration(
                Modifiers.Internal_Static_ReadOnly(),
                IdentifierName(nameof(AnalyzerOptionDescriptor)),
                analyzer.Identifier,
                ObjectCreationExpression(
                    IdentifierName(nameof(AnalyzerOptionDescriptor)),
                    ArgumentList(
                        (analyzer.Id != null)
                            ? Argument(SimpleMemberAccessExpression(IdentifierName("AnalyzerOptionDiagnosticDescriptors"), IdentifierName(analyzer.Identifier)))
                            : Argument(NullLiteralExpression()),
                        Argument(SimpleMemberAccessExpression(IdentifierName("DiagnosticDescriptors"), IdentifierName(parent.Identifier))),
                        Argument(StringLiteralExpression(optionKey)))));

            if (analyzer.IsObsolete)
            {
                fieldDeclaration = fieldDeclaration.AddObsoleteAttributeIf(analyzer.IsObsolete, error: true);
            }

            return(fieldDeclaration);
        }
Esempio n. 3
0
        private static FieldDeclarationSyntax CreateMember(string id, string identifier, bool isObsolete)
        {
            FieldDeclarationSyntax fieldDeclaration = FieldDeclaration(
                Modifiers.Public_Const(),
                PredefinedStringType(),
                identifier,
                StringLiteralExpression(id));

            if (isObsolete)
            {
                fieldDeclaration = fieldDeclaration.AddObsoleteAttributeIf(isObsolete, error: true);
            }

            return(fieldDeclaration);
        }
Esempio n. 4
0
        public static CompilationUnitSyntax Generate(IEnumerable <RefactoringDescriptor> refactorings, bool obsolete, IComparer <string> comparer)
        {
            return(CompilationUnit(
                       UsingDirectives("System"),
                       NamespaceDeclaration("Roslynator.CSharp.Refactorings",
                                            ClassDeclaration(
                                                Modifiers.PublicStaticPartial(),
                                                "RefactoringIdentifiers",
                                                refactorings
                                                .Where(f => f.IsObsolete == obsolete)
                                                .OrderBy(f => f.Identifier, comparer)
                                                .Select(f =>
            {
                FieldDeclarationSyntax fieldDeclaration = FieldDeclaration(
                    Modifiers.PublicConst(),
                    PredefinedStringType(),
                    f.Identifier,
                    AddExpression(IdentifierName("Prefix"), StringLiteralExpression(f.Id.Substring(RefactoringIdentifiers.Prefix.Length))));

                return fieldDeclaration.AddObsoleteAttributeIf(f.IsObsolete);
            })
                                                .ToSyntaxList <MemberDeclarationSyntax>()))));
        }