public static void ComputeRefactorings(RefactoringContext context, SyntaxToken semicolonToken)
        {
            if (!semicolonToken.IsKind(SyntaxKind.SemicolonToken))
            {
                return;
            }

            if (semicolonToken.IsMissing)
            {
                return;
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertExpressionBodyToBlockBody))
            {
                ArrowExpressionClauseSyntax arrowExpressionClause = GetArrowExpressionClause(semicolonToken);

                if (arrowExpressionClause?.IsMissing == false &&
                    ExpandExpressionBodyAnalysis.IsFixable(arrowExpressionClause))
                {
                    context.RegisterRefactoring(
                        ConvertExpressionBodyToBlockBodyRefactoring.Title,
                        cancellationToken => ConvertExpressionBodyToBlockBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken),
                        RefactoringIdentifiers.ConvertExpressionBodyToBlockBody);
                }
            }
        }
Beispiel #2
0
        public static void ComputeRefactorings(RefactoringContext context, ArrowExpressionClauseSyntax arrowExpressionClause)
        {
            ExpressionSyntax expression = arrowExpressionClause.Expression;

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertExpressionBodyToBlockBody) &&
                (context.Span.IsEmptyAndContainedInSpan(arrowExpressionClause) || context.Span.IsBetweenSpans(expression)) &&
                ExpandExpressionBodyAnalysis.IsFixable(arrowExpressionClause))
            {
                context.RegisterRefactoring(
                    ConvertExpressionBodyToBlockBodyRefactoring.Title,
                    ct => ConvertExpressionBodyToBlockBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, ct),
                    RefactoringDescriptors.ConvertExpressionBodyToBlockBody);
            }
        }
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArrowExpressionClauseSyntax arrowExpressionClause)
        {
            ExpressionSyntax expression = arrowExpressionClause.Expression;

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CallToMethod))
            {
                await ReturnExpressionRefactoring.ComputeRefactoringsAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertExpressionBodyToBlockBody) &&
                (context.Span.IsEmptyAndContainedInSpan(arrowExpressionClause) || context.Span.IsBetweenSpans(expression)) &&
                ExpandExpressionBodyAnalysis.IsFixable(arrowExpressionClause))
            {
                context.RegisterRefactoring(
                    ConvertExpressionBodyToBlockBodyRefactoring.Title,
                    cancellationToken => ConvertExpressionBodyToBlockBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken),
                    RefactoringIdentifiers.ConvertExpressionBodyToBlockBody);
            }
        }
        public static void ComputeRefactoring(RefactoringContext context, MemberDeclarationListSelection selectedMembers)
        {
            if (selectedMembers.Count <= 1)
            {
                return;
            }

            TextSpan span = context.Span;

            RefactoringDescriptor refactoring = GetRefactoringDescriptor(selectedMembers.First());

            if (refactoring.Id == null)
            {
                return;
            }

            if (!RefactoringDescriptorComparer.Id.Equals(refactoring, GetRefactoringDescriptor(selectedMembers.Last())))
            {
                return;
            }

            if (RefactoringDescriptorComparer.Id.Equals(refactoring, RefactoringDescriptors.ConvertBlockBodyToExpressionBody) &&
                context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody))
            {
                context.RegisterRefactoring(
                    ConvertBlockBodyToExpressionBodyRefactoring.Title,
                    ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringDescriptors.ConvertBlockBodyToExpressionBody);
            }
            else if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertExpressionBodyToBlockBody))
            {
                context.RegisterRefactoring(
                    ConvertExpressionBodyToBlockBodyRefactoring.Title,
                    ct => ConvertExpressionBodyToBlockBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringDescriptors.ConvertExpressionBodyToBlockBody);
            }
        }
        public static void ComputeRefactoring(RefactoringContext context, MemberDeclarationListSelection selectedMembers)
        {
            if (selectedMembers.Count <= 1)
            {
                return;
            }

            TextSpan span = context.Span;

            string refactoringId = GetRefactoringId(selectedMembers.First());

            if (refactoringId == null)
            {
                return;
            }

            if (refactoringId != GetRefactoringId(selectedMembers.Last()))
            {
                return;
            }

            if (refactoringId == RefactoringIdentifiers.ConvertBlockBodyToExpressionBody &&
                context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody))
            {
                context.RegisterRefactoring(
                    ConvertBlockBodyToExpressionBodyRefactoring.Title,
                    ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.ConvertBlockBodyToExpressionBody);
            }
            else if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertExpressionBodyToBlockBody))
            {
                context.RegisterRefactoring(
                    ConvertExpressionBodyToBlockBodyRefactoring.Title,
                    ct => ConvertExpressionBodyToBlockBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.ConvertExpressionBodyToBlockBody);
            }
        }