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


C# SyntaxNode.FindTokenFromEnd方法代码示例

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


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

示例1: GetFormattingSpan

        public static TextSpan GetFormattingSpan(SyntaxNode root, TextSpan span)
        {
            Contract.ThrowIfNull(root);

            var startToken = root.FindToken(span.Start).GetPreviousToken();
            var endToken = root.FindTokenFromEnd(span.End).GetNextToken();

            var startPosition = startToken.SpanStart;
            var endPosition = endToken.RawKind == 0 ? root.Span.End : endToken.Span.End;

            return TextSpan.FromBounds(startPosition, endPosition);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:12,代码来源:CommonFormattingHelpers.cs

示例2: GetOwningNodes

        /// <summary>
        /// find owning usings/field/statement/expression-bodied member of the given position
        /// </summary>
        private static IEnumerable<SyntaxNode> GetOwningNodes(SyntaxNode root, int position)
        {
            // make sure caret position is somewhere we can find a token
            var token = root.FindTokenFromEnd(position);
            if (token.Kind() == SyntaxKind.None)
            {
                return SpecializedCollections.EmptyEnumerable<SyntaxNode>();
            }

            return token.GetAncestors<SyntaxNode>()
                        .Where(AllowedConstructs)
                        .Select(OwningNode);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:16,代码来源:AutomaticLineEnderCommandHandler.cs

示例3: GetTokens

        private static void GetTokens(SyntaxNode root, TextSpan span, out SyntaxToken token1, out SyntaxToken token2)
        {
            // get tokens within given span
            token1 = root.FindToken(span.Start);
            token2 = root.FindTokenFromEnd(span.End);

            // It is possible the given span doesn't have any tokens in them. In that case, 
            // make tokens to be the adjacent ones to the given span.
            if (span.End < token1.Span.Start)
            {
                token1 = token1.GetPreviousToken();
            }

            if (token2.Span.End < span.Start)
            {
                token2 = token2.GetNextToken();
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:BaseIndentationFormattingRule.cs

示例4: GetTokensAroundSpan

        /// <summary>
        /// retrieve 4 tokens around span like below.
        ///
        /// [previousToken][startToken][SPAN][endToken][nextToken]
        /// </summary>
        private static void GetTokensAroundSpan(
            SyntaxNode root, TextSpan span,
            out SyntaxToken previousToken,
            out SyntaxToken startToken,
            out SyntaxToken endToken,
            out SyntaxToken nextToken)
        {
            // get tokens at the edges of the span
            startToken = root.FindToken(span.Start, findInsideTrivia: true);

            endToken = root.FindTokenFromEnd(span.End, findInsideTrivia: true);

            // there must be tokens at each edge
            Contract.ThrowIfTrue(startToken.RawKind == 0 || endToken.RawKind == 0);

            // get previous and next tokens around span
            previousToken = startToken.GetPreviousToken(includeZeroWidth: true, includeSkipped: true, includeDirectives: true, includeDocumentationComments: true);
            nextToken = endToken.GetNextToken(includeZeroWidth: true, includeSkipped: true, includeDirectives: true, includeDocumentationComments: true);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:24,代码来源:AbstractCodeCleanerService.cs

示例5: GetOwningNode

        /// <summary>
        /// find owning usings/field/statement of the given position
        /// </summary>
        private static SyntaxNode GetOwningNode(SyntaxNode root, int position)
        {
            // make sure caret position is somewhere we can find a token
            var token = root.FindTokenFromEnd(position);
            if (token.Kind() == SyntaxKind.None)
            {
                return null;
            }

            return token.GetAncestors<SyntaxNode>()
                        .Where(n => n is StatementSyntax || n is BaseFieldDeclarationSyntax || n is UsingDirectiveSyntax)
                        .FirstOrDefault();
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:16,代码来源:AutomaticLineEnderCommandHandler.cs


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