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