• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SyntaxToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SyntaxToken的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken类的具体用法?C# SyntaxToken怎么用?C# SyntaxToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SyntaxToken类属于命名空间,在下文中一共展示了SyntaxToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TryDetermineOverridableMembers

		static bool TryDetermineOverridableMembers(SemanticModel semanticModel, SyntaxToken startToken, Accessibility seenAccessibility, out ISet<ISymbol> overridableMembers, CancellationToken cancellationToken)
		{
			var result = new HashSet<ISymbol>();
			var containingType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(startToken.SpanStart, cancellationToken);
			if (containingType != null && !containingType.IsScriptClass && !containingType.IsImplicitClass)
			{
				if (containingType.TypeKind == TypeKind.Class || containingType.TypeKind == TypeKind.Struct)
				{
					var baseTypes = containingType.GetBaseTypes().Reverse();
					foreach (var type in baseTypes)
					{
						cancellationToken.ThrowIfCancellationRequested();

						// Prefer overrides in derived classes
						RemoveOverriddenMembers(result, type, cancellationToken);

						// Retain overridable methods
						AddProtocolMembers(semanticModel, result, containingType, type, cancellationToken);
					}
					// Don't suggest already overridden members
					RemoveOverriddenMembers(result, containingType, cancellationToken);
				}
			}

			// Filter based on accessibility
			if (seenAccessibility != Accessibility.NotApplicable)
			{
				result.RemoveWhere(m => m.DeclaredAccessibility != seenAccessibility);
			}

			overridableMembers = result;
			return overridableMembers.Count > 0;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:33,代码来源:ProtocolMemberContextHandler.cs


示例2: GetTextChangeSpan

 private TextSpan GetTextChangeSpan(SyntaxToken stringLiteral, int position)
 {
     return PathCompletionUtilities.GetTextChangeSpan(
         quotedPath: stringLiteral.ToString(),
         quotedPathStart: stringLiteral.SpanStart,
         position: position);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AbstractReferenceDirectiveCompletionProvider.cs


示例3: GetCollapsibleStart

        private static int GetCollapsibleStart(SyntaxToken firstToken)
        {
            // If the *next* token has any leading comments, we use the end of the last one.
            // If not, we check *this* token to see if it has any trailing comments and use the last one;
            // otherwise, we use the end of this token.

            var start = firstToken.Span.End;

            var nextToken = firstToken.GetNextToken();
            if (nextToken.Kind() != SyntaxKind.None && nextToken.HasLeadingTrivia)
            {
                var lastLeadingCommentTrivia = nextToken.LeadingTrivia.GetLastComment();
                if (lastLeadingCommentTrivia != null)
                {
                    start = lastLeadingCommentTrivia.Value.Span.End;
                }
            }

            if (firstToken.HasTrailingTrivia)
            {
                var lastTrailingCommentTrivia = firstToken.TrailingTrivia.GetLastComment();
                if (lastTrailingCommentTrivia != null)
                {
                    start = lastTrailingCommentTrivia.Value.Span.End;
                }
            }

            return start;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:29,代码来源:CSharpOutliningHelpers.cs


示例4: IsAfterNameEqualsArgument

        private bool IsAfterNameEqualsArgument(SyntaxToken token)
        {
            var argumentList = token.Parent as AttributeArgumentListSyntax;
            if (token.Kind() == SyntaxKind.CommaToken && argumentList != null)
            {
                foreach (var item in argumentList.Arguments.GetWithSeparators())
                {
                    if (item.IsToken && item.AsToken() == token)
                    {
                        return false;
                    }

                    if (item.IsNode)
                    {
                        var node = item.AsNode() as AttributeArgumentSyntax;
                        if (node.NameEquals != null)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
开发者ID:noahstein,项目名称:roslyn,代码行数:25,代码来源:AttributeNamedParameterCompletionProvider.cs


示例5: GetTextBetween

            public override string GetTextBetween(SyntaxToken token1, SyntaxToken token2)
            {
                var text = base.GetTextBetween(token1, token2);
                Contract.ThrowIfFalse(text == _debugNodeData.GetTextBetween(token1, token2));

                return text;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:TreeData.Debug.cs


示例6: CheckDeclarationName

        private static void CheckDeclarationName(MemberDeclarationSyntax member, SyntaxToken identifier, SyntaxNodeAnalysisContext context)
        {
            var symbol = context.SemanticModel.GetDeclaredSymbol(member);
            if (ClassName.IsTypeComRelated(symbol?.ContainingType) ||
                symbol.IsInterfaceImplementationOrMemberOverride() ||
                symbol.IsExtern)
            {
                return;
            }

            if (identifier.ValueText.StartsWith("_", StringComparison.Ordinal) ||
                identifier.ValueText.EndsWith("_", StringComparison.Ordinal))
            {
                context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
                    identifier.ValueText, MessageFormatUnderscore));
                return;
            }

            string suggestion;
            if (TryGetChangedName(identifier.ValueText, out suggestion))
            {
                var messageEnding = string.Format(MessageFormatNonUnderscore, suggestion);
                context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
                    identifier.ValueText, messageEnding));
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:26,代码来源:MethodName.cs


示例7: GetPreviousEmptyLines

        private IEnumerable<SyntaxTrivia> GetPreviousEmptyLines(SyntaxToken openBrace)
        {
            var result = new List<SyntaxTrivia>();

            var lineOfOpenBrace = openBrace.GetLineSpan().StartLinePosition.Line;
            var lineToCheck = lineOfOpenBrace - 1;

            while (lineToCheck > -1)
            {
                var trivias = openBrace.LeadingTrivia
                    .Where(t => t.GetLineSpan().StartLinePosition.Line == lineToCheck)
                    .ToList();
                var endOfLineTrivia = trivias.Where(t => t.IsKind(SyntaxKind.EndOfLineTrivia)).ToList();
                if (endOfLineTrivia.Any() && trivias.Except(endOfLineTrivia).All(t => t.IsKind(SyntaxKind.WhitespaceTrivia)))
                {
                    lineToCheck--;
                    result.AddRange(trivias);
                }
                else
                {
                    break;
                }
            }

            return result;
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:26,代码来源:SA1509CodeFixProvider.cs


示例8: MethodDeclaration

 public static MethodDeclarationSyntax MethodDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     TypeSyntax returnType,
     ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
     SyntaxToken identifier,
     TypeParameterListSyntax typeParameterList,
     ParameterListSyntax parameterList,
     SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
     BlockSyntax body,
     SyntaxToken semicolonToken)
 {
     return SyntaxFactory.MethodDeclaration(
         attributeLists,
         modifiers,
         default(SyntaxToken),
         returnType,
         explicitInterfaceSpecifier,
         identifier,
         typeParameterList,
         parameterList,
         constraintClauses,
         body,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:MethodDeclarationSyntax.cs


示例9: HandleCloseBracketToken

        private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
        {
            if (token.IsMissing)
            {
                return;
            }

            if (!token.Parent.IsKind(SyntaxKind.AttributeList))
            {
                return;
            }

            if (token.IsFirstInLine())
            {
                return;
            }

            SyntaxToken precedingToken = token.GetPreviousToken();
            if (!precedingToken.HasTrailingTrivia)
            {
                return;
            }

            if (!precedingToken.TrailingTrivia.Last().IsKind(SyntaxKind.WhitespaceTrivia))
            {
                return;
            }

            // Closing attribute brackets must not be preceded by a space.
            context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.RemoveImmediatePreceding));
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:31,代码来源:SA1017ClosingAttributeBracketsMustBeSpacedCorrectly.cs


示例10: CreatePragmaDirectiveTrivia

        private SyntaxTriviaList CreatePragmaDirectiveTrivia(SyntaxToken disableOrRestoreKeyword, Diagnostic diagnostic, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine)
        {
            var id = SyntaxFactory.IdentifierName(diagnostic.Id);
            var ids = new SeparatedSyntaxList<ExpressionSyntax>().Add(id);
            var pragmaDirective = SyntaxFactory.PragmaWarningDirectiveTrivia(disableOrRestoreKeyword, ids, true);
            var pragmaDirectiveTrivia = SyntaxFactory.Trivia(pragmaDirective.WithAdditionalAnnotations(Formatter.Annotation));
            var endOfLineTrivia = SyntaxFactory.EndOfLine(@"
");
            var triviaList = SyntaxFactory.TriviaList(pragmaDirectiveTrivia);

            var title = diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture);
            if (!string.IsNullOrWhiteSpace(title))
            {
                var titleComment = SyntaxFactory.Comment(string.Format(" // {0}", title)).WithAdditionalAnnotations(Formatter.Annotation);
                triviaList = triviaList.Add(titleComment);
            }

            if (needsLeadingEndOfLine)
            {
                triviaList = triviaList.Insert(0, endOfLineTrivia);
            }

            if (needsTrailingEndOfLine)
            {
                triviaList = triviaList.Add(endOfLineTrivia);
            }

            return triviaList;
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:29,代码来源:CSharpSuppressionCodeFixProvider.cs


示例11: UvssEventTriggerSyntax

        /// <summary>
        /// Initializes a new instance of the <see cref="UvssEventTriggerSyntax"/> class.
        /// </summary>
        internal UvssEventTriggerSyntax(
            SyntaxToken triggerKeyword,
            SyntaxToken eventKeyword,
            UvssEventNameSyntax eventName,
            UvssEventTriggerArgumentList argumentList,
            SyntaxToken qualifierToken,
            UvssBlockSyntax body)
            : base(SyntaxKind.EventTrigger)
        {
            this.TriggerKeyword = triggerKeyword;
            ChangeParent(triggerKeyword);

            this.EventKeyword = eventKeyword;
            ChangeParent(eventKeyword);

            this.EventName = eventName;
            ChangeParent(eventName);

            this.ArgumentList = argumentList;
            ChangeParent(argumentList);

            this.QualifierToken = qualifierToken;
            ChangeParent(qualifierToken);

            this.Body = body;
            ChangeParent(body);

            SlotCount = 6;
            UpdateIsMissing();
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:33,代码来源:UvssEventTriggerSyntax.cs


示例12: HandleOpenBracketToken

        private static void HandleOpenBracketToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
        {
            bool firstInLine = token.IsFirstInLine();
            bool precededBySpace = true;
            bool ignorePrecedingSpaceProblem = false;

            if (!firstInLine)
            {
                precededBySpace = token.IsPrecededByWhitespace();

                // ignore if handled by SA1026
                ignorePrecedingSpaceProblem = precededBySpace && token.GetPreviousToken().IsKind(SyntaxKind.NewKeyword);
            }

            bool followedBySpace = token.IsFollowedByWhitespace();
            bool lastInLine = token.IsLastInLine();

            if (!firstInLine && precededBySpace && !ignorePrecedingSpaceProblem && !lastInLine && followedBySpace)
            {
                // Opening square bracket must {neither preceded nor followed} by a space.
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "neither preceded nor followed"));
            }
            else if (!firstInLine && precededBySpace && !ignorePrecedingSpaceProblem)
            {
                // Opening square bracket must {not be preceded} by a space.
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "not be preceded"));
            }
            else if (!lastInLine && followedBySpace)
            {
                // Opening square bracket must {not be followed} by a space.
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "not be followed"));
            }
        }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:33,代码来源:SA1010OpeningSquareBracketsMustBeSpacedCorrectly.cs


示例13: CreatePragmaDirectiveTriviaAsync

        private async Task<SyntaxTriviaList> CreatePragmaDirectiveTriviaAsync(
            SyntaxToken disableOrRestoreKeyword, Diagnostic diagnostic, Func<SyntaxNode, Task<SyntaxNode>> formatNode, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine)
        {
            var id = SyntaxFactory.IdentifierName(diagnostic.Id);
            var ids = new SeparatedSyntaxList<ExpressionSyntax>().Add(id);
            var pragmaDirective = SyntaxFactory.PragmaWarningDirectiveTrivia(disableOrRestoreKeyword, ids, true);
            pragmaDirective = (PragmaWarningDirectiveTriviaSyntax)await formatNode(pragmaDirective).ConfigureAwait(false);
            var pragmaDirectiveTrivia = SyntaxFactory.Trivia(pragmaDirective);
            var endOfLineTrivia = SyntaxFactory.ElasticCarriageReturnLineFeed;
            var triviaList = SyntaxFactory.TriviaList(pragmaDirectiveTrivia);

            var title = diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture);
            if (!string.IsNullOrWhiteSpace(title))
            {
                var titleComment = SyntaxFactory.Comment(string.Format(" // {0}", title)).WithAdditionalAnnotations(Formatter.Annotation);
                triviaList = triviaList.Add(titleComment);
            }

            if (needsLeadingEndOfLine)
            {
                triviaList = triviaList.Insert(0, endOfLineTrivia);
            }

            if (needsTrailingEndOfLine)
            {
                triviaList = triviaList.Add(endOfLineTrivia);
            }

            return triviaList;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:30,代码来源:CSharpSuppressionCodeFixProvider.cs


示例14: FixOpenBraceNextToken

        /// <summary>
        /// Remove the extra new lines on the token which immediately follows an open brace.
        /// </summary>
        private static SyntaxToken FixOpenBraceNextToken(SyntaxToken token)
        {
            if (!token.HasLeadingTrivia)
            {
                return token;
            }

            if (token.Kind() == SyntaxKind.CloseBraceToken &&
                token.LeadingTrivia.All(x => x.IsKind(SyntaxKind.WhitespaceTrivia) || x.IsKind(SyntaxKind.EndOfLineTrivia)))
            {
                // This is an open / close brace combo with no content inbetween.  Just return the 
                // close brace and let the formatter handle the white space issues.  If there was a new line 
                // between the two it will be attached to the open brace and hence maintained. 
                return token.WithLeadingTrivia(SyntaxTriviaList.Empty);
            }

            // Remove all of the new lines at the top
            var triviaList = token.LeadingTrivia;
            var list = new List<SyntaxTrivia>(triviaList.Count);
            var index = MovePastSimpleNewLines(triviaList, 0);

            while (index < triviaList.Count)
            {
                list.Add(triviaList[index]);
                index++;
            }

            var newTriviaList = SyntaxFactory.TriviaList(list);
            return token.WithLeadingTrivia(newTriviaList);
        }
开发者ID:chuck-mitchell,项目名称:codeformatter,代码行数:33,代码来源:BraceNewLineRule.cs


示例15: GetPathThroughLastSlash

 private string GetPathThroughLastSlash(SyntaxToken stringLiteral, int position)
 {
     return PathCompletionUtilities.GetPathThroughLastSlash(
         quotedPath: stringLiteral.ToString(),
         quotedPathStart: stringLiteral.SpanStart,
         position: position);
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:ReferenceDirectiveCompletionProvider.cs


示例16: HandleOpenBracketToken

        private static void HandleOpenBracketToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
        {
            if (token.IsMissing)
            {
                return;
            }

            if (!token.Parent.IsKind(SyntaxKind.AttributeList))
            {
                return;
            }

            if (token.IsLastInLine())
            {
                return;
            }

            if (!token.HasTrailingTrivia)
            {
                return;
            }

            if (!token.TrailingTrivia[0].IsKind(SyntaxKind.WhitespaceTrivia))
            {
                return;
            }

            // Opening attribute brackets must not be followed by a space.
            context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingCodeFixProvider.RemoveFollowing));
        }
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:30,代码来源:SA1016OpeningAttributeBracketsMustBeSpacedCorrectly.cs


示例17: GetNewStartToken

            private static SyntaxToken GetNewStartToken(SyntaxToken startToken, Diagnostic diagnostic, AbstractSuppressionCodeFixProvider fixer)
            {
                var trivia = startToken.LeadingTrivia.ToImmutableArray();

                // Insert the #pragma disable directive after all leading new line trivia but before first trivia of any other kind.
                int index;
                SyntaxTrivia firstNonEOLTrivia = trivia.FirstOrDefault(t => !fixer.IsEndOfLine(t));
                if (firstNonEOLTrivia == default(SyntaxTrivia))
                {
                    index = trivia.Length;
                }
                else
                {
                    index = trivia.IndexOf(firstNonEOLTrivia);
                }

                bool needsLeadingEOL;
                if (index > 0)
                {
                    needsLeadingEOL = !fixer.IsEndOfLine(trivia[index - 1]);
                }
                else if (startToken.FullSpan.Start == 0)
                {
                    needsLeadingEOL = false;
                }
                else
                {
                    needsLeadingEOL = true;
                }

                var pragmaWarningTrivia = fixer.CreatePragmaDisableDirectiveTrivia(diagnostic, needsLeadingEOL);

                return startToken.WithLeadingTrivia(trivia.InsertRange(index, pragmaWarningTrivia));
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:34,代码来源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs


示例18: Trailing

            public static AnalysisResult Trailing(SyntaxToken token)
            {
                var result = default(AnalysisResult);
                Analyze(token.TrailingTrivia, ref result);

                return result;
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:7,代码来源:TriviaDataFactory.Analyzer.cs


示例19: IsWithinNaturalLanguage

        protected override bool IsWithinNaturalLanguage(SyntaxToken token, int position)
        {
            switch (token.Kind())
            {
                case SyntaxKind.StringLiteralToken:
                    // This, in combination with the override of GetExtentOfWordFromToken() below, treats the closing
                    // quote as a separate token.  This maintains behavior with VS2013.
                    if (position == token.Span.End - 1 && token.Text.EndsWith("\"", StringComparison.Ordinal))
                    {
                        return false;
                    }

                    return true;

                case SyntaxKind.CharacterLiteralToken:
                    // Before the ' is considered outside the character
                    return position != token.SpanStart;

                case SyntaxKind.InterpolatedStringTextToken:
                case SyntaxKind.XmlTextLiteralToken:
                    return true;
            }

            return false;
        }
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:25,代码来源:TextStructureNavigatorProvider.cs


示例20: IsInvalidToken

 protected override bool IsInvalidToken(SyntaxToken token)
 {
     // invalid token to be formatted
     return token.IsKind(SyntaxKind.None) ||
            token.IsKind(SyntaxKind.EndOfDirectiveToken) ||
            token.IsKind(SyntaxKind.EndOfFileToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:SmartTokenFormatterCommandHandler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SyntaxTokenList类代码示例发布时间:2022-05-24
下一篇:
C# SyntaxReference类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap