예제 #1
0
        private static bool IsNestedFix(SyntaxNode node, SemanticModel semanticModel, ReduceIfNestingOptions options, INamedTypeSymbol taskSymbol, CancellationToken cancellationToken)
        {
            options |= ReduceIfNestingOptions.AllowNestedFix;

            while (node != null)
            {
                if (node is IfStatementSyntax ifStatement)
                {
                    ReduceIfNestingAnalysis analysis = Analyze(ifStatement, semanticModel, options, taskSymbol, cancellationToken);

                    if (analysis.Success)
                    {
                        return(true);
                    }

                    node = analysis.TopNode;
                }

                if (node is MemberDeclarationSyntax)
                {
                    return(false);
                }

                if (node is AccessorDeclarationSyntax)
                {
                    return(false);
                }

                node = node.Parent;
            }

            Debug.Fail("");

            return(false);
        }
예제 #2
0
            public override SyntaxNode VisitBlock(BlockSyntax node)
            {
                if (_statementsInfo.Parent == null &&
                    node.IsParentKind(SyntaxKind.SwitchSection))
                {
                    return(Rewrite(new StatementListInfo(node)));
                }

                _statementsInfo = new StatementListInfo(node);

                IfStatementSyntax ifStatement = FindFixableIfStatement(_statementsInfo.Statements, _jumpKind);

                if (ReduceIfNestingAnalysis.IsFixable(ifStatement))
                {
                    return(Rewrite(_statementsInfo, ifStatement));
                }

                return(node);
            }
예제 #3
0
            private static IfStatementSyntax FindFixableIfStatement(SyntaxList <StatementSyntax> statements, SyntaxKind jumpKind)
            {
                int i = statements.Count - 1;

                while (i >= 0 &&
                       statements[i].Kind() == SyntaxKind.LocalFunctionStatement)
                {
                    i--;
                }

                if (i == -1)
                {
                    return(null);
                }

                if (statements[i] is IfStatementSyntax ifStatement)
                {
                    return(ifStatement);
                }
                else if (ReduceIfNestingAnalysis.GetJumpKind(statements[i]) == jumpKind)
                {
                    i--;

                    while (i >= 0 &&
                           statements[i].Kind() == SyntaxKind.LocalFunctionStatement)
                    {
                        i--;
                    }

                    if (i == -1)
                    {
                        return(null);
                    }

                    if (statements[i] is IfStatementSyntax ifStatement2)
                    {
                        return(ifStatement2);
                    }
                }

                return(null);
            }