Exemplo n.º 1
0
        static void CollectSwitchSectionStatements(AstNodeCollection <Statement> result, RefactoringContext context,
                                                   Statement statement)
        {
            BlockStatement blockStatement;

            if (statement is BlockStatement)
            {
                blockStatement = (BlockStatement)statement.Clone();
            }
            else
            {
                blockStatement = new BlockStatement {
                    statement.Clone()
                }
            };

            var breackStatement = new BreakStatement();

            blockStatement.Add(breackStatement);
            // check if break is needed
            var reachabilityAnalysis = context.CreateReachabilityAnalysis(blockStatement);

            if (!reachabilityAnalysis.IsReachable(breackStatement))
            {
                blockStatement.Statements.Remove(breackStatement);
            }

            var statements = blockStatement.Statements.ToArray();

            blockStatement.Statements.Clear();
            result.AddRange(statements);
        }
    }
Exemplo n.º 2
0
        static void SortNodeCollection <T> (AstNodeCollection <T> collection) where T : AstNode
        {
            var sortedMembers = collection
                                .OrderBy(GetNodeSortGroup)
                                .ThenBy(GetNodeSortName)
                                .ThenBy(GetNodeSortSignature)
                                .ToList();

            collection.Clear();
            collection.AddRange(sortedMembers);
        }
Exemplo n.º 3
0
        static void CollectSwitchSectionStatements(AstNodeCollection <Statement> result, BaseRefactoringContext context,
                                                   Statement statement)
        {
            BlockStatement blockStatement = statement as BlockStatement;

            if (blockStatement != null)
            {
                result.AddRange(blockStatement.Statements.Select(s => s.Clone()));
            }
            else
            {
                result.Add(statement.Clone());
            }

            // add 'break;' at end if necessary
            var reachabilityAnalysis = context.CreateReachabilityAnalysis(statement);

            if (reachabilityAnalysis.IsEndpointReachable(statement))
            {
                result.Add(new BreakStatement());
            }
        }