示例#1
0
    //STEP 1
    public override SyntaxNode VisitWhileStatement(WhileStatementSyntax node)
    {
        var nodeVisited = (WhileStatementSyntax)base.VisitWhileStatement(node);

        var condition = nodeVisited.Condition;

        if (condition.Kind() == SyntaxKind.IdentifierName)
        {
            return(nodeVisited);
        }

        string conditionVarIdentifier = ConditionIdentifier;
        var    newConditionVar        = SyntaxFactoryExtensions.GenerateLocalVariableDeclaration(conditionVarIdentifier,
                                                                                                 condition, SyntaxKind.BoolKeyword).NormalizeWhitespace().WithTriviaFrom(nodeVisited);
        var newCondition = SyntaxFactory.IdentifierName(conditionVarIdentifier).WithTriviaFrom(condition);

        markedNodes.Add(condition);
        markedNodes.Add(node);
        replacementNodes.Add(new Tuple <ExpressionSyntax, IdentifierNameSyntax, StatementSyntax, WhileStatementSyntax>(condition, newCondition, newConditionVar, node));
        return(nodeVisited);
    }