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


C# SyntaxNode.FindTokenOnLeftOfPosition方法代码示例

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


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

示例1: GetTokensAtEdges

        private Dictionary<TriviaLocation, SyntaxToken> GetTokensAtEdges(SyntaxNode root, TextSpan textSpan)
        {
            var tokens = new Dictionary<TriviaLocation, SyntaxToken>();
			tokens[TriviaLocation.AfterBeginningOfSpan] = root.FindTokenOnRightOfPosition(textSpan.Start, includeSkipped: false);
            tokens[TriviaLocation.BeforeBeginningOfSpan] = tokens[TriviaLocation.AfterBeginningOfSpan].GetPreviousToken(includeZeroWidth: true);
			tokens[TriviaLocation.BeforeEndOfSpan] = root.FindTokenOnLeftOfPosition(textSpan.End, includeSkipped: false);
            tokens[TriviaLocation.AfterEndOfSpan] = tokens[TriviaLocation.BeforeEndOfSpan].GetNextToken(includeZeroWidth: true);
            return tokens;
        }
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:9,代码来源:AbstractSyntaxTriviaService.cs

示例2: GetInitialSelectionInfo

        private SelectionInfo GetInitialSelectionInfo(SyntaxNode root, SourceText text, CancellationToken cancellationToken)
        {
            var adjustedSpan = GetAdjustedSpan(text, this.OriginalSpan);

            var firstTokenInSelection = root.FindTokenOnRightOfPosition(adjustedSpan.Start, includeSkipped: false);
            var lastTokenInSelection = root.FindTokenOnLeftOfPosition(adjustedSpan.End, includeSkipped: false);

            if (firstTokenInSelection.Kind() == SyntaxKind.None || lastTokenInSelection.Kind() == SyntaxKind.None)
            {
                return new SelectionInfo { Status = new OperationStatus(OperationStatusFlag.None, CSharpFeaturesResources.InvalidSelection), OriginalSpan = adjustedSpan };
            }

            if (!adjustedSpan.Contains(firstTokenInSelection.Span) && !adjustedSpan.Contains(lastTokenInSelection.Span))
            {
                return new SelectionInfo
                {
                    Status = new OperationStatus(OperationStatusFlag.None, CSharpFeaturesResources.SelectionDoesNotContainAValidToken),
                    OriginalSpan = adjustedSpan,
                    FirstTokenInOriginalSpan = firstTokenInSelection,
                    LastTokenInOriginalSpan = lastTokenInSelection
                };
            }

            if (!firstTokenInSelection.UnderValidContext() || !lastTokenInSelection.UnderValidContext())
            {
                return new SelectionInfo
                {
                    Status = new OperationStatus(OperationStatusFlag.None, CSharpFeaturesResources.NoValidSelectionToPerformExtraction),
                    OriginalSpan = adjustedSpan,
                    FirstTokenInOriginalSpan = firstTokenInSelection,
                    LastTokenInOriginalSpan = lastTokenInSelection
                };
            }

            var commonRoot = firstTokenInSelection.GetCommonRoot(lastTokenInSelection);
            if (commonRoot == null)
            {
                return new SelectionInfo
                {
                    Status = new OperationStatus(OperationStatusFlag.None, CSharpFeaturesResources.NoCommonRootNodeForExtraction),
                    OriginalSpan = adjustedSpan,
                    FirstTokenInOriginalSpan = firstTokenInSelection,
                    LastTokenInOriginalSpan = lastTokenInSelection
                };
            }

            var selectionInExpression = commonRoot is ExpressionSyntax;
            if (!selectionInExpression && !commonRoot.UnderValidContext())
            {
                return new SelectionInfo
                {
                    Status = new OperationStatus(OperationStatusFlag.None, CSharpFeaturesResources.NoValidSelectionToPerformExtraction),
                    OriginalSpan = adjustedSpan,
                    FirstTokenInOriginalSpan = firstTokenInSelection,
                    LastTokenInOriginalSpan = lastTokenInSelection
                };
            }

            return new SelectionInfo
            {
                Status = OperationStatus.Succeeded,
                OriginalSpan = adjustedSpan,
                CommonRootFromOriginalSpan = commonRoot,
                SelectionInExpression = selectionInExpression,
                FirstTokenInOriginalSpan = firstTokenInSelection,
                LastTokenInOriginalSpan = lastTokenInSelection
            };
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:68,代码来源:CSharpSelectionValidator.cs


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