コード例 #1
0
ファイル: RaiseRewriter.cs プロジェクト: yonglehou/PSharp
        /// <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;
        }
コード例 #2
0
ファイル: PureMethodsFixer.cs プロジェクト: Winsto/MVA-Roslyn
        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;

        }
コード例 #3
0
ファイル: Transpiler.cs プロジェクト: benlaan/cs2ts
 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());
 }
コード例 #4
0
ファイル: PureMethodsFixer.cs プロジェクト: Winsto/MVA-Roslyn
        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;

        }
コード例 #5
0
 public override void VisitExpressionStatement(ExpressionStatementSyntax node)
 {
     _2JS.AppendLine(node.ToString());
     base.VisitExpressionStatement(node);
 }