Example #1
0
        public static TNode RemoveComments <TNode>(TNode node, CommentKinds kinds) where TNode : SyntaxNode
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            return(RemoveComments(node, node.FullSpan, kinds));
        }
Example #2
0
        internal CommentRemover(SyntaxNode node, CommentKinds kinds, TextSpan span)
            : base(visitIntoStructuredTrivia: true)
        {
            Node = node;
            Span = span;

            ShouldRemoveSingleLineComment = (kinds & CommentKinds.SingleLine) != 0;
            ShouldRemoveMultiLineComment  = (kinds & CommentKinds.MultiLine) != 0;
            ShouldRemoveSingleLineDocumentationComment = (kinds & CommentKinds.SingleLineDocumentation) != 0;
            ShouldRemoveMultiLineDocumentationComment  = (kinds & CommentKinds.MultiLineDocumentation) != 0;
        }
Example #3
0
        public static TNode RemoveComments <TNode>(TNode node, TextSpan span, CommentKinds kinds) where TNode : SyntaxNode
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            var remover = new CommentRemover(node, kinds, span);

            return((TNode)remover.Visit(node));
        }
Example #4
0
        /// <summary>
        /// Creates a new document with comments of the specified kind removed.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="kinds"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task <Document> RemoveCommentsAsync(
            this Document document,
            CommentKinds kinds,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            SyntaxNode newRoot = SyntaxRemover.RemoveComments(root, kinds)
                                 .WithFormatterAnnotation();

            return(document.WithSyntaxRoot(newRoot));
        }
Example #5
0
 protected override bool IsRegularComment(SyntaxTrivia trivia)
 {
     return(CommentKinds.Contains(trivia.Kind()));
 }