Beispiel #1
0
            private static IEnumerable <SyntaxTrivia> ResolveTrivia(
                TriviaLocation location,
                PreviousNextTokenPair tokenPair,
                Dictionary <SyntaxToken, LeadingTrailingTriviaPair> triviaMap)
            {
                var previousTriviaPair = triviaMap.ContainsKey(tokenPair.PreviousToken) ? triviaMap[tokenPair.PreviousToken] : default;
                var nextTriviaPair     = triviaMap.ContainsKey(tokenPair.NextToken) ? triviaMap[tokenPair.NextToken] : default;

                var trailingTrivia = previousTriviaPair.TrailingTrivia ?? SpecializedCollections.EmptyEnumerable <SyntaxTrivia>();
                var leadingTrivia  = nextTriviaPair.LeadingTrivia ?? SpecializedCollections.EmptyEnumerable <SyntaxTrivia>();

                return(tokenPair.PreviousToken.TrailingTrivia.Concat(trailingTrivia).Concat(leadingTrivia).Concat(tokenPair.NextToken.LeadingTrivia));
            }
Beispiel #2
0
            private LeadingTrailingTriviaPair CreateTriviaPairs(
                TriviaLocation locationKind,
                PreviousNextTokenPair tokenPair,
                IEnumerable <SyntaxTrivia> trivia)
            {
                // beginning of the tree
                if (tokenPair.PreviousToken.RawKind == 0)
                {
                    return(new LeadingTrailingTriviaPair {
                        TrailingTrivia = SpecializedCollections.EmptyEnumerable <SyntaxTrivia>(), LeadingTrivia = trivia
                    });
                }

                return(GetTrailingAndLeadingTrivia(locationKind, tokenPair, trivia));
            }
Beispiel #3
0
            private LeadingTrailingTriviaPair GetTrailingAndLeadingTrivia(TriviaLocation locationKind, PreviousNextTokenPair tokenPair, IEnumerable <SyntaxTrivia> trivia)
            {
                var list = trivia.ToList();

                // there are some noisy trivia
                var index = GetFirstEndOfLineIndex(list);

                return(new LeadingTrailingTriviaPair
                {
                    TrailingTrivia = CreateTriviaListFromTo(list, 0, index),
                    LeadingTrivia = CreateTriviaListFromTo(list, index + 1, list.Count - 1)
                });
            }