当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxToken.IsKeyword方法代码示例

本文整理汇总了C#中SyntaxToken.IsKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsKeyword方法的具体用法?C# SyntaxToken.IsKeyword怎么用?C# SyntaxToken.IsKeyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxToken的用法示例。


在下文中一共展示了SyntaxToken.IsKeyword方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            VisitLeadingTrivia(token);
            bool isProcessed = false;

            if (token.IsKeyword())
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
                isProcessed = true;
            }
            else
            {
                switch (token.Kind)
                {
                    case SyntaxKind.IdentifierToken:
                        writeDelegate(this.GetTokenKind(token), token.GetText(), token.Span.Start);
                        isProcessed = true;
                        break;
                    default:
                        writeDelegate(TokenKind.None, token.GetText(), null);
                        isProcessed = true;
                        break;
                }
            }

            if (!isProcessed)
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
            }
            base.VisitTrailingTrivia(token);
        }
开发者ID:kris444,项目名称:SourceCodeReader,代码行数:31,代码来源:CSharpCodeNavigationSyntaxWalker.cs

示例2: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            VisitLeadingTrivia(token);
            bool isProcessed = false;

            if (token.IsKeyword())
            {
                writeDelegate(TokenKind.None, token.GetText(), null);
                isProcessed = true;
            }
            else
            {
                switch (token.Kind)
                {
                    case SyntaxKind.IdentifierToken:
                        TokenKind tokenKind = this.GetTokenKind(token);
                        if (tokenKind == TokenKind.None)
                        {
                            writeDelegate(TokenKind.None, token.GetText(), null);
                        }
                        else
                        {
                            try
                            {
                                string fullyQualifiedNamed = this.GetFullyQualifiedName(tokenKind, token);
                                writeDelegate(tokenKind, token.GetText(), fullyQualifiedNamed);
                            }
                            catch (Exception)
                            {
                                writeDelegate(TokenKind.None, token.GetText(),null);
                            }
                        }
                        isProcessed = true;
                        break;
                    default:
                        writeDelegate(TokenKind.None,token.GetText(), null);
                        isProcessed = true;
                        break;
                }
            }

            if (!isProcessed)
            {
                writeDelegate(TokenKind.None,token.GetText(), null);
            }
            base.VisitTrailingTrivia(token);
        }
开发者ID:swapneeld,项目名称:SourceCodeReader,代码行数:47,代码来源:CSharpCodeNavigationSyntaxWalker.cs

示例3: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            SyntaxElementWithTrivia element;

            if (token.IsKeyword() || token.IsContextualKeyword())
            {
                // Keyword
                element = token.IsKind(SyntaxKind.PartialKeyword)
                    ? ProcessPartialKeyword(token)
                    : new SyntaxElementWithTrivia(token, SyntaxElementKind.Keyword);
            }
            else if (token.IsKind(SyntaxKind.IdentifierToken))
            {
                // Identifier

                element = ProcessSemanticSymbolIdentifier(token);
            }
            else if (IsStringLitteralToken(token))
            {
                // String litteral
                element = new SyntaxElementWithTrivia(token, SyntaxElementKind.StringLitteral);
            }
            else
            {
                // Litteral
                element = new SyntaxElementWithTrivia(token, SyntaxElementKind.Litteral);
            }

            using (_currentSyntaxElement.PostValue(element))
            {
                VisitLeadingTrivia(token);
                VisitTrailingTrivia(token);
            }

            ResultsAccumulator.Add(element);
        }
开发者ID:pgrefviau,项目名称:SourceMaster,代码行数:36,代码来源:FileSyntaxWalker.cs

示例4: GetAdjustSpacesOperation

        public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustSpacesOperation> nextOperation)
        {
            if (optionSet == null)
            {
                return nextOperation.Invoke();
            }

            System.Diagnostics.Debug.Assert(previousToken.Parent != null && currentToken.Parent != null);

            var previousKind = previousToken.Kind();
            var currentKind = currentToken.Kind();
            var previousParentKind = previousToken.Parent.Kind();
            var currentParentKind = currentToken.Parent.Kind();

            // For Method Declaration
            if (currentToken.IsOpenParenInParameterList() && previousKind == SyntaxKind.IdentifierToken)
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpacingAfterMethodDeclarationName);
            }

            // For Generic Method Declaration
            if (currentToken.IsOpenParenInParameterList() && previousKind == SyntaxKind.GreaterThanToken && previousParentKind == SyntaxKind.TypeParameterList)
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpacingAfterMethodDeclarationName);
            }

            // Case: public static implicit operator string(Program p) { return null; }
            if (previousToken.IsKeyword() && currentToken.IsOpenParenInParameterListOfAConversionOperatorDeclaration())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpacingAfterMethodDeclarationName);
            }

            // Case: public static Program operator !(Program p) { return null; }
            if (previousToken.Parent.IsKind(SyntaxKind.OperatorDeclaration) && currentToken.IsOpenParenInParameterListOfAOperationDeclaration())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpacingAfterMethodDeclarationName);
            }

            if (previousToken.IsOpenParenInParameterList() && currentToken.IsCloseParenInParameterList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceBetweenEmptyMethodDeclarationParentheses);
            }

            if (previousToken.IsOpenParenInParameterList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodDeclarationParenthesis);
            }

            if (currentToken.IsCloseParenInParameterList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodDeclarationParenthesis);
            }

            // For Method Call
            if (currentToken.IsOpenParenInArgumentList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceAfterMethodCallName);
            }

            if (previousToken.IsOpenParenInArgumentList() && currentToken.IsCloseParenInArgumentList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceBetweenEmptyMethodCallParentheses);
            }

            if (previousToken.IsOpenParenInArgumentList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodCallParentheses);
            }

            if (currentToken.IsCloseParenInArgumentList())
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodCallParentheses);
            }

            // For spacing around: typeof, default, and sizeof; treat like a Method Call
            if (currentKind == SyntaxKind.OpenParenToken && IsFunctionLikeKeywordExpressionKind(currentParentKind))
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceAfterMethodCallName);
            }

            if (previousKind == SyntaxKind.OpenParenToken && IsFunctionLikeKeywordExpressionKind(previousParentKind))
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodCallParentheses);
            }

            if (currentKind == SyntaxKind.CloseParenToken && IsFunctionLikeKeywordExpressionKind(currentParentKind))
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceWithinMethodCallParentheses);
            }

            // For Spacing b/n control flow keyword and paren. Parent check not needed.
            if (currentKind == SyntaxKind.OpenParenToken &&
                (previousKind == SyntaxKind.IfKeyword || previousKind == SyntaxKind.WhileKeyword || previousKind == SyntaxKind.SwitchKeyword ||
                previousKind == SyntaxKind.ForKeyword || previousKind == SyntaxKind.ForEachKeyword || previousKind == SyntaxKind.CatchKeyword ||
                previousKind == SyntaxKind.UsingKeyword))
            {
                return AdjustSpacesOperationZeroOrOne(optionSet, CSharpFormattingOptions.SpaceAfterControlFlowStatementKeyword);
            }

            // For spacing between parenthesis and expression
//.........这里部分代码省略.........
开发者ID:stebet,项目名称:roslyn,代码行数:101,代码来源:SpacingFormattingRule.cs

示例5: VisitToken

            public override void VisitToken(SyntaxToken token)
            {
                VisitLeadingTrivia(token);

                var diagnostics = Diagnostics(token);
                if (diagnostics != null)
                {
                    if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
                        Mark(token, "error");
                    else
                        Mark(token, "warning");
                }

                if (token.IsKeyword() || token.IsContextualKeyword())
                {
                    Mark(token, "keyword");
                    var type = GetTokenType(token);
                    if (type.Type != TokenType.Kind.Unknown)
                        ClassifyIdentifierToken(token);
                }

                var kind = token.CSharpContextualKind();
                switch (kind)
                {
                    case SyntaxKind.IdentifierToken:
                        ClassifyIdentifierToken(token); break;

                    case SyntaxKind.StringLiteralToken:
                        Mark(token, "string"); break;

                    case SyntaxKind.NumericLiteralToken:
                        Mark(token, "number"); break;

                    case SyntaxKind.CharacterLiteralToken:
                        Mark(token, "char"); break;
                }

                VisitTrailingTrivia(token);
            }
开发者ID:Runt-Editor,项目名称:Runt,代码行数:39,代码来源:Highlighter.cs

示例6: TryGetTextForKeyword

        private bool TryGetTextForKeyword(SyntaxToken token, Document document, ISyntaxFactsService syntaxFacts, out string text)
        {
            if (token.Kind() == SyntaxKind.InKeyword)
            {
                if (token.GetAncestor<FromClauseSyntax>() != null)
                {
                    text = "from_CSharpKeyword";
                    return true;
                }

                if (token.GetAncestor<JoinClauseSyntax>() != null)
                {
                    text = "join_CSharpKeyword";
                    return true;
                }
            }

            if (token.IsKeyword())
            {
                text = Keyword(token.Text);
                return true;
            }

            if (token.ValueText == "var" && token.IsKind(SyntaxKind.IdentifierToken) &&
                token.Parent.Parent is VariableDeclarationSyntax && token.Parent == ((VariableDeclarationSyntax)token.Parent.Parent).Type)
            {
                text = "var_CSharpKeyword";
                return true;
            }

            if (syntaxFacts.IsTypeNamedDynamic(token, token.Parent))
            {
                text = "dynamic_CSharpKeyword";
                return true;
            }

            text = null;
            return false;
        }
开发者ID:hemaltandel,项目名称:roslyn,代码行数:39,代码来源:CSharpHelpContextService.cs

示例7: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            if (token.IsKeyword() ||
                (token.Kind == SyntaxKind.IdentifierToken && token.ToString() == "var"))
            {
                formatter.SetForegroundBrush(keywordBrush, token.Span.Start, token.Span.Length);
                return;
            }

            switch (token.Kind)
            {
                case SyntaxKind.StringLiteralToken:
                case SyntaxKind.StringLiteralExpression:
                    formatter.SetForegroundBrush(stringBrush, token.Span.Start, token.Span.Length);
                    break;
                case SyntaxKind.IdentifierToken:
                    if (token.Parent is IdentifierNameSyntax)
                    {
                        var parentToken = ((IdentifierNameSyntax)token.Parent);
                        string tokenName = parentToken.ToString();
                        if (parentToken.Parent is ObjectCreationExpressionSyntax ||
                            parentToken.Parent is TypeArgumentListSyntax)
                        {
                            formatter.SetForegroundBrush(typeBrush, token.Span.Start, token.Span.Length);
                        }
                    }
                    break;
                case SyntaxKind.SingleLineCommentTrivia:
                case SyntaxKind.MultiLineCommentTrivia:
                    formatter.SetForegroundBrush(triviaBrush, token.Span.Start, token.Span.Length);
                    break;
            }
        }
开发者ID:aelij,项目名称:svcperf,代码行数:33,代码来源:CSharpTextBox.cs

示例8: IsKeyword

 public bool IsKeyword(SyntaxToken token) => token.IsKeyword();
开发者ID:modulexcite,项目名称:SourceBrowser,代码行数:1,代码来源:CSWalkerUtils.cs

示例9: VisitToken

        public override void VisitToken(SyntaxToken token)
        {
            var itc = new AnnotatedCodeChunk {TextValue = token.Text};

            var node = token.Parent;

            if (token.IsKind(SyntaxKind.IdentifierToken))
            {
                if (node is IdentifierNameSyntax) // var, or variable mention
                {
                    var symbol = SemanticModel.GetSymbolInfo(node).Symbol;

                    if (symbol is INamedTypeSymbol) // var, or variable mention
                    {
                        if (node.ToString() == "var")
                        {
                            itc.CodeType = CodeType.Keyword;
                        }
                        else
                        {
                            itc.CodeType = CodeType.Type;
                        }
                        itc.TooltipValue = GetTooltipForType(symbol as INamedTypeSymbol);
                    }
                    else if (symbol is IFieldSymbol) // variable mention
                    {
                        itc.CodeType = CodeType.Variable;
                        itc.TooltipValue = GetTooltipForType((symbol as IFieldSymbol).Type);
                    }
                    else if (symbol is IMethodSymbol) // method call
                    {
                        itc.CodeType = CodeType.Method;
                        itc.TooltipValue = GetTooltipForMethod(symbol as IMethodSymbol);
                    }
                    else if (symbol is INamespaceSymbol)
                    {
                        itc.CodeType = CodeType.Namespace;
                        itc.TooltipValue = GetTooltipForNamespace(symbol as INamespaceSymbol);
                    }
                    else if (symbol is IPropertySymbol)
                    {
                        itc.CodeType = CodeType.Property;
                        itc.TooltipValue = GetTooltipForProperty(symbol as IPropertySymbol);
                    }
                }

                if (node is VariableDeclaratorSyntax) // variable name declaration
                {
                    var symbol = SemanticModel.GetDeclaredSymbol(node);
                    var typeSymbol = symbol as IFieldSymbol;
                    itc.CodeType = CodeType.Variable;
                    itc.TooltipValue = GetTooltipForType(typeSymbol?.Type);
                }

                if (node is GenericNameSyntax)
                {
                    var symbol = SemanticModel.GetSymbolInfo(node).Symbol;

                    if (symbol is INamedTypeSymbol)
                    {
                        itc.CodeType = CodeType.Type;
                        itc.TooltipValue = GetTooltipForType(symbol as INamedTypeSymbol);
                    }
                }
            }
            else if (node is PredefinedTypeSyntax) // "int"
            {
                var type = SemanticModel.GetTypeInfo(node).Type;
                itc.CodeType = CodeType.Keyword;
                itc.TooltipValue = GetTooltipForType(type);
            }
            
            if (token.IsKeyword())
            {
                itc.CodeType = CodeType.Keyword;
            }
                        
            AddItcAction(itc);

            base.VisitToken(token);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:81,代码来源:ReportingCSharpSyntaxWalker.cs

示例10: IsKeyword

 public bool IsKeyword(SyntaxToken token)
 {
     return token.IsKeyword();
 }
开发者ID:george2giga,项目名称:SourceBrowser,代码行数:4,代码来源:CSWalkerUtils.cs

示例11: VisitToken

        protected override void VisitToken(SyntaxToken token)
        {
            if (token.HasLeadingTrivia)
            {
                foreach (var trivia in token.LeadingTrivia)
                {
                    VisitTrivia(trivia);
                }
            }

            bool isProcessed = false;

            // キーワードであるか
            if (token.IsKeyword())
            {
                view.Add(new Syntax(token.ValueText, ConsoleColor.Blue));
                isProcessed = true;

            }
            else
            {
                switch (token.Kind())
                {
                    // 各種リテラルであるか
                    case SyntaxKind.StringLiteralToken:
                        view.Add(new Syntax('"' + token.ValueText + '"', ConsoleColor.Red));
                        isProcessed = true;
                        break;
                    case SyntaxKind.CharacterLiteralToken:
                        view.Add(new Syntax(token.ValueText, ConsoleColor.Magenta));
                        isProcessed = true;
                        break;
                    case SyntaxKind.NumericLiteralToken:
                        view.Add(new Syntax(token.ValueText, ConsoleColor.DarkGreen));
                        isProcessed = true;
                        break;
                    case SyntaxKind.IdentifierToken:
                        // 何かの名前(変数等)を参照しようとした場合
                        if (token.Parent is SimpleNameSyntax)
                        {
                            var name = (SimpleNameSyntax)token.Parent;
                            // 参照先に関する情報を取得
                            var info = semanticModel.GetSymbolInfo(name);
                            if (info.Symbol != null && info.Symbol.Kind != SymbolKind.ErrorType)
                            {
                                switch (info.Symbol.Kind)
                                {
                                    case SymbolKind.NamedType:
                                        // クラスや列挙などの場合は色づけ
                                        view.Add(new Syntax(token.ValueText, ConsoleColor.Cyan));
                                        isProcessed = true;
                                        break;
                                    case SymbolKind.Namespace:
                                    case SymbolKind.Parameter:
                                    case SymbolKind.Local:
                                    case SymbolKind.Field:
                                    case SymbolKind.Property:
                                        // それ以外は通常の色
                                        view.Add(new Syntax(token.ValueText, ConsoleColor.White));
                                        isProcessed = true;
                                        break;
                                }
                            }
                        }
                        else if (token.Parent is TypeDeclarationSyntax)
                        {
                            // 宣言時のStatementがヒットした場合
                            var name = (TypeDeclarationSyntax)token.Parent;
                            var info = semanticModel.GetDeclaredSymbol(name);
                            if (info != null && info.Kind != SymbolKind.ErrorType)
                            {
                                switch (info.Kind)
                                {
                                    case SymbolKind.NamedType:
                                        view.Add(new Syntax(token.ValueText, ConsoleColor.Cyan));
                                        isProcessed = true;
                                        break;
                                }
                            }
                        }
                        break;
                }
            }

            // それ以外の項目 (今のところ、特殊例はすべて色づけしない)
            if (!isProcessed)
            {
                view.Add(new Syntax(token.ValueText, ConsoleColor.White));
            }

            if (token.HasTrailingTrivia)
            {
                foreach (var trivia in token.TrailingTrivia)
                {
                    VisitTrivia(trivia);
                }
            }

        }
开发者ID:kkrnt,项目名称:hsp.cs,代码行数:99,代码来源:SyntaxHighlight.cs


注:本文中的SyntaxToken.IsKeyword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。