Exemple #1
0
        internal static Task <Document> RemoveSingleLineDocumentationComment(
            this Document document,
            DocumentationCommentTriviaSyntax documentationComment,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SyntaxNode node    = documentationComment.ParentTrivia.Token.Parent;
            SyntaxNode newNode = SyntaxRemover.RemoveSingleLineDocumentationComment(node, documentationComment);

            return(document.ReplaceNodeAsync(node, newNode, cancellationToken));
        }
Exemple #2
0
        /// <summary>
        /// Creates a new document with trivia inside the specified span removed.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="span"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task <Document> RemoveTriviaAsync(
            this Document document,
            TextSpan span,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

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

            SyntaxNode newRoot = SyntaxRemover.RemoveTrivia(root, span);

            return(document.WithSyntaxRoot(newRoot));
        }
Exemple #3
0
        internal static Task <Document> RemoveNodeAsync(
            this Document document,
            SyntaxNode node,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            return(document.RemoveNodeAsync(node, SyntaxRemover.GetRemoveOptions(node), cancellationToken));
        }
Exemple #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));
        }
Exemple #5
0
        /// <summary>
        /// Create a new document with the specified member declaration removed.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="member"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        internal static Task <Document> RemoveMemberAsync(
            this Document document,
            MemberDeclarationSyntax member,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            SyntaxNode parent = member.Parent;

            switch (parent?.Kind())
            {
            case SyntaxKind.CompilationUnit:
            {
                var compilationUnit = (CompilationUnitSyntax)parent;

                return(document.ReplaceNodeAsync(compilationUnit, SyntaxRemover.RemoveMember(compilationUnit, member), cancellationToken));
            }

            case SyntaxKind.NamespaceDeclaration:
            {
                var namespaceDeclaration = (NamespaceDeclarationSyntax)parent;

                return(document.ReplaceNodeAsync(namespaceDeclaration, SyntaxRemover.RemoveMember(namespaceDeclaration, member), cancellationToken));
            }

            case SyntaxKind.ClassDeclaration:
            {
                var classDeclaration = (ClassDeclarationSyntax)parent;

                return(document.ReplaceNodeAsync(classDeclaration, SyntaxRemover.RemoveMember(classDeclaration, member), cancellationToken));
            }

            case SyntaxKind.StructDeclaration:
            {
                var structDeclaration = (StructDeclarationSyntax)parent;

                return(document.ReplaceNodeAsync(structDeclaration, SyntaxRemover.RemoveMember(structDeclaration, member), cancellationToken));
            }

            case SyntaxKind.InterfaceDeclaration:
            {
                var interfaceDeclaration = (InterfaceDeclarationSyntax)parent;

                return(document.ReplaceNodeAsync(interfaceDeclaration, SyntaxRemover.RemoveMember(interfaceDeclaration, member), cancellationToken));
            }

            default:
            {
                Debug.Assert(parent == null, parent.Kind().ToString());

                return(document.RemoveNodeAsync(member, SyntaxRemover.DefaultRemoveOptions, cancellationToken));
            }
            }
        }