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


C# SyntaxTriviaList类代码示例

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


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


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