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

            if (semicolonToken.IsMissing)
            {
                return;
            }

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

                if (arrowExpressionClause?.IsMissing == false &&
                    ExpandExpressionBodyAnalysis.IsFixable(arrowExpressionClause))
                {
                    context.RegisterRefactoring(
                        "Expand expression body",
                        cancellationToken => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken));
                }
            }
        }
Beispiel #2
0
        public static void ComputeRefactoring(RefactoringContext context, MemberDeclarationListSelection selectedMembers)
        {
            if (selectedMembers.Count <= 1)
            {
                return;
            }

            SyntaxListSelection <MemberDeclarationSyntax> .Enumerator en = selectedMembers.GetEnumerator();

            if (!en.MoveNext())
            {
                return;
            }

            TextSpan span = context.Span;

            string refactoringId = GetRefactoringId(en.Current);

            if (refactoringId == null)
            {
                return;
            }

            while (en.MoveNext())
            {
                if (refactoringId != GetRefactoringId(en.Current))
                {
                    return;
                }
            }

            if (refactoringId == RefactoringIdentifiers.UseExpressionBodiedMember &&
                context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember))
            {
                context.RegisterRefactoring(
                    UseExpressionBodiedMemberRefactoring.Title,
                    ct => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.UseExpressionBodiedMember);
            }
            else if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandExpressionBody))
            {
                context.RegisterRefactoring(
                    ExpandExpressionBodyRefactoring.Title,
                    ct => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.ExpandExpressionBody);
            }
        }
Beispiel #3
0
        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.ExpandExpressionBody) &&
                (context.Span.IsEmptyAndContainedInSpan(arrowExpressionClause) || context.Span.IsBetweenSpans(expression)) &&
                ExpandExpressionBodyAnalysis.IsFixable(arrowExpressionClause))
            {
                context.RegisterRefactoring(
                    "Expand expression body",
                    cancellationToken => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken));
            }
        }
        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.UseExpressionBodiedMember &&
                context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember))
            {
                context.RegisterRefactoring(
                    UseExpressionBodiedMemberRefactoring.Title,
                    ct => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.UseExpressionBodiedMember);
            }
            else if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandExpressionBody))
            {
                context.RegisterRefactoring(
                    ExpandExpressionBodyRefactoring.Title,
                    ct => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, selectedMembers, ct),
                    RefactoringIdentifiers.ExpandExpressionBody);
            }
        }
Beispiel #5
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArrowExpressionClauseSyntax arrowExpressionClause)
        {
            ExpressionSyntax expression = arrowExpressionClause.Expression;

            if (expression != null &&
                context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.AddBooleanComparison,
                    RefactoringIdentifiers.ChangeMemberTypeAccordingToReturnExpression,
                    RefactoringIdentifiers.AddCastExpression,
                    RefactoringIdentifiers.CallToMethod))
            {
                await ReturnExpressionRefactoring.ComputeRefactoringsAsync(context, expression).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandExpressionBody) &&
                (context.Span.IsEmptyAndContainedInSpan(arrowExpressionClause) ||
                 context.Span.IsBetweenSpans(expression)) &&
                ExpandExpressionBodyRefactoring.CanRefactor(arrowExpressionClause))
            {
                context.RegisterRefactoring(
                    "Expand expression body",
                    cancellationToken => ExpandExpressionBodyRefactoring.RefactorAsync(context.Document, arrowExpressionClause, cancellationToken));
            }
        }