private static void TestDeterminedLastElseClause(IfStatementSyntax conditionalNode, bool expected) { Assert.IsNotNull(conditionalNode, "Found node should be of type `{0}`!", typeof(IfStatementSyntax).Name); ConditionalStatement conditionalStatement = new ConditionalStatement(conditionalNode); bool lastElsePresent = conditionalStatement.HasElseBlock; Assert.AreEqual(expected, lastElsePresent, "Expected last ELSE clause presence does not match!"); }
private static void TestRetrievedNumberOfBodies(IfStatementSyntax conditionalNode, int expected) { Assert.IsNotNull(conditionalNode, "Found node should be of type `{0}`!", typeof(IfStatementSyntax).Name); ConditionalStatement conditionalStatement = new ConditionalStatement(conditionalNode); int blocksNumber = conditionalStatement.BlocksNumber; Assert.AreEqual(expected, blocksNumber, "Number of retrieved blocks does not match!"); }
/// <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); }