Beispiel #1
0
 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));
 }
Beispiel #2
0
 private SyntaxTriviaList RemoveRegions(SyntaxTriviaList oldTriviaList)
 {
     return SyntaxFactory.TriviaList(oldTriviaList
         .Where(trivia => trivia.Kind() != SyntaxKind.RegionDirectiveTrivia &&
                          trivia.Kind() != SyntaxKind.EndRegionDirectiveTrivia));
 }
 public static SyntaxTrivia?GetLastCommentOrWhitespace(this SyntaxTriviaList triviaList)
 {
     return(triviaList
            .Where(t => t.MatchesKind(SyntaxKind.SingleLineCommentTrivia, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.WhitespaceTrivia))
            .LastOrNullable());
 }
 public static SyntaxTrivia?GetLastComment(this SyntaxTriviaList triviaList)
 {
     return(triviaList
            .Where(t => t.IsRegularComment())
            .LastOrNullable());
 }
 public static SyntaxTrivia?GetFirstNewLine(this SyntaxTriviaList triviaList)
 {
     return(triviaList
            .Where(t => t.Kind() == SyntaxKind.EndOfLineTrivia)
            .FirstOrNullable());
 }
 public static SyntaxTriviaList WithoutWhitespaceTrivia(this SyntaxTriviaList triviaList)
 {
     return(new SyntaxTriviaList().AddRange(triviaList.Where(t => !t.IsWhitespaceTrivia())));
 }
Beispiel #7
0
 /// <summary>
 /// return only skipped tokens
 /// </summary>
 private static IEnumerable <SyntaxToken> GetSkippedTokens(SyntaxTriviaList list)
 {
     return(list.Where(trivia => trivia.RawKind == (int)SyntaxKind.SkippedTokensTrivia)
            .SelectMany(t => ((SkippedTokensTriviaSyntax)t.GetStructure()).Tokens));
 }
Beispiel #8
0
 public static SyntaxTriviaList ExcludeDirectivies(this SyntaxTriviaList list)
 {
     return(SyntaxFactory.TriviaList(list.Where(t => !t.IsDirective)));
 }
 public static List <string> ToList(SyntaxTriviaList trivias) =>
 trivias.Where(Filter).Select(ExtractText).ToList();