本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxTree.FindTokenOnLeftOfPosition方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTree.FindTokenOnLeftOfPosition方法的具体用法?C# SyntaxTree.FindTokenOnLeftOfPosition怎么用?C# SyntaxTree.FindTokenOnLeftOfPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxTree
的用法示例。
在下文中一共展示了SyntaxTree.FindTokenOnLeftOfPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsPartialMethodCompletionContext
protected override bool IsPartialMethodCompletionContext(SyntaxTree tree, int position, CancellationToken cancellationToken, out DeclarationModifiers modifiers, out SyntaxToken token)
{
var touchingToken = tree.FindTokenOnLeftOfPosition(position, cancellationToken);
var targetToken = touchingToken.GetPreviousTokenIfTouchingWord(position);
var text = tree.GetText(cancellationToken);
token = targetToken;
modifiers = default(DeclarationModifiers);
if (targetToken.IsKind(SyntaxKind.VoidKeyword, SyntaxKind.PartialKeyword) ||
(targetToken.Kind() == SyntaxKind.IdentifierToken && targetToken.HasMatchingText(SyntaxKind.PartialKeyword)))
{
return !IsOnSameLine(touchingToken.GetNextToken(), touchingToken, text) &&
VerifyModifiers(tree, position, cancellationToken, out modifiers);
}
return false;
}
示例2: GetInitializedMembers
static HashSet<string> GetInitializedMembers (SyntaxTree tree, int position, CancellationToken cancellationToken)
{
var token = tree.FindTokenOnLeftOfPosition (position, cancellationToken)
.GetPreviousTokenIfTouchingWord (position);
// We should have gotten back a { or ,
if (token.Kind () == SyntaxKind.CommaToken || token.Kind () == SyntaxKind.OpenBraceToken) {
if (token.Parent != null) {
var initializer = token.Parent as InitializerExpressionSyntax;
if (initializer != null) {
return new HashSet<string> (initializer.Expressions.OfType<AssignmentExpressionSyntax> ()
.Where (b => b.OperatorToken.Kind () == SyntaxKind.EqualsToken)
.Select (b => b.Left)
.OfType<IdentifierNameSyntax> ()
.Select (i => i.Identifier.ValueText));
}
}
}
return new HashSet<string> ();
}
示例3: GetObjectCreationNewExpression
internal static SyntaxNode GetObjectCreationNewExpression (SyntaxTree tree, int position, CancellationToken cancellationToken)
{
if (tree != null) {
if (!tree.IsInNonUserCode (position, cancellationToken)) {
var tokenOnLeftOfPosition = tree.FindTokenOnLeftOfPosition (position, cancellationToken);
var newToken = tokenOnLeftOfPosition.GetPreviousTokenIfTouchingWord (position);
// Only after 'new'.
if (newToken.Kind () == SyntaxKind.NewKeyword) {
// Only if the 'new' belongs to an object creation expression (and isn't a 'new'
// modifier on a member).
if (tree.IsObjectCreationTypeContext (position, tokenOnLeftOfPosition, cancellationToken)) {
return newToken.Parent as ExpressionSyntax;
}
}
}
}
return null;
}
示例4: VerifyModifiers
static bool VerifyModifiers(SyntaxTree tree, int position, CancellationToken cancellationToken/*, out DeclarationModifiers modifiers*/)
{
var touchingToken = tree.FindTokenOnLeftOfPosition(position, cancellationToken);
var token = touchingToken.GetPreviousToken();
bool foundPartial = touchingToken.IsKindOrHasMatchingText(SyntaxKind.PartialKeyword);
bool foundAsync = false;
while (IsOnSameLine(token, touchingToken, tree.GetText(cancellationToken)))
{
if (token.IsKind(SyntaxKind.ExternKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.InternalKeyword))
{
//modifiers = default(DeclarationModifiers);
return false;
}
if (token.IsKindOrHasMatchingText(SyntaxKind.AsyncKeyword))
{
foundAsync = true;
}
foundPartial = foundPartial || token.IsKindOrHasMatchingText(SyntaxKind.PartialKeyword);
token = token.GetPreviousToken();
}
/*modifiers = new DeclarationModifiers()
.WithPartial(true)
.WithAsync (foundAsync);*/
return foundPartial;
}
示例5: GetToken
protected override SyntaxToken GetToken(CompletionItem completionItem, SyntaxTree tree, CancellationToken cancellationToken)
{
var tokenSpanEnd = MemberInsertionCompletionItem.GetTokenSpanEnd(completionItem);
return tree.FindTokenOnLeftOfPosition(tokenSpanEnd, cancellationToken);
}