public static async Task ComputeRefactoringAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (!ifStatement.IsTopmostIf())
            {
                return;
            }

            SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

            foreach (IfStatementOrElseClause ifOrElse in ifStatement.GetChain())
            {
                if (ifOrElse.IsIf)
                {
                    if (!IsFixable(ifOrElse.AsIf(), semanticModel, context.CancellationToken))
                    {
                        return;
                    }
                }
                else if (ContainsBreakStatementThatBelongsToParentLoop(ifOrElse.AsElse().Statement))
                {
                    return;
                }
            }

            string title = (ifStatement.IsSimpleIf())
                ? "Replace if with switch"
                : "Replace if-else with switch";

            context.RegisterRefactoring(
                title,
                cancellationToken => RefactorAsync(context.Document, ifStatement, cancellationToken));
        }
Ejemplo n.º 2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (ifStatement.IsTopmostIf() &&
                (context.Span.IsEmptyAndContainedInSpan(ifStatement.IfKeyword) || context.Span.IsBetweenSpans(ifStatement)))
            {
                if (context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf,
                        RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf,
                        RefactoringIdentifiers.SimplifyIf))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    var options = new IfAnalysisOptions(
                        useCoalesceExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf),
                        useConditionalExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf),
                        useBooleanExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.SimplifyIf));

                    foreach (IfRefactoring refactoring in IfRefactoring.Analyze(ifStatement, options, semanticModel, context.CancellationToken))
                    {
                        context.RegisterRefactoring(
                            refactoring.Title,
                            cancellationToken => refactoring.RefactorAsync(context.Document, cancellationToken));
                    }
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SwapStatementsInIfElse))
                {
                    SwapStatementInIfElseRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceIfElseWithSwitch))
                {
                    await ReplaceIfElseWithSwitchRefactoring.ComputeRefactoringAsync(context, ifStatement).ConfigureAwait(false);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfStatement))
                {
                    SplitIfStatementRefactoring.ComputeRefactoring(context, ifStatement);
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReduceIfNesting) &&
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(ifStatement.IfKeyword))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                if (ReduceIfNestingRefactoring.IsFixable(
                        ifStatement,
                        semanticModel,
                        semanticModel.GetTypeByMetadataName(MetadataNames.System_Threading_Tasks_Task),
                        context.CancellationToken,
                        topLevelOnly: false))
                {
                    context.RegisterRefactoring(
                        "Reduce if nesting",
                        cancellationToken => ReduceIfNestingRefactoring.RefactorAsync(context.Document, ifStatement, context.CancellationToken));
                }
            }
        }
Ejemplo n.º 3
0
        public static void ComputeRefactoring(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            ExpressionSyntax condition = ifStatement.Condition;

            if (condition?.IsMissing != false)
            {
                return;
            }

            StatementSyntax statement = ifStatement.Statement;

            if (statement?.IsMissing != false)
            {
                return;
            }

            Document document = context.Document;

            ElseClauseSyntax elseClause = ifStatement.Else;

            if (elseClause != null)
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.InvertIfElse))
                {
                    StatementSyntax elseStatement = elseClause.Statement;

                    if (elseStatement?.IsMissing == false &&
                        !elseStatement.IsKind(SyntaxKind.IfStatement))
                    {
                        context.RegisterRefactoring(
                            "Invert if-else",
                            ct => InvertIfElseAsync(document, ifStatement, ct),
                            RefactoringIdentifiers.InvertIfElse);
                    }
                }
            }
            else if (context.IsRefactoringEnabled(RefactoringIdentifiers.InvertIf) &&
                     ifStatement.IsTopmostIf())
            {
                InvertIfAnalysis analysis = InvertIfAnalysis.Create(ifStatement, statement);

                if (analysis.Success)
                {
                    context.RegisterRefactoring(
                        "Invert if",
                        ct => InvertIfAsync(document, ifStatement, recursive: false, ct),
                        RefactoringIdentifiers.InvertIf);

                    if (analysis.AnalyzeNextStatement().Success)
                    {
                        context.RegisterRefactoring(
                            "Invert if (recursively)",
                            ct => InvertIfAsync(document, ifStatement, recursive: true, ct),
                            RecursiveRefactoringIdentifier);
                    }
                }
            }
        }
        public static bool CanRefactor(
            IfStatementSyntax ifStatement,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ifStatement.IsTopmostIf())
            {
                ElseClauseSyntax elseClause = ifStatement.Else;

                if (elseClause != null)
                {
                    ExpressionSyntax condition = ifStatement.Condition;

                    if (condition != null)
                    {
                        ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(condition, cancellationToken);

                        if (typeSymbol?.IsBoolean() == true)
                        {
                            AssignmentExpressionSyntax trueExpression = GetSimpleAssignmentExpression(ifStatement.GetSingleStatementOrDefault());

                            ExpressionSyntax trueRight = trueExpression?.Right;

                            if (trueRight?.IsBooleanLiteralExpression() == true)
                            {
                                AssignmentExpressionSyntax falseExpression = GetSimpleAssignmentExpression(elseClause.GetSingleStatementOrDefault());

                                ExpressionSyntax falseRight = falseExpression?.Right;

                                if (falseRight?.IsBooleanLiteralExpression() == true)
                                {
                                    var trueBooleanLiteral  = (LiteralExpressionSyntax)trueRight;
                                    var falseBooleanLiteral = (LiteralExpressionSyntax)falseRight;

                                    if (trueBooleanLiteral.IsKind(SyntaxKind.TrueLiteralExpression) != falseBooleanLiteral.IsKind(SyntaxKind.TrueLiteralExpression) &&
                                        trueExpression.Left?.IsEquivalentTo(falseExpression.Left, topLevel: false) == true)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf,
                    RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf,
                    RefactoringIdentifiers.SimplifyIf,
                    RefactoringIdentifiers.SwapStatementsInIfElse,
                    RefactoringIdentifiers.ReplaceIfElseWithSwitch) &&
                ifStatement.IsTopmostIf() &&
                context.Span.IsBetweenSpans(ifStatement))
            {
                if (context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf,
                        RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf,
                        RefactoringIdentifiers.SimplifyIf,
                        RefactoringIdentifiers.SplitIfStatement))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    var options = new IfAnalysisOptions(
                        useCoalesceExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf),
                        useConditionalExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf),
                        useBooleanExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.SimplifyIf));

                    foreach (IfRefactoring refactoring in IfRefactoring.Analyze(ifStatement, options, semanticModel, context.CancellationToken))
                    {
                        context.RegisterRefactoring(
                            refactoring.Title,
                            cancellationToken => refactoring.RefactorAsync(context.Document, cancellationToken));
                    }
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SwapStatementsInIfElse))
                {
                    SwapStatementInIfElseRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceIfElseWithSwitch))
                {
                    await ReplaceIfElseWithSwitchRefactoring.ComputeRefactoringAsync(context, ifStatement).ConfigureAwait(false);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfStatement))
                {
                    SplitIfStatementRefactoring.ComputeRefactoring(context, ifStatement);
                }
            }
        }
Ejemplo n.º 6
0
        public static void ComputeRefactoring(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (!ifStatement.IsTopmostIf())
            {
                return;
            }

            IfStatementSyntax topmostIf = ifStatement;

            while (true)
            {
                ElseClauseSyntax elseClause = ifStatement.Else;

                if (elseClause == null)
                {
                    return;
                }

                if (!IsLastStatementJumpStatement(ifStatement.Statement))
                {
                    return;
                }

                StatementSyntax elseStatement = elseClause.Statement;

                if (elseStatement == null)
                {
                    return;
                }

                if (elseStatement.Kind() != SyntaxKind.IfStatement)
                {
                    if (!IsLastStatementJumpStatement(elseStatement))
                    {
                        return;
                    }

                    context.RegisterRefactoring(
                        "Replace if-else with if-return",
                        cancellationToken => RefactorAsync(context.Document, topmostIf, cancellationToken));

                    return;
                }

                ifStatement = (IfStatementSyntax)elseStatement;
            }
        }
        public static void ComputeRefactoring(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (!ifStatement.IsTopmostIf())
            {
                return;
            }

            if (ifStatement.Condition.IsMissing)
            {
                return;
            }

            if (ifStatement.Parent is IfStatementSyntax parentIf)
            {
                parentIf = (IfStatementSyntax)ifStatement.Parent;
            }
            else
            {
                if (ifStatement.Parent is not BlockSyntax block)
                {
                    return;
                }

                if (block.Statements.Count != 1)
                {
                    return;
                }

                parentIf = block.Parent as IfStatementSyntax;

                if (parentIf == null)
                {
                    return;
                }
            }

            if (parentIf.Condition.IsMissing)
            {
                return;
            }

            context.RegisterRefactoring(
                "Merge if with parent if",
                ct => RefactorAsync(context.Document, ifStatement, ct),
                RefactoringDescriptors.MergeIfWithParentIf);
        }
        public static void ComputeRefactoring(
            RefactoringContext context,
            IfStatementSyntax ifStatement,
            SemanticModel semanticModel)
        {
            if (!ifStatement.IsTopmostIf())
            {
                return;
            }

            ExpressionSyntax switchExpression = null;

            foreach (IfStatementOrElseClause ifOrElse in ifStatement.AsCascade())
            {
                if (ifOrElse.IsIf)
                {
                    IfStatementSyntax ifStatement2 = ifOrElse.AsIf();

                    (bool success, ExpressionSyntax switchExpression)result = Analyze(ifStatement2.Condition?.WalkDownParentheses(), switchExpression, semanticModel, context.CancellationToken);

                    if (!result.success)
                    {
                        return;
                    }

                    switchExpression = result.switchExpression;

                    if (ContainsBreakStatementThatBelongsToParentIterationStatement(ifStatement2.Statement))
                    {
                        return;
                    }
                }
                else if (ContainsBreakStatementThatBelongsToParentIterationStatement(ifOrElse.AsElse().Statement))
                {
                    return;
                }
            }

            Document document = context.Document;

            context.RegisterRefactoring(
                "Convert to 'switch'",
                ct => RefactorAsync(document, ifStatement, ct),
                RefactoringIdentifiers.ConvertIfToSwitch);
        }
        public static async Task ComputeRefactoringAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (ifStatement.IsTopmostIf())
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                if (GetIfStatements(ifStatement)
                    .All(f => IsValidIf(f, semanticModel, context.CancellationToken)))
                {
                    string title = (ifStatement.IsSimpleIf())
                        ? "Replace if with switch"
                        : "Replace if-else with switch";

                    context.RegisterRefactoring(
                        title,
                        cancellationToken => RefactorAsync(context.Document, ifStatement, cancellationToken));
                }
            }
        }
Ejemplo n.º 10
0
        public static ImmutableArray <IfRefactoring> Analyze(
            IfStatementSyntax ifStatement,
            IfAnalysisOptions options,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ifStatement.IsTopmostIf())
            {
                ExpressionSyntax condition = ifStatement.Condition;

                if (condition != null)
                {
                    ElseClauseSyntax elseClause = ifStatement.Else;

                    if (elseClause != null)
                    {
                        if (options.CheckSpanDirectives(ifStatement))
                        {
                            StatementSyntax statement1 = ifStatement.GetSingleStatementOrDefault();

                            if (statement1 != null)
                            {
                                SyntaxKind kind1 = statement1.Kind();

                                if (kind1 == SyntaxKind.ExpressionStatement ||
                                    kind1 == SyntaxKind.ReturnStatement ||
                                    kind1 == SyntaxKind.YieldReturnStatement)
                                {
                                    StatementSyntax statement2 = elseClause.GetSingleStatementOrDefault();

                                    if (statement2?.IsKind(kind1) == true)
                                    {
                                        switch (kind1)
                                        {
                                        case SyntaxKind.ExpressionStatement:
                                        {
                                            return(Analyze(ifStatement, condition, (ExpressionStatementSyntax)statement1, (ExpressionStatementSyntax)statement2, semanticModel, cancellationToken, options));
                                        }

                                        case SyntaxKind.ReturnStatement:
                                        {
                                            return(Analyze(ifStatement, condition, ((ReturnStatementSyntax)statement1).Expression, ((ReturnStatementSyntax)statement2).Expression, semanticModel, cancellationToken, options, isYield: false));
                                        }

                                        case SyntaxKind.YieldReturnStatement:
                                        {
                                            return(Analyze(ifStatement, condition, ((YieldStatementSyntax)statement1).Expression, ((YieldStatementSyntax)statement2).Expression, semanticModel, cancellationToken, options, isYield: true));
                                        }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        StatementSyntax nextStatement = ifStatement.NextStatement();

                        if (nextStatement?.IsKind(SyntaxKind.ReturnStatement) == true)
                        {
                            return(Analyze(ifStatement, (ReturnStatementSyntax)nextStatement, options, semanticModel, cancellationToken));
                        }
                    }
                }
            }

            return(ImmutableArray <IfRefactoring> .Empty);
        }
Ejemplo n.º 11
0
        public static ImmutableArray <IfRefactoring> Analyze(
            IfStatementSyntax ifStatement,
            IfAnalysisOptions options,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!ifStatement.IsTopmostIf())
            {
                return(Empty);
            }

            ExpressionSyntax condition = ifStatement.Condition?.WalkDownParentheses();

            if (condition == null)
            {
                return(Empty);
            }

            ElseClauseSyntax elseClause = ifStatement.Else;

            if (elseClause != null)
            {
                if (!options.CheckSpanDirectives(ifStatement))
                {
                    return(Empty);
                }

                StatementSyntax statement1 = ifStatement.GetSingleStatementOrDefault();

                if (statement1 == null)
                {
                    return(Empty);
                }

                SyntaxKind kind1 = statement1.Kind();

                if (kind1.Is(
                        SyntaxKind.ExpressionStatement,
                        SyntaxKind.ReturnStatement,
                        SyntaxKind.YieldReturnStatement))
                {
                    StatementSyntax statement2 = elseClause.GetSingleStatementOrDefault();

                    if (statement2?.Kind() == kind1)
                    {
                        switch (kind1)
                        {
                        case SyntaxKind.ExpressionStatement:
                        {
                            return(Analyze(
                                       ifStatement,
                                       condition,
                                       (ExpressionStatementSyntax)statement1,
                                       (ExpressionStatementSyntax)statement2,
                                       options,
                                       semanticModel,
                                       cancellationToken));
                        }

                        case SyntaxKind.ReturnStatement:
                        {
                            return(Analyze(
                                       ifStatement,
                                       condition,
                                       ((ReturnStatementSyntax)statement1).Expression?.WalkDownParentheses(),
                                       ((ReturnStatementSyntax)statement2).Expression?.WalkDownParentheses(),
                                       options,
                                       isYield: false,
                                       semanticModel: semanticModel,
                                       cancellationToken: cancellationToken));
                        }

                        case SyntaxKind.YieldReturnStatement:
                        {
                            return(Analyze(
                                       ifStatement,
                                       condition,
                                       ((YieldStatementSyntax)statement1).Expression?.WalkDownParentheses(),
                                       ((YieldStatementSyntax)statement2).Expression?.WalkDownParentheses(),
                                       options,
                                       isYield: true,
                                       semanticModel: semanticModel,
                                       cancellationToken: cancellationToken));
                        }
                        }
                    }
                }
            }
            else if (ifStatement.NextStatementOrDefault() is ReturnStatementSyntax returnStatement)
            {
                return(Analyze(ifStatement, returnStatement, options, semanticModel, cancellationToken));
            }

            return(Empty);
        }
Ejemplo n.º 12
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            SyntaxToken ifKeyword = ifStatement.IfKeyword;

            bool isTopmostIf = ifStatement.IsTopmostIf();

            if (context.Span.IsEmptyAndContainedInSpan(ifKeyword) ||
                context.Span.IsBetweenSpans(ifStatement))
            {
                if (isTopmostIf &&
                    context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf,
                        RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf,
                        RefactoringIdentifiers.SimplifyIf))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    IfAnalysisOptions options = GetIfAnalysisOptions(context);

                    foreach (IfAnalysis analysis in IfAnalysis.Analyze(ifStatement, options, semanticModel, context.CancellationToken))
                    {
                        string refactoringId = GetRefactoringIdentifier(analysis);

                        if (context.IsRefactoringEnabled(refactoringId))
                        {
                            context.RegisterRefactoring(
                                analysis.Title,
                                ct => IfRefactoring.RefactorAsync(context.Document, analysis, ct),
                                refactoringId);
                        }
                    }
                }

                if (context.IsAnyRefactoringEnabled(RefactoringIdentifiers.InvertIf, RefactoringIdentifiers.InvertIfElse) &&
                    isTopmostIf &&
                    context.Span.IsEmptyAndContainedInSpan(ifKeyword))
                {
                    InvertIfRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceIfWithSwitch) &&
                    isTopmostIf)
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    ReplaceIfWithSwitchRefactoring.ComputeRefactoring(context, ifStatement, semanticModel);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfStatement))
                {
                    SplitIfStatementRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.MergeIfWithParentIf) &&
                    isTopmostIf &&
                    context.Span.IsEmptyAndContainedInSpan(ifKeyword))
                {
                    MergeIfWithParentIfRefactoring.ComputeRefactoring(context, ifStatement);
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.InvertIf) &&
                context.Span.IsEmptyAndContainedInSpan(ifKeyword))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                ReduceIfNestingAnalysisResult analysis = ReduceIfNestingAnalysis.Analyze(
                    ifStatement,
                    semanticModel,
                    options: ReduceIfNestingOptions.AllowNestedFix
                    | ReduceIfNestingOptions.AllowIfInsideIfElse
                    | ReduceIfNestingOptions.AllowLoop
                    | ReduceIfNestingOptions.AllowSwitchSection,
                    cancellationToken: context.CancellationToken);

                if (analysis.Success)
                {
                    context.RegisterRefactoring(
                        "Invert if",
                        ct => ReduceIfNestingRefactoring.RefactorAsync(context.Document, ifStatement, analysis.JumpKind, false, ct),
                        RefactoringIdentifiers.InvertIf);

                    if (ReduceIfNestingAnalysis.IsFixableRecursively(ifStatement, analysis.JumpKind))
                    {
                        context.RegisterRefactoring(
                            "Invert if (recursively)",
                            ct => ReduceIfNestingRefactoring.RefactorAsync(context.Document, ifStatement, analysis.JumpKind, true, ct),
                            EquivalenceKey.Join(RefactoringIdentifiers.InvertIf, "Recursive"));
                    }
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfElse) &&
                context.Span.IsEmptyAndContainedInSpan(ifKeyword))
            {
                SplitIfElseRefactoring.ComputeRefactoring(context, ifStatement);
            }
        }
Ejemplo n.º 13
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, IfStatementSyntax ifStatement)
        {
            if (ifStatement.IsTopmostIf() &&
                (context.Span.IsEmptyAndContainedInSpan(ifStatement.IfKeyword) || context.Span.IsBetweenSpans(ifStatement)))
            {
                if (context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf,
                        RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf,
                        RefactoringIdentifiers.SimplifyIf))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    var options = new IfAnalysisOptions(
                        useCoalesceExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseCoalesceExpressionInsteadOfIf),
                        useConditionalExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.UseConditionalExpressionInsteadOfIf),
                        useBooleanExpression: context.IsRefactoringEnabled(RefactoringIdentifiers.SimplifyIf),
                        useExpression: false);

                    foreach (IfAnalysis analysis in IfAnalysis.Analyze(ifStatement, options, semanticModel, context.CancellationToken))
                    {
                        context.RegisterRefactoring(
                            analysis.Title,
                            cancellationToken => IfRefactoring.RefactorAsync(context.Document, analysis, cancellationToken));
                    }
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SwapIfElse))
                {
                    SwapIfElseRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceIfWithSwitch))
                {
                    await ReplaceIfWithSwitchRefactoring.ComputeRefactoringAsync(context, ifStatement).ConfigureAwait(false);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfStatement))
                {
                    SplitIfStatementRefactoring.ComputeRefactoring(context, ifStatement);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.MergeIfWithParentIf) &&
                    context.Span.IsEmptyAndContainedInSpan(ifStatement.IfKeyword))
                {
                    MergeIfWithParentIfRefactoring.ComputeRefactoring(context, ifStatement);
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReduceIfNesting) &&
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(ifStatement.IfKeyword))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                ReduceIfNestingAnalysisResult analysis = ReduceIfNestingAnalysis.Analyze(
                    ifStatement,
                    semanticModel,
                    options: ReduceIfNestingOptions.AllowNestedFix
                    | ReduceIfNestingOptions.AllowIfInsideIfElse
                    | ReduceIfNestingOptions.AllowLoop
                    | ReduceIfNestingOptions.AllowSwitchSection,
                    taskSymbol: semanticModel.GetTypeByMetadataName(MetadataNames.System_Threading_Tasks_Task),
                    cancellationToken: context.CancellationToken);

                if (analysis.Success)
                {
                    context.RegisterRefactoring(
                        "Reduce if nesting",
                        cancellationToken => ReduceIfNestingRefactoring.RefactorAsync(context.Document, ifStatement, analysis.JumpKind, false, cancellationToken));

                    if (ReduceIfNestingAnalysis.IsFixableRecursively(ifStatement, analysis.JumpKind))
                    {
                        context.RegisterRefactoring(
                            "Reduce if nesting (recursively)",
                            cancellationToken => ReduceIfNestingRefactoring.RefactorAsync(context.Document, ifStatement, analysis.JumpKind, true, cancellationToken));
                    }
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.SplitIfElse) &&
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(ifStatement.IfKeyword))
            {
                SplitIfElseRefactoring.ComputeRefactoring(context, ifStatement);
            }
        }