/// <summary> /// Factory method for class <see cref="ConditionalStatementASTWalker"/>. /// </summary> /// <param name="node"><see cref="CSharpSyntaxNode"/> Used to initialize the walker.</param> /// <param name="semanticModel">The semantic model.</param> /// <returns></returns> public static ConditionalStatementASTWalker Create(CSharpSyntaxNode node, SemanticModel semanticModel = null) { // TODO: Use TranslationUnitFactory in order to have AST walkers decoupled from helpers // via factories (which will be using helpers) ConditionalStatement helper = new ConditionalStatement(node as IfStatementSyntax); var statement = ConditionalStatementTranslationUnit.Create(helper.BlocksNumber, helper.HasElseBlock); return(new ConditionalStatementASTWalker(node, statement, semanticModel)); }
/// <summary> /// /// </summary> /// <param name="testExpression"></param> /// <param name="bodyStatements"></param> /// <param name="elseStatements"></param> /// <returns></returns> public static ITranslationUnit BuildIfStatementTranslationUnit(ITranslationUnit testExpression, IEnumerable <ITranslationUnit> bodyStatements, IEnumerable <ITranslationUnit> elseStatements = null) { var translationUnit = ConditionalStatementTranslationUnit.Create(1, elseStatements != null); translationUnit.SetTestExpression(testExpression, 0); foreach (var statement in bodyStatements) { translationUnit.SetStatementInConditionalBlock(statement, 0); } if (elseStatements != null) { foreach (var statement in elseStatements) { translationUnit.SetStatementInElseBlock(statement); } } return(translationUnit); }