Exemple #1
0
        private static bool KeywordRequiresEscaping(SyntaxToken id)
        {
            var keywordKind = SyntaxFacts.GetKeywordKind(id.ValueText);

            if (keywordKind == SyntaxKind.None)
            {
                return(false);
            }
            if (!SyntaxFacts.IsPredefinedType(keywordKind))
            {
                return(true);
            }

            // List of the kinds that end in declaration and can have names attached
            return(id.IsKind(CSSyntaxKind.CatchDeclaration,
                             CSSyntaxKind.ClassDeclaration,
                             CSSyntaxKind.DelegateDeclaration,
                             CSSyntaxKind.EnumDeclaration,
                             CSSyntaxKind.EnumMemberDeclaration,
                             CSSyntaxKind.EventDeclaration,
                             CSSyntaxKind.EventFieldDeclaration,
                             CSSyntaxKind.FieldDeclaration,
                             CSSyntaxKind.InterfaceDeclaration,
                             CSSyntaxKind.MethodDeclaration,
                             CSSyntaxKind.PropertyDeclaration,
                             CSSyntaxKind.NamespaceDeclaration,
                             CSSyntaxKind.StructDeclaration,
                             CSSyntaxKind.VariableDeclaration));
        }
        private static bool IsKeywordThatNeedsEscaped(SyntaxToken id)
        {
            var keywordKind = SyntaxFacts.GetKeywordKind(id.ValueText);

            if (keywordKind == SyntaxKind.None)
            {
                return(false);
            }
            if (!SyntaxFacts.IsPredefinedType(keywordKind))
            {
                return(true);
            }

            return(id.IsKind(CSSyntaxKind.CatchDeclaration,
                             CSSyntaxKind.ClassDeclaration,
                             CSSyntaxKind.EnumDeclaration,
                             CSSyntaxKind.EnumMemberDeclaration,
                             CSSyntaxKind.EventDeclaration,
                             CSSyntaxKind.EventFieldDeclaration,
                             CSSyntaxKind.FieldDeclaration,
                             CSSyntaxKind.InterfaceDeclaration,
                             CSSyntaxKind.MethodDeclaration,
                             CSSyntaxKind.PropertyDeclaration,
                             CSSyntaxKind.NamespaceDeclaration,
                             CSSyntaxKind.StructDeclaration,
                             CSSyntaxKind.VariableDeclaration));
        }
Exemple #3
0
        static SyntaxToken ConvertIdentifier(SyntaxToken id)
        {
            var keywordKind = SyntaxFacts.GetKeywordKind(id.ValueText);

            if (keywordKind != SyntaxKind.None && !SyntaxFacts.IsPredefinedType(keywordKind))
            {
                return(SyntaxFactory.Identifier("[" + id.ValueText + "]"));
            }
            return(SyntaxFactory.Identifier(id.ValueText));
        }
        public static SyntaxToken ConvertIdentifier(SyntaxToken id)
        {
            var idText = id.ValueText;

            // Underscore is a special character in VB lexer which continues lines - not sure where to find the whole set of other similar tokens if any
            // Rather than a complicated contextual rename, just add an extra dash to all identifiers and hope this method is consistently used
            if (idText.All(c => c == '_'))
            {
                idText += "_";
            }
            var keywordKind = SyntaxFacts.GetKeywordKind(idText);

            if (keywordKind != SyntaxKind.None && !SyntaxFacts.IsPredefinedType(keywordKind))
            {
                return(SyntaxFactory.Identifier("[" + idText + "]"));
            }
            return(SyntaxFactory.Identifier(idText));
        }