private static bool IsFirstStatementIfStatement( IBlockFactsService blockFacts, IIfLikeStatementGenerator ifGenerator, SyntaxNode ifOrElseIf, out SyntaxNode ifStatement) { // Check whether the first statement inside an if or else if is an if statement. // If the if statement is inside a block, it has to be the first statement of the block. // An if or else if should always be a statement container, but we'll do a defensive check anyway. Debug.Assert(blockFacts.IsStatementContainer(ifOrElseIf)); if (blockFacts.IsStatementContainer(ifOrElseIf)) { var rootStatements = blockFacts.GetStatementContainerStatements(ifOrElseIf); var statements = WalkDownScopeBlocks(blockFacts, rootStatements); if (statements.Count > 0 && ifGenerator.IsIfOrElseIf(statements[0])) { ifStatement = statements[0]; return(true); } } ifStatement = null; return(false); }
private static bool IsFirstStatementOfIfOrElseIf( IBlockFactsService blockFacts, IIfLikeStatementGenerator ifGenerator, SyntaxNode statement, out SyntaxNode ifOrElseIf) { // Check whether the statement is a first statement inside an if or else if. // If it's inside a block, it has to be the first statement of the block. // We can't assume that a statement will always be in a statement container, because an if statement // in top level code will be in a GlobalStatement. if (blockFacts.IsStatementContainer(statement.Parent)) { var statements = blockFacts.GetStatementContainerStatements(statement.Parent); if (statements.Count > 0 && statements[0] == statement) { var rootStatements = WalkUpScopeBlocks(blockFacts, statements); if (rootStatements.Count > 0 && ifGenerator.IsIfOrElseIf(rootStatements[0].Parent)) { ifOrElseIf = rootStatements[0].Parent; return(true); } } } ifOrElseIf = null; return(false); }