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

C# SyntaxTriviaList类代码示例

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

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



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

示例1: RemoveBlankLines

        private static List<SyntaxTrivia> RemoveBlankLines(SyntaxTriviaList trivia, ref bool changed)
        {
            var newTrivia = new List<SyntaxTrivia>();

            for (int i = 0; i < trivia.Count;)
            {
                var trivia1 = trivia[i];
                newTrivia.Add(trivia1);

                if (i < trivia.Count - 1)
                {
                    var trivia2 = trivia[i + 1];

                    if (trivia1.Kind == SyntaxKind.EndOfLineTrivia &&
                        trivia2.Kind == SyntaxKind.EndOfLineTrivia)
                    {
                        changed = true;
                        i += 2;
                        continue;
                    }
                }

                i++;
            }

            return newTrivia;
        }
开发者ID:mindraptor,项目名称:MetaProgramming,代码行数:27,代码来源:NewLineCleanup.cs


示例2: FixCommentWhitespace

            private SyntaxTriviaList FixCommentWhitespace(SyntaxTriviaList textLines)
            {
                var changedLines = new SyntaxTriviaList();
                bool skipNextNewline = false;

                foreach (var text in textLines)
                {
                    if (skipNextNewline)
                    {
                        skipNextNewline = false;

                        if (text.Kind() == SyntaxKind.EndOfLineTrivia)
                        {
                            continue;
                        }
                    }

                    var removeTrivia = this.HasEmptyComment(text);

                    if (!removeTrivia)
                    {
                        changedLines = changedLines.Add(text);
                    }
                    else
                    {
                        skipNextNewline = true;
                    }
                }

                return changedLines;
            }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:31,代码来源:SA1120_CommentMustNotBeEmpty.cs


示例3: RemoveBlankLineTrivia

        private static List<SyntaxTrivia> RemoveBlankLineTrivia(SyntaxTriviaList trivia, ref bool changed)
        {
            var newTrivia = new List<SyntaxTrivia>();

            for (int i = 0; i < trivia.Count;)
            {
                var trivia1 = trivia[i];
                newTrivia.Add(trivia1);

                if (i < trivia.Count - 2)
                {
                    var trivia2 = trivia[i + 1];
                    var trivia3 = trivia[i + 2];

                    if (trivia1.Kind == SyntaxKind.EndOfLineTrivia &&
                        trivia2.Kind == SyntaxKind.WhitespaceTrivia &&
                        trivia3.Kind == SyntaxKind.EndOfLineTrivia)
                    {
                        // Skip the whitespace with a newline.
                        newTrivia.Add(trivia3);
                        changed = true;
                        i += 3;
                        continue;
                    }
                }

                i++;
            }

            return newTrivia;
        }
开发者ID:mindraptor,项目名称:MetaProgramming,代码行数:31,代码来源:WhiteSpaceCleanup.cs


示例4: IndexOfFirstNonWhitespaceTrivia

        /// <summary>
        /// Returns the index of the first non-whitespace trivia in the given trivia list.
        /// </summary>
        /// <param name="triviaList">The trivia list to process.</param>
        /// <param name="endOfLineIsWhitespace"><see langword="true"/> to treat <see cref="SyntaxKind.EndOfLineTrivia"/>
        /// as whitespace; otherwise, <see langword="false"/>.</param>
        /// <returns>The index where the non-whitespace starts, or -1 if there is no non-whitespace trivia.</returns>
        internal static int IndexOfFirstNonWhitespaceTrivia(SyntaxTriviaList triviaList, bool endOfLineIsWhitespace)
        {
            for (var index = 0; index < triviaList.Count; index++)
            {
                var currentTrivia = triviaList[index];
                switch (currentTrivia.Kind())
                {
                case SyntaxKind.EndOfLineTrivia:
                    if (!endOfLineIsWhitespace)
                    {
                        return index;
                    }

                    break;

                case SyntaxKind.WhitespaceTrivia:
                    break;

                default:
                    // encountered non-whitespace trivia -> the search is done.
                    return index;
                }
            }

            return -1;
        }
开发者ID:tmaczynski,项目名称:AsyncUsageAnalyzers,代码行数:33,代码来源:TriviaHelper.cs


示例5: GetImportsFromTrivia

 static string GetImportsFromTrivia(SyntaxTriviaList triviaList)
 {
     return triviaList
                 .Where(trivia => trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) || trivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
                 .Select(trivia => trivia.ToString().TrimStart('/', '*').Trim())
                 .Where(comment => comment.StartsWith("import"))
                 .Aggregate("", (current, comment) => current + (comment + ConvertToSwift.NewLine));
 }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:8,代码来源:Program.cs


示例6: ClassifyExteriorTrivia

 private void ClassifyExteriorTrivia(SyntaxTriviaList triviaList)
 {
     foreach (var t in triviaList)
     {
         if (t.CSharpKind() == SyntaxKind.DocumentationCommentExteriorTrivia)
         {
             AddClassification(t, ClassificationTypeNames.XmlDocCommentDelimiter);
         }
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:10,代码来源:Worker_DocumentationComments.cs


示例7: Add

        public void Add(SyntaxTriviaList list, int offset, int length)
        {
            if (nodes == null || count + length > nodes.Length)
            {
                this.Grow(count + length);
            }

            list.CopyTo(offset, nodes, count, length);
            count += length;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:10,代码来源:SyntaxTriviaListBuilder.cs


示例8: Add

        public void Add(SyntaxTriviaList list, int offset, int length)
        {
            if (_nodes == null || _count + length > _nodes.Length)
            {
                this.Grow(_count + length);
            }

            list.CopyTo(offset, _nodes, _count, length);
            _count += length;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:10,代码来源:SyntaxTriviaListBuilder.cs


示例9: GetBestNewLineTrivia

        internal static SyntaxTrivia GetBestNewLineTrivia(SyntaxTriviaList list, SyntaxTrivia? defaultNewLineTrivia = null)
        {
            SyntaxTrivia trivia;
            if (TryGetExistingNewLine(list, out trivia))
            {
                return trivia;
            }

            return defaultNewLineTrivia ?? SyntaxFactory.CarriageReturnLineFeed;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:10,代码来源:SyntaxUtil.cs


示例10: GetTransformedDocumentAsync

        private static Task<Document> GetTransformedDocumentAsync(CodeFixContext context, SyntaxNode syntaxRoot, SyntaxNode node, SyntaxTriviaList leadingTrivia)
        {
            var newTriviaList = leadingTrivia;
            newTriviaList = newTriviaList.Insert(0, SyntaxFactory.CarriageReturnLineFeed);

            var newNode = node.WithLeadingTrivia(newTriviaList);
            var newSyntaxRoot = syntaxRoot.ReplaceNode(node, newNode);
            var newDocument = context.Document.WithSyntaxRoot(newSyntaxRoot);

            return Task.FromResult(newDocument);
        }
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:11,代码来源:SA1516CodeFixProvider.cs


示例11: VisitList

        public override SyntaxTriviaList VisitList(SyntaxTriviaList list)
        {
            list = base.VisitList(list);

            var lineBreaksAtBeginning = list.TakeWhile(t => t.IsKind(SyntaxKind.EndOfLineTrivia)).Count();
            if (lineBreaksAtBeginning > 1)
            {
                list = SyntaxFactory.TriviaList(list.Skip(lineBreaksAtBeginning - 1));
            }

            return list;
        }
开发者ID:transformersprimeabcxyz,项目名称:CodeCleanupTools,代码行数:12,代码来源:RemoveConsecutiveEmptyLines.cs


示例12: FixCommentWhitespace

            private SyntaxTriviaList FixCommentWhitespace(SyntaxTriviaList textLines)
            {
                var changedLines = new SyntaxTriviaList();

                foreach (var text in textLines)
                {
                    var fixedText = this.FixCommentWhitespaceForLine(text);
                    changedLines = changedLines.Add(fixedText);
                }

                return changedLines;
            }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:12,代码来源:SA1005_CommentMustStartWithSpace.cs


示例13: TryGetExistingNewLine

        private static bool TryGetExistingNewLine(SyntaxTriviaList list, out SyntaxTrivia newLineTrivia)
        {
            foreach (var trivia in list)
            {
                if (trivia.IsKind(SyntaxKind.EndOfLineTrivia))
                {
                    newLineTrivia = trivia;
                    return true;
                }
            }

            newLineTrivia = default(SyntaxTrivia);
            return false;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:14,代码来源:SyntaxUtil.cs


示例14: FixTriviaList

        private static SyntaxTriviaList FixTriviaList(SyntaxTriviaList triviaList, IEnumerable<SyntaxTrivia> commentTrivias)
        {
            foreach (var singleLineComment in commentTrivias)
            {
                int commentLocation = triviaList.IndexOf(singleLineComment);
                if (commentLocation == -1)
                {
                    continue;
                }

                int index = commentLocation + 1;

                index++;
                while (index < triviaList.Count && index > 0)
                {
                    switch (triviaList[index].Kind())
                    {
                    case SyntaxKind.EndOfLineTrivia:
                    case SyntaxKind.WhitespaceTrivia:
                        index++;
                        break;

                    default:

                        if (triviaList[index - 1].IsKind(SyntaxKind.WhitespaceTrivia))
                        {
                            index--;
                        }

                        triviaList = SyntaxTriviaList.Empty.AddRange(triviaList.Take(commentLocation + 2).Concat(triviaList.Skip(index)));

                        // We found the trivia so we don't have to loop any longer
                        index = -1;
                        break;
                    }
                }

                if (index == triviaList.Count)
                {
                    if (triviaList[index - 1].IsKind(SyntaxKind.WhitespaceTrivia))
                    {
                        index--;
                    }

                    triviaList = SyntaxTriviaList.Empty.AddRange(triviaList.Take(commentLocation + 2).Concat(triviaList.Skip(index)));
                }
            }

            return triviaList;
        }
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:50,代码来源:SA1512CodeFixProvider.cs


示例15: Filter

        private static IEnumerable<SyntaxTrivia> Filter(SyntaxTriviaList triviaList, SyntaxTrivia start, SyntaxTrivia end)
        {
            var inHeader = false;

            foreach (var trivia in triviaList)
            {
                if (trivia == start)
                    inHeader = true;
                else if (trivia == end)
                    inHeader = false;
                else if (!inHeader)
                    yield return trivia;
            }
        }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:14,代码来源:HasNoCustomCopyrightHeaderFormattingRule.cs


示例16: GetExistingHeader

            private List<string> GetExistingHeader(SyntaxTriviaList triviaList)
            {
                var i = 0;
                MovePastBlankLines(triviaList, ref i);

                var headerList = new List<string>();
                while (i < triviaList.Count && IsLineComment(triviaList[i]))
                {
                    headerList.Add(GetCommentText(triviaList[i].ToFullString()));
                    i++;
                    MoveToNextLineOrTrivia(triviaList, ref i);
                }

                return headerList;
            }
开发者ID:michaelcfanning,项目名称:codeformatter,代码行数:15,代码来源:CopyrightHeaderRule.cs


示例17: GetOutliningSpans

        private void GetOutliningSpans(SyntaxTriviaList triviaList)
        {
            foreach (var trivia in triviaList)
            {
                _cancellationToken.ThrowIfCancellationRequested();
                if (_triviaProviderMap.TryGetValue(trivia.RawKind, out var providers))
                {
                    foreach (var provider in providers)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();

                        provider.CollectBlockSpans(_document, trivia, _spans, _cancellationToken);
                    }
                }
            }
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:16,代码来源:BlockSpanCollector.cs


示例18: CheckForAssignmentOfLiteral

 internal static bool CheckForAssignmentOfLiteral(StatementSyntax statement, SyntaxKind literalExpressionType, out ExpressionSyntax assignmentTarget, out SyntaxTriviaList assignmentTrailingTriviaList)
 {
     assignmentTarget = null;
     assignmentTrailingTriviaList = SyntaxFactory.TriviaList(SyntaxFactory.SyntaxTrivia(SyntaxKind.DisabledTextTrivia, ""));
     var expressionStatement = statement as ExpressionStatementSyntax;
     if (expressionStatement == null)
         return false;
     var assignmentExpression = expressionStatement.Expression as AssignmentExpressionSyntax;
     if ((assignmentExpression == null) || !assignmentExpression.IsKind(SyntaxKind.SimpleAssignmentExpression))
         return false;
     assignmentTarget = assignmentExpression.Left as IdentifierNameSyntax;
     assignmentTrailingTriviaList = assignmentExpression.OperatorToken.TrailingTrivia;
     if (assignmentTarget == null)
         assignmentTarget = assignmentExpression.Left as MemberAccessExpressionSyntax;
     var rightAssignment = assignmentExpression.Right as LiteralExpressionSyntax;
     return (assignmentTarget != null) && (rightAssignment != null) && (rightAssignment.IsKind(literalExpressionType));
 }
开发者ID:yeaicc,项目名称:RefactoringEssentials,代码行数:17,代码来源:ConvertIfToOrExpressionAnalyzer.cs


示例19: ToIdentifierToken

 public static SyntaxToken ToIdentifierToken(this string identifier, bool isQueryContext = false)
 {
     string text = identifier.EscapeIdentifier(isQueryContext);
     if ((text.Length == 0) || (text[0] != '@'))
     {
         return SyntaxFactory.Identifier(text);
     }
     string valueText = identifier.StartsWith("@") ? identifier.Substring(1) : identifier;
     SyntaxTriviaList leading = new SyntaxTriviaList();
     SyntaxToken token = SyntaxFactory.Identifier(leading, SyntaxKind.None, '@' + valueText, valueText, new SyntaxTriviaList());
     if (!identifier.StartsWith("@"))
     {
         SyntaxAnnotation[] annotations = new SyntaxAnnotation[] { Simplifier.Annotation };
         token = token.WithAdditionalAnnotations(annotations);
     }
     return token;
 }
开发者ID:herskinduk,项目名称:AutoWrapping,代码行数:17,代码来源:RoslynStringExtensions.cs


示例20: GetOutliningSpans

        private void GetOutliningSpans(SyntaxTriviaList triviaList)
        {
            foreach (var trivia in triviaList)
            {
                _cancellationToken.ThrowIfCancellationRequested();

                ImmutableArray<AbstractSyntaxTriviaOutliner> outliners;
                if (_triviaOutlinerMap.TryGetValue(trivia.RawKind, out outliners))
                {
                    foreach (var outliner in outliners)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();

                        outliner.CollectOutliningSpans(_document.Document, trivia, _regions, _cancellationToken);
                    }
                }
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:18,代码来源:RegionCollector.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# SyntaxWriter类代码示例发布时间:2022-05-24
下一篇:
C# SyntaxTrivia类代码示例发布时间: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