internal static void ComputeRefactoring(RefactoringContext context, BinaryExpressionSpan binaryExpressionSpan) { BinaryExpressionSyntax binaryExpression = binaryExpressionSpan.BinaryExpression; SyntaxKind kind = binaryExpression.Kind(); if (kind == SyntaxKind.LogicalAndExpression || kind == SyntaxKind.LogicalOrExpression) { BinaryExpressionSyntax condition = GetCondition(binaryExpression); if (condition != null) { SyntaxNode parent = condition.Parent; switch (parent?.Kind()) { case SyntaxKind.IfStatement: { if (kind == SyntaxKind.LogicalAndExpression) { var refactoring = new ExtractConditionFromIfToNestedIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (IfStatementSyntax)parent, condition, binaryExpressionSpan, cancellationToken)); } else if (kind == SyntaxKind.LogicalOrExpression) { IStatementContainer container = GetStatementContainer((StatementSyntax)parent); if (container != null) { var refactoring = new ExtractConditionFromIfToIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, container, condition, binaryExpressionSpan, cancellationToken)); } } break; } case SyntaxKind.WhileStatement: { if (kind == SyntaxKind.LogicalAndExpression) { var refactoring = new ExtractConditionFromWhileToNestedIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (WhileStatementSyntax)parent, condition, binaryExpressionSpan, cancellationToken)); } break; } } } } }
internal static void ComputeRefactoring(RefactoringContext context, BinaryExpressionSelection binaryExpressionSelection) { BinaryExpressionSyntax binaryExpression = binaryExpressionSelection.BinaryExpression; SyntaxKind kind = binaryExpression.Kind(); if (!kind.Is(SyntaxKind.LogicalAndExpression, SyntaxKind.LogicalOrExpression)) { return; } BinaryExpressionSyntax condition = GetCondition(binaryExpression); if (condition == null) { return; } SyntaxNode parent = condition.Parent; switch (parent?.Kind()) { case SyntaxKind.IfStatement: { if (kind == SyntaxKind.LogicalAndExpression) { ExtractConditionFromIfToNestedIfRefactoring refactoring = ExtractConditionFromIfToNestedIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (IfStatementSyntax)parent, condition, binaryExpressionSelection, cancellationToken), RefactoringIdentifiers.ExtractExpressionFromCondition); } else if (kind == SyntaxKind.LogicalOrExpression) { StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo((StatementSyntax)parent); if (statementsInfo.Success) { ExtractConditionFromIfToIfRefactoring refactoring = ExtractConditionFromIfToIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, statementsInfo, condition, binaryExpressionSelection, cancellationToken), RefactoringIdentifiers.ExtractExpressionFromCondition); } } break; } case SyntaxKind.WhileStatement: { if (kind == SyntaxKind.LogicalAndExpression) { ExtractConditionFromWhileToNestedIfRefactoring refactoring = ExtractConditionFromWhileToNestedIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (WhileStatementSyntax)parent, condition, binaryExpressionSelection, cancellationToken), RefactoringIdentifiers.ExtractExpressionFromCondition); } break; } } }
public static void ComputeRefactoring(RefactoringContext context, ExpressionSyntax expression) { SyntaxNode parent = expression.Parent; if (parent == null) { return; } SyntaxKind kind = parent.Kind(); if (!kind.Is(SyntaxKind.LogicalAndExpression, SyntaxKind.LogicalOrExpression)) { return; } BinaryExpressionSyntax binaryExpression = GetCondition((BinaryExpressionSyntax)parent); if (binaryExpression == null) { return; } parent = binaryExpression.Parent; switch (parent?.Kind()) { case SyntaxKind.IfStatement: { if (kind == SyntaxKind.LogicalAndExpression) { ExtractConditionFromIfToNestedIfRefactoring refactoring = ExtractConditionFromIfToNestedIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, binaryExpression, expression, cancellationToken)); } else if (kind == SyntaxKind.LogicalOrExpression) { StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo((StatementSyntax)parent); if (statementsInfo.Success) { ExtractConditionFromIfToIfRefactoring refactoring = ExtractConditionFromIfToIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, statementsInfo, binaryExpression, expression, cancellationToken)); } } break; } case SyntaxKind.WhileStatement: { if (kind == SyntaxKind.LogicalAndExpression) { StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo((StatementSyntax)parent); if (statementsInfo.Success) { ExtractConditionFromWhileToNestedIfRefactoring refactoring = ExtractConditionFromWhileToNestedIfRefactoring.Instance; context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (WhileStatementSyntax)parent, binaryExpression, expression, cancellationToken)); } } break; } } }
public static void ComputeRefactoring(RefactoringContext context, ExpressionSyntax expression) { SyntaxNode parent = expression.Parent; if (parent != null) { SyntaxKind kind = parent.Kind(); if (kind == SyntaxKind.LogicalAndExpression || kind == SyntaxKind.LogicalOrExpression) { BinaryExpressionSyntax binaryExpression = GetCondition((BinaryExpressionSyntax)parent); if (binaryExpression != null) { parent = binaryExpression.Parent; switch (parent?.Kind()) { case SyntaxKind.IfStatement: { if (kind == SyntaxKind.LogicalAndExpression) { var refactoring = new ExtractConditionFromIfToNestedIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, binaryExpression, expression, cancellationToken)); } else if (kind == SyntaxKind.LogicalOrExpression) { StatementContainer container; if (StatementContainer.TryCreate((StatementSyntax)parent, out container)) { var refactoring = new ExtractConditionFromIfToIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, container, binaryExpression, expression, cancellationToken)); } } break; } case SyntaxKind.WhileStatement: { if (kind == SyntaxKind.LogicalAndExpression) { StatementContainer container; if (StatementContainer.TryCreate((StatementSyntax)parent, out container)) { var refactoring = new ExtractConditionFromWhileToNestedIfRefactoring(); context.RegisterRefactoring( refactoring.Title, cancellationToken => refactoring.RefactorAsync(context.Document, (WhileStatementSyntax)parent, binaryExpression, expression, cancellationToken)); } } break; } } } } } }