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


C# SyntaxTree.FindTokenOnLeftOfPosition方法代码示例

本文整理汇总了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;
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:19,代码来源:PartialMethodCompletionProvider.cs

示例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> ();
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:22,代码来源:ObjectInitializerContextHandler.cs

示例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;
		}
开发者ID:powerumc,项目名称:monodevelop_korean,代码行数:20,代码来源:ObjectCreationContextHandler.cs

示例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;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:31,代码来源:PartialContextHandler.cs

示例5: GetToken

 protected override SyntaxToken GetToken(CompletionItem completionItem, SyntaxTree tree, CancellationToken cancellationToken)
 {
     var tokenSpanEnd = MemberInsertionCompletionItem.GetTokenSpanEnd(completionItem);
     return tree.FindTokenOnLeftOfPosition(tokenSpanEnd, cancellationToken);
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:5,代码来源:PartialMethodCompletionProvider.cs


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