Exemple #1
0
        public override SyntaxToken VisitToken(SyntaxToken currentToken)
        {
            var previousToken = currentToken.GetPreviousToken();

            currentToken = base.VisitToken(currentToken);

            currentToken = currentToken.WithLeadingTrivia(currentToken.LeadingTrivia.Where(t => t.ShouldBePreserved()));
            currentToken = currentToken.WithTrailingTrivia(currentToken.TrailingTrivia.Where(t => t.ShouldBePreserved()));

            if (currentToken.LeadingTrivia.Sum(t => t.FullSpan.Length) + previousToken.TrailingTrivia.Where(t => t.ShouldBePreserved()).Sum(t => t.FullSpan.Length) == 0)
            {
                if (TokenCollisionDetector.IsColliding(previousToken.Kind(), currentToken.Kind()))
                {
                    currentToken = currentToken.WithLeadingTrivia(SyntaxFactory.Whitespace(" "));
                }
            }

            return(currentToken);
        }
Exemple #2
0
        public override SyntaxToken VisitToken(SyntaxToken token)
        {
            token = base.VisitToken(token);

            var newTrivia = new List <SyntaxTrivia>();
            var trivia    = token.LeadingTrivia;

            TrimTrivia(trivia, newTrivia, false);
            var previousToken = token.GetPreviousToken();

            if ((previousToken != null) && TokenCollisionDetector.IsColliding(token.Kind(), previousToken.Kind()))
            {
                if (token.LeadingTrivia.Sum(t => t.FullSpan.Length) + previousToken.TrailingTrivia.Where(t => t.IsKind(SyntaxKind.WhitespaceTrivia)).Sum(t => t.FullSpan.Length) == 0)
                {
                    newTrivia.Add(SyntaxFactory.Whitespace(" "));
                }
            }
            token  = token.WithLeadingTrivia(newTrivia);
            trivia = token.TrailingTrivia;
            TrimTrivia(trivia, newTrivia, true);
            token = token.WithTrailingTrivia(newTrivia);

            return(token);
        }