本文整理汇总了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;
}
示例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
};
}