/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="ConditionalStatementASTWalker"/> class. /// </summary> /// <param name="node"></param> /// <param name="conditionalStatement"></param> /// <param name="semanticModel">The semantic model.</param> protected ConditionalStatementASTWalker(CSharpSyntaxNode node, ConditionalStatementTranslationUnit conditionalStatement, SemanticModel semanticModel) : base(node, semanticModel) { var statementSyntaxNode = node as IfStatementSyntax; if (statementSyntaxNode == null) { throw new ArgumentException( string.Format("Specified node is not of type {0}", typeof(IfStatementSyntax).Name)); } if (conditionalStatement == null) { throw new ArgumentNullException(nameof(conditionalStatement)); } // Node assigned in base, no need to assign it here this.statement = conditionalStatement; // Going through parts in the statement and filling the translation unit with initial data this.VisitNode(statementSyntaxNode, 0); }
public static MockedConditionalStatementTranslationUnit Create(ConditionalStatementTranslationUnit statementTranslationUnit) { return(new MockedConditionalStatementTranslationUnit(statementTranslationUnit)); }
protected MockedConditionalStatementTranslationUnit(ConditionalStatementTranslationUnit original) : base(original) { }