blob: b3c0723bcbb90980835d3b4b5ab0e3013e10d94a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis;
namespace ICSharpCode.NRefactory6.CSharp
{
internal static class SyntaxTriviaListExtensions
{
public static bool Any(this SyntaxTriviaList triviaList, params SyntaxKind[] kinds)
{
foreach (var trivia in triviaList)
{
if (trivia.MatchesKind(kinds))
{
return true;
}
}
return false;
}
public static SyntaxTrivia? GetFirstNewLine(this SyntaxTriviaList triviaList)
{
return triviaList
.Where(t => t.Kind() == SyntaxKind.EndOfLineTrivia)
.FirstOrNullable();
}
public static SyntaxTrivia? GetLastComment(this SyntaxTriviaList triviaList)
{
return triviaList
.Where(t => t.MatchesKind(SyntaxKind.SingleLineCommentTrivia, SyntaxKind.MultiLineCommentTrivia))
.LastOrNullable();
}
public static IEnumerable<SyntaxTrivia> SkipInitialWhitespace(this SyntaxTriviaList triviaList)
{
return triviaList.SkipWhile(t => t.Kind() == SyntaxKind.WhitespaceTrivia);
}
}
}
|