Example #1
0
        private static SyntaxTrivia GetDocumentationCommentTrivia(ISymbol symbol, SemanticModel semanticModel, int position, CancellationToken cancellationToken = default(CancellationToken))
        {
            string xmlString = symbol.GetDocumentationCommentXml(cancellationToken: cancellationToken);

            if (!string.IsNullOrEmpty(xmlString))
            {
                string innerXml = GetInnerXml(xmlString);

                if (innerXml != null)
                {
                    string text = AddSlashes(innerXml.TrimEnd());

                    SyntaxTriviaList triviaList = SyntaxFactory.ParseLeadingTrivia(text);

                    if (triviaList.Count == 1)
                    {
                        SyntaxTrivia trivia = triviaList.First();

                        if (trivia.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) &&
                            trivia.HasStructure)
                        {
                            SyntaxNode structure = trivia.GetStructure();

                            if (structure.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia))
                            {
                                var commentTrivia = (DocumentationCommentTriviaSyntax)structure;

                                var rewriter = new DocumentationCommentTriviaRewriter(position, semanticModel);

                                // Remove T: from cref attribute and replace `1 with {T}
                                commentTrivia = (DocumentationCommentTriviaSyntax)rewriter.Visit(commentTrivia);

                                // Remove <filterpriority> element
                                commentTrivia = RemoveFilterPriorityElement(commentTrivia);

                                string commentTriviaText = commentTrivia.ToFullString();

                                commentTriviaText = Regex.Replace(commentTriviaText, @"^///\s*(\r?\n|$)", "", RegexOptions.Multiline);

                                triviaList = SyntaxFactory.ParseLeadingTrivia(commentTriviaText);

                                if (triviaList.Count == 1)
                                {
                                    return(triviaList.First());
                                }
                            }
                        }
                    }
                }

                Debug.Assert(false, xmlString);
            }

            return(default(SyntaxTrivia));
        }
Example #2
0
        public static SyntaxTrivia Parse(string xml, SemanticModel semanticModel, int position)
        {
            string triviaText = AddSlashes(xml.TrimEnd());

            SyntaxTrivia trivia = ParseLeadingTrivia(triviaText).Single();

            var commentTrivia = (DocumentationCommentTriviaSyntax)trivia.GetStructure();

            var rewriter = new DocumentationCommentTriviaRewriter(position, semanticModel);

            // Remove T: from cref attribute and replace `1 with {T}
            commentTrivia = (DocumentationCommentTriviaSyntax)rewriter.VisitDocumentationCommentTrivia(commentTrivia);

            // Remove <filterpriority> element
            commentTrivia = RemoveFilterPriorityElement(commentTrivia);

            string text = commentTrivia.ToFullString();

            // Remove /// from empty lines
            text = _commentedEmptyLineRegex.Replace(text, "");

            return(ParseLeadingTrivia(text).Single());
        }
Example #3
0
        private static SyntaxTrivia GetDocumentationCommentTrivia(ISymbol symbol, SemanticModel semanticModel, int position, CancellationToken cancellationToken = default(CancellationToken))
        {
            string xml = symbol.GetDocumentationCommentXml(cancellationToken: cancellationToken);

            if (string.IsNullOrEmpty(xml))
            {
                return(default(SyntaxTrivia));
            }

            string innerXml = GetInnerXml(xml);

            Debug.Assert(innerXml != null, xml);

            if (innerXml == null)
            {
                return(default(SyntaxTrivia));
            }

            string innerXmlWithSlashes = AddSlashes(innerXml.TrimEnd());

            SyntaxTriviaList leadingTrivia = ParseLeadingTrivia(innerXmlWithSlashes);

            if (leadingTrivia.Count != 1)
            {
                return(default(SyntaxTrivia));
            }

            SyntaxTrivia trivia = leadingTrivia.First();

            if (trivia.Kind() != SyntaxKind.SingleLineDocumentationCommentTrivia)
            {
                return(default(SyntaxTrivia));
            }

            if (!trivia.HasStructure)
            {
                return(default(SyntaxTrivia));
            }

            SyntaxNode structure = trivia.GetStructure();

            if (structure.Kind() != SyntaxKind.SingleLineDocumentationCommentTrivia)
            {
                return(default(SyntaxTrivia));
            }

            var commentTrivia = (DocumentationCommentTriviaSyntax)structure;

            var rewriter = new DocumentationCommentTriviaRewriter(position, semanticModel);

            // Remove T: from cref attribute and replace `1 with {T}
            commentTrivia = (DocumentationCommentTriviaSyntax)rewriter.VisitDocumentationCommentTrivia(commentTrivia);

            // Remove <filterpriority> element
            commentTrivia = RemoveFilterPriorityElement(commentTrivia);

            string text = commentTrivia.ToFullString();

            // Remove /// from empty lines
            text = _commentedEmptyLineRegex.Replace(text, "");

            leadingTrivia = ParseLeadingTrivia(text);

            if (leadingTrivia.Count == 1)
            {
                return(leadingTrivia.First());
            }

            return(default(SyntaxTrivia));
        }