Exemple #1
0
        /// <summary>
        /// Rewrites the raise statement.
        /// </summary>
        /// <param name="node">ExpressionStatementSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(ExpressionStatementSyntax node)
        {
            var text = "{ " + node.ToString() + "return; }";
            var rewritten = SyntaxFactory.ParseStatement(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
        private async Task<Document> AssignMethodReturnToReceiverAsync(CodeFixContext context, Document document, ExpressionStatementSyntax statement, string receiverName, CancellationToken c)
        {
            var rValueExpr = statement.ToString();
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
            var memberAccess = root.FindNode(context.Span)?.FirstAncestorOrSelf<MemberAccessExpressionSyntax>();

            var declaration = SyntaxFactory
                .ParseStatement($"{receiverName} = {rValueExpr}");

            var formattedDeclaration = declaration.WithTriviaFrom(statement);
            // Replace the old statement with the block:
            var newRoot = root.ReplaceNode((SyntaxNode)statement, formattedDeclaration);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;

        }
Exemple #3
0
 public override void VisitExpressionStatement(ExpressionStatementSyntax node)
 {
     // TODO: Don't just emit the expression as-is. Need to process the nodes of the expression
     Emit(node.ToString());
 }
        private async Task<Document> AssignMethodReturnToNewVariable(Document document, ExpressionStatementSyntax statement, CancellationToken c)
        {
            var rValueExpr = statement.ToString();
            var semanticModel = await document.GetSemanticModelAsync();
            var newVariable = FindAvailableVariableName("returnValue",
                statement, semanticModel);

            var declaration = SyntaxFactory.ParseStatement($"var {newVariable} = {rValueExpr}");

            var formattedDeclaration = declaration.WithTriviaFrom(statement);
            // Replace the old statement with the block:
            var root = await document.GetSyntaxRootAsync();
            var newRoot = root.ReplaceNode((SyntaxNode)statement, formattedDeclaration);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;

        }
 public override void VisitExpressionStatement(ExpressionStatementSyntax node)
 {
     _2JS.AppendLine(node.ToString());
     base.VisitExpressionStatement(node);
 }