本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例6: ClassifyExteriorTrivia
private void ClassifyExteriorTrivia(SyntaxTriviaList triviaList)
{
foreach (var t in triviaList)
{
if (t.CSharpKind() == SyntaxKind.DocumentationCommentExteriorTrivia)
{
AddClassification(t, ClassificationTypeNames.XmlDocCommentDelimiter);
}
}
}
示例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;
}
示例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;
}
示例9: GetBestNewLineTrivia
internal static SyntaxTrivia GetBestNewLineTrivia(SyntaxTriviaList list, SyntaxTrivia? defaultNewLineTrivia = null)
{
SyntaxTrivia trivia;
if (TryGetExistingNewLine(list, out trivia))
{
return trivia;
}
return defaultNewLineTrivia ?? SyntaxFactory.CarriageReturnLineFeed;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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