Exemplo n.º 1
0
        private static bool CheckTriviaLocateTogether(CompilationUnitSyntax root, SyntaxTrivia first, SyntaxTrivia second)
        {
            var trivia = root.FindTrivia(first.Span.End + 1);

            while (trivia.Span.End < second.Span.Start)
            {
                if (!(trivia.IsKind(SyntaxKind.WhitespaceTrivia) ||
                      trivia.IsKind(SyntaxKind.EndOfLineTrivia)))
                {
                    return(false);
                }
                trivia = root.FindTrivia(trivia.Span.End + 1);
            }
            return(true);
        }
        public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
        {
            switch (trivia.Kind())
            {
            case SyntaxKind.SingleLineCommentTrivia:
            case SyntaxKind.MultiLineCommentTrivia:
            {
                return(SyntaxHelper.EmptyTrivia);
            }

            case SyntaxKind.SingleLineDocumentationCommentTrivia:
            case SyntaxKind.MultiLineDocumentationCommentTrivia:
            {
                if (!_keepXmlComment)
                {
                    return(SyntaxHelper.EmptyTrivia);
                }

                break;
            }

            case SyntaxKind.EndOfLineTrivia:
            {
                if (trivia.SpanStart > 0)
                {
                    SyntaxTrivia trivia2 = _compilationUnit.FindTrivia(trivia.SpanStart - 1);

                    if (trivia2.IsKind(SyntaxKind.SingleLineCommentTrivia))
                    {
                        return(SyntaxHelper.EmptyTrivia);
                    }
                }

                break;
            }
            }

            return(base.VisitTrivia(trivia));
        }