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


C# SyntaxToken.Kind方法代码示例

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


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

示例1: GetClassification

        /// <summary>
        /// Determine the classification type for a given token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns>The correct syntactic classification for the token.</returns>
        public static string GetClassification(SyntaxToken token)
        {
            if (SyntaxFacts.IsKeywordKind(token.Kind()))
            {
                return ClassificationTypeNames.Keyword;
            }
            else if (SyntaxFacts.IsPunctuation(token.Kind()))
            {
                return GetClassificationForPunctuation(token);
            }
            else if (token.Kind() == SyntaxKind.IdentifierToken)
            {
                return GetClassificationForIdentifier(token);
            }
            else if (IsStringToken(token))
            {
                return IsVerbatimStringToken(token)
                    ? ClassificationTypeNames.VerbatimStringLiteral
                    : ClassificationTypeNames.StringLiteral;
            }
            else if (token.Kind() == SyntaxKind.NumericLiteralToken)
            {
                return ClassificationTypeNames.NumericLiteral;
            }

            return null;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:32,代码来源:ClassificationHelpers.cs

示例2: FormatToken

        public IList<TextChange> FormatToken(Workspace workspace, SyntaxToken token, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(token.Kind() == SyntaxKind.None || token.Kind() == SyntaxKind.EndOfFileToken);

            // get previous token
            var previousToken = token.GetPreviousToken(includeZeroWidth: true);
            if (previousToken.Kind() == SyntaxKind.None)
            {
                // no previous token. nothing to format
                return SpecializedCollections.EmptyList<TextChange>();
            }

            // This is a heuristic to prevent brace completion from breaking user expectation/muscle memory in common scenarios (see Devdiv:823958).
            // Formatter uses FindToken on the position, which returns token to left, if there is nothing to the right and returns token to the right
            // if there exists one. If the shape is "{|}", we're including '}' in the formatting range. Avoid doing that to improve verbatim typing
            // in the following special scenarios.  
            int adjustedEndPosition = token.Span.End;
            if (token.IsKind(SyntaxKind.OpenBraceToken) &&
                (token.Parent.IsInitializerForArrayOrCollectionCreationExpression() ||
                    token.Parent is AnonymousObjectCreationExpressionSyntax))
            {
                var nextToken = token.GetNextToken(includeZeroWidth: true);
                if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
                {
                    // Format upto '{' and exclude '}'
                    adjustedEndPosition = token.SpanStart;
                }
            }

            var smartTokenformattingRules = (new SmartTokenFormattingRule()).Concat(_formattingRules);
            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(previousToken.SpanStart, adjustedEndPosition) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:32,代码来源:SmartTokenFormatter.cs

示例3: FindAppropriateRangeWorker

        private static ValueTuple<SyntaxToken, SyntaxToken>? FindAppropriateRangeWorker(SyntaxToken endToken, bool useDefaultRange)
        {
            // special token that we know how to find proper starting token
            switch (endToken.Kind())
            {
                case SyntaxKind.CloseBraceToken:
                    {
                        return FindAppropriateRangeForCloseBrace(endToken);
                    }

                case SyntaxKind.SemicolonToken:
                    {
                        return FindAppropriateRangeForSemicolon(endToken);
                    }

                case SyntaxKind.ColonToken:
                    {
                        return FindAppropriateRangeForColon(endToken);
                    }

                default:
                    {
                        // default case
                        if (!useDefaultRange)
                        {
                            return null;
                        }

                        // if given token is skipped token, don't bother to find appropriate
                        // starting point
                        if (endToken.Kind() == SyntaxKind.SkippedTokensTrivia)
                        {
                            return null;
                        }

                        var parent = endToken.Parent;
                        if (parent == null)
                        {
                            // if there is no parent setup yet, nothing we can do here.
                            return null;
                        }

                        // if we are called due to things in trivia or literals, don't bother
                        // finding a starting token
                        if (parent.Kind() == SyntaxKind.StringLiteralExpression ||
                            parent.Kind() == SyntaxKind.CharacterLiteralExpression)
                        {
                            return null;
                        }

                        // format whole node that containing the end token + its previous one
                        // to do indentation
                        return ValueTuple.Create(GetAppropriatePreviousToken(parent.GetFirstToken()), parent.GetLastToken());
                    }
            }
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:56,代码来源:FormattingRangeHelper.cs

示例4: IsAnonymousObjectCreation

        private bool IsAnonymousObjectCreation(SyntaxToken token)
        {
            if (token.Parent is AnonymousObjectCreationExpressionSyntax)
            {
                // We'll show the builder after an open brace or comma, because that's where the
                // user can start declaring new named parts. 
                return token.Kind() == SyntaxKind.OpenBraceToken || token.Kind() == SyntaxKind.CommaToken;
            }

            return false;
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:11,代码来源:CSharpSuggestionModeCompletionProvider.cs

示例5: VisitToken

            public override SyntaxToken VisitToken(SyntaxToken token)
            {
                if (_lastTokenEndedInWhitespace)
                {
                    token = token.WithLeadingTrivia(Enumerable.Empty<SyntaxTrivia>());
                }
                else if (token.LeadingTrivia.Count > 0)
                {
                    if (_useElasticTrivia)
                    {
                        token = token.WithLeadingTrivia(SyntaxFactory.ElasticSpace);
                    }
                    else
                    {
                        token = token.WithLeadingTrivia(SyntaxFactory.Space);
                    }
                }

                if (token.TrailingTrivia.Count > 0)
                {
                    if (_useElasticTrivia)
                    {
                        token = token.WithTrailingTrivia(SyntaxFactory.ElasticSpace);
                    }
                    else
                    {
                        token = token.WithTrailingTrivia(SyntaxFactory.Space);
                    }

                    _lastTokenEndedInWhitespace = true;
                }
                else
                {
                    _lastTokenEndedInWhitespace = false;
                }

                if (token.Kind() == SyntaxKind.StringLiteralToken ||
                    token.Kind() == SyntaxKind.InterpolatedStringTextToken)
                {
                    if (s_newlinePattern.IsMatch(token.Text))
                    {
                        var newText = s_newlinePattern.Replace(token.Text, " ");
                        token = SyntaxFactory.Token(
                            token.LeadingTrivia,
                            token.Kind(),
                            newText, newText,
                            token.TrailingTrivia);
                    }
                }
 
                return token;
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:52,代码来源:SyntaxNodeExtensions.SingleLineRewriter.cs

示例6: GetAssignmentOperator

 internal static SyntaxKind GetAssignmentOperator(SyntaxToken token)
 {
     switch (token.Kind())
     {
         case SyntaxKind.AmpersandToken:
             return SyntaxKind.AndAssignmentExpression;
         case SyntaxKind.BarToken:
             return SyntaxKind.OrAssignmentExpression;
         case SyntaxKind.CaretToken:
             return SyntaxKind.ExclusiveOrAssignmentExpression;
         case SyntaxKind.PlusToken:
             return SyntaxKind.AddAssignmentExpression;
         case SyntaxKind.MinusToken:
             return SyntaxKind.SubtractAssignmentExpression;
         case SyntaxKind.AsteriskToken:
             return SyntaxKind.MultiplyAssignmentExpression;
         case SyntaxKind.SlashToken:
             return SyntaxKind.DivideAssignmentExpression;
         case SyntaxKind.PercentToken:
             return SyntaxKind.ModuloAssignmentExpression;
         case SyntaxKind.LessThanLessThanToken:
             return SyntaxKind.LeftShiftAssignmentExpression;
         case SyntaxKind.GreaterThanGreaterThanToken:
             return SyntaxKind.RightShiftAssignmentExpression;
         default:
             return SyntaxKind.None;
     }
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:28,代码来源:ReplaceWithOperatorAssignmentCodeRefactoringProvider.cs

示例7: IsColonInSwitchLabel

 public static bool IsColonInSwitchLabel(SyntaxToken token)
 {
     var switchLabel = token.Parent as SwitchLabelSyntax;
     return token.Kind() == SyntaxKind.ColonToken &&
         switchLabel != null &&
         switchLabel.ColonToken == token;
 }
开发者ID:MischkowskyM,项目名称:roslyn,代码行数:7,代码来源:FormattingRangeHelper.cs

示例8: IsWithinNaturalLanguage

        protected override bool IsWithinNaturalLanguage(SyntaxToken token, int position)
        {
            switch (token.Kind())
            {
                case SyntaxKind.StringLiteralToken:
                    // This, in combination with the override of GetExtentOfWordFromToken() below, treats the closing
                    // quote as a separate token.  This maintains behavior with VS2013.
                    if (position == token.Span.End - 1 && token.Text.EndsWith("\"", StringComparison.Ordinal))
                    {
                        return false;
                    }

                    return true;

                case SyntaxKind.CharacterLiteralToken:
                    // Before the ' is considered outside the character
                    return position != token.SpanStart;

                case SyntaxKind.InterpolatedStringTextToken:
                case SyntaxKind.XmlTextLiteralToken:
                    return true;
            }

            return false;
        }
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:25,代码来源:TextStructureNavigatorProvider.cs

示例9: FormatRange

        public IList<TextChange> FormatRange(
            Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
            Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);

            var smartTokenformattingRules = _formattingRules;
            var common = startToken.GetCommonRoot(endToken);
            if (common.ContainsDiagnostics)
            {
                // if there is errors, do not touch lines
                smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
            }

            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:16,代码来源:SmartTokenFormatter.cs

示例10: IsAfterNameEqualsArgument

        private bool IsAfterNameEqualsArgument(SyntaxToken token)
        {
            var argumentList = token.Parent as AttributeArgumentListSyntax;
            if (token.Kind() == SyntaxKind.CommaToken && argumentList != null)
            {
                foreach (var item in argumentList.Arguments.GetWithSeparators())
                {
                    if (item.IsToken && item.AsToken() == token)
                    {
                        return false;
                    }

                    if (item.IsNode)
                    {
                        var node = item.AsNode() as AttributeArgumentSyntax;
                        if (node.NameEquals != null)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
开发者ID:noahstein,项目名称:roslyn,代码行数:25,代码来源:AttributeNamedParameterCompletionProvider.cs

示例11: FixOpenBraceNextToken

        /// <summary>
        /// Remove the extra new lines on the token which immediately follows an open brace.
        /// </summary>
        private static SyntaxToken FixOpenBraceNextToken(SyntaxToken token)
        {
            if (!token.HasLeadingTrivia)
            {
                return token;
            }

            if (token.Kind() == SyntaxKind.CloseBraceToken &&
                token.LeadingTrivia.All(x => x.IsKind(SyntaxKind.WhitespaceTrivia) || x.IsKind(SyntaxKind.EndOfLineTrivia)))
            {
                // This is an open / close brace combo with no content inbetween.  Just return the 
                // close brace and let the formatter handle the white space issues.  If there was a new line 
                // between the two it will be attached to the open brace and hence maintained. 
                return token.WithLeadingTrivia(SyntaxTriviaList.Empty);
            }

            // Remove all of the new lines at the top
            var triviaList = token.LeadingTrivia;
            var list = new List<SyntaxTrivia>(triviaList.Count);
            var index = MovePastSimpleNewLines(triviaList, 0);

            while (index < triviaList.Count)
            {
                list.Add(triviaList[index]);
                index++;
            }

            var newTriviaList = SyntaxFactory.TriviaList(list);
            return token.WithLeadingTrivia(newTriviaList);
        }
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:33,代码来源:BraceNewLineRule.cs

示例12: TryGetVariable

        private bool TryGetVariable(SyntaxToken token, out PatternVariable variable)
        {
            variable = null;
            if (token.Kind() != SyntaxKind.IdentifierToken)
                return false;

            var variableName = token.ValueText;
            return _variableMap.TryGetValue(variableName, out variable);
        }
开发者ID:terrajobst,项目名称:apiporter,代码行数:9,代码来源:Pattern.cs

示例13: GetAdjustNewLinesOperation

        public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
        {
            if (previousToken.Kind() == SyntaxKind.CommaToken && s_allowableKinds.Contains(previousToken.Parent.Kind()))
            {
                return FormattingOperations.CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
            }

            return base.GetAdjustNewLinesOperation(previousToken, currentToken, optionSet, nextOperation);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:ChangeSignatureFormattingRule.cs

示例14: IsOperator

        public bool IsOperator(SyntaxToken token)
        {
            var kind = token.Kind();

            return
                (SyntaxFacts.IsAnyUnaryExpression(kind) &&
                    (token.Parent is PrefixUnaryExpressionSyntax || token.Parent is PostfixUnaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||
                (SyntaxFacts.IsBinaryExpression(kind) && (token.Parent is BinaryExpressionSyntax || token.Parent is OperatorDeclarationSyntax)) ||
                (SyntaxFacts.IsAssignmentExpressionOperatorToken(kind) && token.Parent is AssignmentExpressionSyntax);
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:10,代码来源:CSharpSyntaxFactsService.cs

示例15: FormatRange

        public IList<TextChange> FormatRange(
            Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
            Contract.ThrowIfTrue(endToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.EndOfFileToken);

            var smartTokenformattingRules = _formattingRules;
            var common = startToken.GetCommonRoot(endToken);

            // if there are errors, do not touch lines
            // Exception: In the case of try-catch-finally block, a try block without a catch/finally block is considered incomplete
            //            but we would like to apply line operation in a completed try block even if there is no catch/finally block
            if (common.ContainsDiagnostics && !CloseBraceOfTryBlock(endToken))
            {
                smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
            }

            return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
        }
开发者ID:vmussak,项目名称:roslyn,代码行数:19,代码来源:SmartTokenFormatter.cs


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