public static async Task ComputeRefactoringsAsync(RefactoringContext context, MethodDeclarationSyntax methodDeclaration) { if (methodDeclaration.Span.Contains(context.Span)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceMethodWithProperty) && methodDeclaration.HeaderSpan().Contains(context.Span) && ReplaceMethodWithPropertyRefactoring.CanRefactor(methodDeclaration)) { context.RegisterRefactoring( $"Replace '{methodDeclaration.Identifier.ValueText}' with property", cancellationToken => ReplaceMethodWithPropertyRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && methodDeclaration.Body?.Span.Contains(context.Span) == true && context.SupportsCSharp6 && UseExpressionBodiedMemberRefactoring.CanRefactor(methodDeclaration)) { context.RegisterRefactoring( "Use expression-bodied member", cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && methodDeclaration.HeaderSpan().Contains(context.Span) && MakeMemberAbstractRefactoring.CanRefactor(methodDeclaration)) { context.RegisterRefactoring( "Make method abstract", cancellationToken => MakeMemberAbstractRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberVirtual) && methodDeclaration.HeaderSpan().Contains(context.Span)) { MakeMemberVirtualRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && methodDeclaration.HeaderSpan().Contains(context.Span)) { await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RenameMethodAccordingToTypeName)) { await RenameMethodAccoringToTypeNameAsync(context, methodDeclaration).ConfigureAwait(false); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, MethodDeclarationSyntax methodDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ChangeMethodReturnTypeToVoid) && context.Span.IsEmptyAndContainedInSpan(methodDeclaration)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceMethodWithProperty) && methodDeclaration.HeaderSpan().Contains(context.Span) && ReplaceMethodWithPropertyRefactoring.CanRefactor(methodDeclaration)) { context.RegisterRefactoring( $"Replace '{methodDeclaration.Identifier.ValueText}' with property", cancellationToken => ReplaceMethodWithPropertyRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken), RefactoringIdentifiers.ReplaceMethodWithProperty); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(methodDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, cancellationToken => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken), RefactoringIdentifiers.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && context.Span.IsEmptyAndContainedInSpan(methodDeclaration.Identifier)) { MakeMethodAbstractRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberVirtual) && methodDeclaration.HeaderSpan().Contains(context.Span)) { MakeMethodVirtualRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && methodDeclaration.HeaderSpan().Contains(context.Span) && !methodDeclaration.HasDocumentationComment()) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoring(context, methodDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RenameMethodAccordingToTypeName)) { await RenameMethodAccordingToTypeNameAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddParameterToInterfaceMember) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(methodDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); foreach (CodeAction codeAction in AddParameterToInterfaceMemberRefactoring.ComputeRefactoringForImplicitImplementation( new CommonFixContext(context.Document, RefactoringIdentifiers.AddParameterToInterfaceMember, semanticModel, context.CancellationToken), methodDeclaration)) { context.RegisterRefactoring(codeAction); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddMemberToInterface) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(methodDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); AddMemberToInterfaceRefactoring.ComputeRefactoring(context, methodDeclaration, semanticModel); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, MethodDeclarationSyntax methodDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ChangeMethodReturnTypeToVoid) && methodDeclaration.Span.Contains(context.Span)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceMethodWithProperty) && methodDeclaration.HeaderSpan().Contains(context.Span) && ReplaceMethodWithPropertyRefactoring.CanRefactor(methodDeclaration)) { context.RegisterRefactoring( $"Replace '{methodDeclaration.Identifier.ValueText}' with property", cancellationToken => ReplaceMethodWithPropertyRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) && methodDeclaration.Body?.Span.Contains(context.Span) == true && context.SupportsCSharp6 && UseExpressionBodiedMemberAnalysis.IsFixable(methodDeclaration)) { context.RegisterRefactoring( "Use expression-bodied member", cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && methodDeclaration.HeaderSpan().Contains(context.Span)) { MakeMethodAbstractRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberVirtual) && methodDeclaration.HeaderSpan().Contains(context.Span)) { MakeMethodVirtualRefactoring.ComputeRefactoring(context, methodDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && methodDeclaration.HeaderSpan().Contains(context.Span)) { await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RenameMethodAccordingToTypeName)) { await RenameMethodAccoringToTypeNameAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddMemberToInterface) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(methodDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); AddMemberToInterfaceRefactoring.ComputeRefactoring(context, methodDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseListInsteadOfYield) && methodDeclaration.Identifier.Span.Contains(context.Span)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); UseListInsteadOfYieldRefactoring.ComputeRefactoring(context, methodDeclaration, semanticModel); } }