public static Task <Document> RefactorAsync(
            Document document,
            UsingStatementSyntax usingStatement,
            CancellationToken cancellationToken)
        {
            var rewriter = new SyntaxRewriter();

            var newNode = (UsingStatementSyntax)rewriter.Visit(usingStatement)
                          .WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(usingStatement, newNode, cancellationToken));
        }
        public static Task <Document> RefactorAsync(
            Document document,
            EnumDeclarationSyntax enumDeclaration,
            CancellationToken cancellationToken)
        {
            var rewriter = new SyntaxRewriter(enumDeclaration);

            SyntaxNode newNode = rewriter.Visit(enumDeclaration)
                                 .WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(enumDeclaration, newNode, cancellationToken));
        }
Ejemplo n.º 3
0
        public static async Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken);

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithAdditionalAnnotations(Formatter.Annotation);

            SyntaxNode newRoot = oldRoot.ReplaceNode(ifStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            UsingStatementSyntax usingStatement,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            UsingStatementSyntax newNode = SyntaxRewriter.VisitNode(usingStatement)
                                           .WithFormatterAnnotation();

            SyntaxNode newRoot = oldRoot.ReplaceNode(usingStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }
Ejemplo n.º 5
0
        public async Task <Document> VisitAsync(Document document, CancellationToken cancellationToken)
        {
            generator = SyntaxGenerator.GetGenerator(document);
            rewriter  = await SyntaxRewriter.CreateAsync(document);

            var syntax = await document.GetSyntaxRootAsync(cancellationToken);

            syntax = Visit(syntax);

            // Apply fixups
            syntax = new VisualBasicParameterFixup().Visit(syntax);

            return(document.WithSyntaxRoot(syntax));
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            ClassDeclarationSyntax classDeclaration,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var rewriter = new SyntaxRewriter(classDeclaration);

            SyntaxNode newNode = rewriter.Visit(classDeclaration);

            root = root.ReplaceNode(classDeclaration, newNode);

            return(document.WithSyntaxRoot(root));
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            ParenthesizedLambdaExpressionSyntax lambda,
            CancellationToken cancellationToken)
        {
            LambdaExpressionSyntax newLambda = SyntaxRewriter.VisitNode(lambda);

            if (lambda.ParameterList.Parameters.Count == 1)
            {
                newLambda = ConvertParenthesizedLambdaToSimpleLambda((ParenthesizedLambdaExpressionSyntax)newLambda);
            }

            newLambda = newLambda.WithFormatterAnnotation();

            return(await document.ReplaceNodeAsync(lambda, newLambda, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 8
0
        public static Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

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

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(ifStatement, newNode, cancellationToken));
        }
Ejemplo n.º 9
0
        private static async Task <Document> SimplifyLambdaExpressionParameterListAsync(
            Document document,
            ParenthesizedLambdaExpressionSyntax lambda,
            CancellationToken cancellationToken)
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            LambdaExpressionSyntax newLambda = SyntaxRewriter.VisitNode(lambda);

            if (lambda.ParameterList.Parameters.Count == 1)
            {
                newLambda = ConvertParenthesizedLambdaToSimpleLambda((ParenthesizedLambdaExpressionSyntax)newLambda);
            }

            newLambda = newLambda.WithFormatterAnnotation();

            root = root.ReplaceNode(lambda, newLambda);

            return(document.WithSyntaxRoot(root));
        }
Ejemplo n.º 10
0
        private static async Task <Document> RefactorAsync(
            Document document,
            StatementSyntax statement,
            ExpressionSyntax condition,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken);

            SyntaxTriviaList triviaList = SyntaxFactory.TriviaList(SyntaxHelper.NewLine)
                                          .AddRange(statement.GetIndentTrivia())
                                          .Add(SyntaxHelper.DefaultIndent);

            var rewriter = new SyntaxRewriter(triviaList);

            var newCondition = (ExpressionSyntax)rewriter.Visit(condition);

            StatementSyntax newStatement = SetCondition(statement, newCondition)
                                           .WithAdditionalAnnotations(Formatter.Annotation);

            return(document.WithSyntaxRoot(oldRoot.ReplaceNode(statement, newStatement)));
        }
Ejemplo n.º 11
0
        public static async Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

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

            var rewriter = new SyntaxRewriter();

            var newNode = (IfStatementSyntax)rewriter.Visit(ifStatement)
                          .WithFormatterAnnotation();

            return(await document.ReplaceNodeAsync(ifStatement, newNode, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 12
0
        public static async Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

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

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

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithFormatterAnnotation();

            SyntaxNode newRoot = oldRoot.ReplaceNode(ifStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }