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)); }
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) }; }
private LeadingTrailingTriviaPair CreateTriviaPairs( 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(trivia)); }
private IEnumerable<SyntaxTrivia> TriviaResolver( TriviaLocation location, PreviousNextTokenPair tokenPair, Dictionary<SyntaxToken, LeadingTrailingTriviaPair> triviaMap, MethodDeclarationSyntax method) { // Resolve trivia at the edge of the selection. simple case is easy to deal with, but complex cases where // elastic trivia and user trivia are mixed (hybrid case) and we want to preserve some part of user coding style // but not others can be dealt with here. // method has no statement in them. so basically two trivia list now pointing to same thing. "{" and "}" if (tokenPair.PreviousToken == method.Body.OpenBraceToken && tokenPair.NextToken == method.Body.CloseBraceToken) { return (location == TriviaLocation.AfterBeginningOfSpan) ? SpecializedCollections.SingletonEnumerable<SyntaxTrivia>(SyntaxFactory.ElasticMarker) : SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(); } var previousTriviaPair = triviaMap.ContainsKey(tokenPair.PreviousToken) ? triviaMap[tokenPair.PreviousToken] : default(LeadingTrailingTriviaPair); var nextTriviaPair = triviaMap.ContainsKey(tokenPair.NextToken) ? triviaMap[tokenPair.NextToken] : default(LeadingTrailingTriviaPair); var trailingTrivia = previousTriviaPair.TrailingTrivia ?? SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(); var leadingTrivia = nextTriviaPair.LeadingTrivia ?? SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(); var list = trailingTrivia.Concat(leadingTrivia); switch (location) { case TriviaLocation.BeforeBeginningOfSpan: return FilterBeforeBeginningOfSpan(tokenPair, list); case TriviaLocation.AfterEndOfSpan: return FilterTriviaList(list.Concat(tokenPair.NextToken.LeadingTrivia)); case TriviaLocation.AfterBeginningOfSpan: return FilterTriviaList(AppendTrailingTrivia(tokenPair).Concat(list).Concat(tokenPair.NextToken.LeadingTrivia)); case TriviaLocation.BeforeEndOfSpan: return FilterTriviaList(tokenPair.PreviousToken.TrailingTrivia.Concat(list).Concat(tokenPair.NextToken.LeadingTrivia)); } return Contract.FailWithReturn<IEnumerable<SyntaxTrivia>>("Shouldn't reach here"); }
private static IEnumerable<SyntaxTrivia> ResolveTrivia( TriviaLocation location, PreviousNextTokenPair tokenPair, Dictionary<SyntaxToken, LeadingTrailingTriviaPair> triviaMap) { var previousTriviaPair = triviaMap.ContainsKey(tokenPair.PreviousToken) ? triviaMap[tokenPair.PreviousToken] : default(LeadingTrailingTriviaPair); var nextTriviaPair = triviaMap.ContainsKey(tokenPair.NextToken) ? triviaMap[tokenPair.NextToken] : default(LeadingTrailingTriviaPair); 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); }
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); }
private IEnumerable<SyntaxTrivia> AppendTrailingTrivia(PreviousNextTokenPair tokenPair) { if (tokenPair.PreviousToken.RawKind == (int)SyntaxKind.OpenBraceToken || tokenPair.PreviousToken.RawKind == (int)SyntaxKind.SemicolonToken) { return tokenPair.PreviousToken.TrailingTrivia; } return SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(); }
private IEnumerable<SyntaxTrivia> FilterBeforeBeginningOfSpan(PreviousNextTokenPair tokenPair, IEnumerable<SyntaxTrivia> list) { var allList = FilterTriviaList(tokenPair.PreviousToken.TrailingTrivia.Concat(list).Concat(AppendLeadingTrivia(tokenPair))); if (tokenPair.PreviousToken.RawKind == (int)SyntaxKind.OpenBraceToken) { return RemoveBlankLines(allList); } return allList; }
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) }); }