Exemple #1
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList)
        {
            SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

            if (parameters.Count == 0)
            {
                return;
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateParameter))
            {
                var refactoring = new DuplicateParameterRefactoring(parameterList);
                refactoring.ComputeRefactoring(context);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull))
            {
                await CheckParameterForNullRefactoring.ComputeRefactoringAsync(context, parameterList).ConfigureAwait(false);
            }

            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.IntroduceAndInitializeField,
                    RefactoringIdentifiers.IntroduceAndInitializeProperty))
            {
                IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatParameterList) &&
                (context.Span.IsEmpty || context.Span.IsBetweenSpans(parameterList)))
            {
                if (parameterList.IsSingleLine())
                {
                    if (parameters.Count > 1)
                    {
                        context.RegisterRefactoring(
                            "Format each parameter on a separate line",
                            cancellationToken => FormatParameterListRefactoring.FormatEachParameterOnSeparateLineAsync(context.Document, parameterList, cancellationToken));
                    }
                }
                else
                {
                    string title = parameters.Count == 1
                        ? "Format parameter on a single line"
                        : "Format all parameters on a single line";

                    context.RegisterRefactoring(
                        title,
                        cancellationToken => FormatParameterListRefactoring.FormatAllParametersOnSingleLineAsync(context.Document, parameterList, cancellationToken));
                }
            }
        }
Exemple #2
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList)
        {
            SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

            if (parameters.Any())
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateParameter))
                {
                    var refactoring = new DuplicateParameterRefactoring(parameterList);
                    refactoring.ComputeRefactoring(context, RefactoringIdentifiers.DuplicateParameter);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull) &&
                    SeparatedSyntaxListSelection <ParameterSyntax> .TryCreate(parameterList.Parameters, context.Span, out SeparatedSyntaxListSelection <ParameterSyntax> selectedParameters))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    CheckParameterForNullRefactoring.ComputeRefactoring(context, selectedParameters, semanticModel);
                }

                if (context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.IntroduceAndInitializeField,
                        RefactoringIdentifiers.IntroduceAndInitializeProperty))
                {
                    IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatParameterList) &&
                    (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(parameterList)))
                {
                    if (parameterList.IsSingleLine())
                    {
                        if (parameters.Count > 1)
                        {
                            context.RegisterRefactoring(
                                "Format parameters on separate lines",
                                cancellationToken => SyntaxFormatter.ToMultiLineAsync(context.Document, parameterList, cancellationToken),
                                RefactoringIdentifiers.FormatParameterList);
                        }
                    }
                    else if (parameterList.DescendantTrivia(parameterList.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()))
                    {
                        context.RegisterRefactoring(
                            "Format parameters on a single line",
                            cancellationToken => SyntaxFormatter.ToSingleLineAsync(context.Document, parameterList, cancellationToken),
                            RefactoringIdentifiers.FormatParameterList);
                    }
                }
            }
        }
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList)
        {
            SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

            if (parameters.Any())
            {
                if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyParameter))
                {
                    var refactoring = new CopyParameterRefactoring(parameterList);
                    refactoring.ComputeRefactoring(context, RefactoringDescriptors.CopyParameter);
                }

                if (context.IsRefactoringEnabled(RefactoringDescriptors.CheckParameterForNull) &&
                    SeparatedSyntaxListSelection <ParameterSyntax> .TryCreate(parameterList.Parameters, context.Span, out SeparatedSyntaxListSelection <ParameterSyntax> selectedParameters))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    CheckParameterForNullRefactoring.ComputeRefactoring(context, selectedParameters, semanticModel);
                }

                if (context.IsAnyRefactoringEnabled(
                        RefactoringDescriptors.IntroduceAndInitializeField,
                        RefactoringDescriptors.IntroduceAndInitializeProperty))
                {
                    IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList);
                }

                if (context.IsRefactoringEnabled(RefactoringDescriptors.WrapParameters) &&
                    (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(parameterList)))
                {
                    if (parameterList.IsSingleLine())
                    {
                        if (parameters.Count > 1)
                        {
                            context.RegisterRefactoring(
                                "Wrap parameters",
                                ct => SyntaxFormatter.WrapParametersAsync(context.Document, parameterList, ct),
                                RefactoringDescriptors.WrapParameters);
                        }
                    }
                    else if (parameterList.DescendantTrivia(parameterList.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()))
                    {
                        context.RegisterRefactoring(
                            "Unwrap parameters",
                            ct => SyntaxFormatter.UnwrapExpressionAsync(context.Document, parameterList, ct),
                            RefactoringDescriptors.WrapParameters);
                    }
                }
            }
        }
Exemple #4
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList)
        {
            SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

            if (parameters.Any())
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateParameter))
                {
                    var refactoring = new DuplicateParameterRefactoring(parameterList);
                    refactoring.ComputeRefactoring(context);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull))
                {
                    await CheckParameterForNullRefactoring.ComputeRefactoringAsync(context, parameterList).ConfigureAwait(false);
                }

                if (context.IsAnyRefactoringEnabled(
                        RefactoringIdentifiers.IntroduceAndInitializeField,
                        RefactoringIdentifiers.IntroduceAndInitializeProperty))
                {
                    IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatParameterList) &&
                    (context.Span.IsEmpty || context.Span.IsBetweenSpans(parameterList)))
                {
                    if (parameterList.IsSingleLine())
                    {
                        if (parameters.Count > 1)
                        {
                            context.RegisterRefactoring(
                                "Format parameters on separate lines",
                                cancellationToken => CSharpFormatter.ToMultiLineAsync(context.Document, parameterList, cancellationToken));
                        }
                    }
                    else
                    {
                        context.RegisterRefactoring(
                            "Format parameters on a single line",
                            cancellationToken => CSharpFormatter.ToSingleLineAsync(context.Document, parameterList, cancellationToken));
                    }
                }
            }
        }
Exemple #5
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterSyntax parameter)
        {
            await AddOrRenameParameterRefactoring.ComputeRefactoringsAsync(context, parameter).ConfigureAwait(false);

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull))
            {
                await CheckParameterForNullRefactoring.ComputeRefactoringAsync(context, parameter).ConfigureAwait(false);
            }

            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.IntroduceAndInitializeField,
                    RefactoringIdentifiers.IntroduceAndInitializeProperty))
            {
                IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameter);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddDefaultValueToParameter))
            {
                await AddDefaultValueToParameterRefactoring.ComputeRefactoringAsync(context, parameter).ConfigureAwait(false);
            }
        }
Exemple #6
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterSyntax parameter)
        {
            await AddOrRenameParameterRefactoring.ComputeRefactoringsAsync(context, parameter).ConfigureAwait(false);

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull) &&
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(parameter.Identifier))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                CheckParameterForNullRefactoring.ComputeRefactoring(context, parameter, semanticModel);
            }

            if (context.IsAnyRefactoringEnabled(
                    RefactoringIdentifiers.IntroduceAndInitializeField,
                    RefactoringIdentifiers.IntroduceAndInitializeProperty))
            {
                IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameter);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddDefaultValueToParameter))
            {
                await AddDefaultValueToParameterRefactoring.ComputeRefactoringAsync(context, parameter).ConfigureAwait(false);
            }
        }