public static async Task ComputeRefactoringsAsync(RefactoringContext context, LocalFunctionStatementSyntax localFunctionStatement) { if (localFunctionStatement.IsParentKind(SyntaxKind.Block)) { BlockSyntax body = localFunctionStatement.Body; if (body != null) { if (body.OpenBraceToken.Span.Contains(context.Span) || body.CloseBraceToken.Span.Contains(context.Span)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveMember)) { context.RegisterRefactoring(CodeActionFactory.RemoveStatement(context.Document, localFunctionStatement, equivalenceKey: RefactoringIdentifiers.RemoveMember)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateMember)) { context.RegisterRefactoring( "Duplicate local function", cancellationToken => DuplicateMemberDeclarationRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken), RefactoringIdentifiers.DuplicateMember); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CommentOutMember)) { CommentOutRefactoring.RegisterRefactoring(context, localFunctionStatement); } } } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ChangeMethodReturnTypeToVoid) && context.Span.IsEmptyAndContainedInSpan(localFunctionStatement)) { await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, localFunctionStatement).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddTypeParameter)) { AddTypeParameterRefactoring.ComputeRefactoring(context, localFunctionStatement); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody) && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(localFunctionStatement, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, cancellationToken => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, localFunctionStatement, cancellationToken), RefactoringIdentifiers.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MoveUnsafeContextToContainingDeclaration)) { MoveUnsafeContextToContainingDeclarationRefactoring.ComputeRefactoring(context, localFunctionStatement); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, IndexerDeclarationSyntax indexerDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(indexerDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, indexerDeclaration, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringDescriptors.MakeMemberAbstract) && context.Span.IsEmptyAndContainedInSpan(indexerDeclaration.ThisKeyword)) { MakeIndexerAbstractRefactoring.ComputeRefactoring(context, indexerDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.MakeMemberVirtual) && indexerDeclaration.HeaderSpan().Contains(context.Span)) { MakeIndexerVirtualRefactoring.ComputeRefactoring(context, indexerDeclaration); } if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyDocumentationCommentFromBaseMember) && indexerDeclaration.HeaderSpan().Contains(context.Span) && !indexerDeclaration.HasDocumentationComment()) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoring(context, indexerDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringDescriptors.AddParameterToInterfaceMember) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(indexerDeclaration.ThisKeyword)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); foreach (CodeAction codeAction in AddParameterToInterfaceMemberRefactoring.ComputeRefactoringForImplicitImplementation( new CommonFixContext(context.Document, EquivalenceKey.Create(RefactoringDescriptors.AddParameterToInterfaceMember), semanticModel, context.CancellationToken), indexerDeclaration)) { context.RegisterRefactoring(codeAction); } } if (context.IsRefactoringEnabled(RefactoringDescriptors.AddMemberToInterface) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(indexerDeclaration.ThisKeyword)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); AddMemberToInterfaceRefactoring.ComputeRefactoring(context, indexerDeclaration, semanticModel); } }
public static void ComputeRefactorings(RefactoringContext context, DestructorDeclarationSyntax destructorDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(destructorDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, destructorDeclaration, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } }
private static void ComputeRefactorings(RefactoringContext context, ConversionOperatorDeclarationSyntax operatorDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(operatorDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, cancellationToken => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, operatorDeclaration, cancellationToken), RefactoringIdentifiers.ConvertBlockBodyToExpressionBody); } }
public static void ComputeRefactorings(RefactoringContext context, AccessorDeclarationSyntax accessor) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(accessor, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, accessor, ct), RefactoringIdentifiers.ConvertBlockBodyToExpressionBody); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, ConstructorDeclarationSyntax constructorDeclaration) { if (context.IsRefactoringEnabled(RefactoringDescriptors.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(constructorDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, constructorDeclaration, ct), RefactoringDescriptors.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyDocumentationCommentFromBaseMember) && constructorDeclaration.HeaderSpan().Contains(context.Span) && !constructorDeclaration.HasDocumentationComment()) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoring(context, constructorDeclaration, semanticModel); } }
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); } }
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, PropertyDeclarationSyntax propertyDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplacePropertyWithMethod) && propertyDeclaration.HeaderSpan().Contains(context.Span)) { ReplacePropertyWithMethodRefactoring.ComputeRefactoring(context, propertyDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemovePropertyInitializer) && RemovePropertyInitializerRefactoring.CanRefactor(context, propertyDeclaration)) { context.RegisterRefactoring( "Remove property initializer", cancellationToken => RemovePropertyInitializerRefactoring.RefactorAsync(context.Document, propertyDeclaration, cancellationToken), RefactoringIdentifiers.RemovePropertyInitializer); } if (context.IsAnyRefactoringEnabled( RefactoringIdentifiers.ExpandProperty, RefactoringIdentifiers.ExpandPropertyAndAddBackingField) && propertyDeclaration.Span.Contains(context.Span) && ExpandPropertyRefactoring.CanRefactor(propertyDeclaration)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandProperty)) { context.RegisterRefactoring( "Expand property", cancellationToken => ExpandPropertyRefactoring.RefactorAsync(context.Document, propertyDeclaration, cancellationToken), RefactoringIdentifiers.ExpandProperty); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandPropertyAndAddBackingField)) { context.RegisterRefactoring( "Expand property and add backing field", cancellationToken => ExpandPropertyAndAddBackingFieldRefactoring.RefactorAsync(context.Document, propertyDeclaration, context.Settings.PrefixFieldIdentifierWithUnderscore, cancellationToken), RefactoringIdentifiers.ExpandPropertyAndAddBackingField); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ConvertBlockBodyToExpressionBody) && context.SupportsCSharp6 && ConvertBlockBodyToExpressionBodyRefactoring.CanRefactor(propertyDeclaration, context.Span)) { context.RegisterRefactoring( ConvertBlockBodyToExpressionBodyRefactoring.Title, ct => ConvertBlockBodyToExpressionBodyRefactoring.RefactorAsync(context.Document, propertyDeclaration, ct), RefactoringIdentifiers.ConvertBlockBodyToExpressionBody); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.NotifyWhenPropertyChange)) { await NotifyWhenPropertyChangeRefactoring.ComputeRefactoringAsync(context, propertyDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && propertyDeclaration.HeaderSpan().Contains(context.Span)) { MakePropertyAbstractRefactoring.ComputeRefactoring(context, propertyDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberVirtual) && context.Span.IsEmptyAndContainedInSpan(propertyDeclaration.Identifier)) { MakePropertyVirtualRefactoring.ComputeRefactoring(context, propertyDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && propertyDeclaration.HeaderSpan().Contains(context.Span) && !propertyDeclaration.HasDocumentationComment()) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoring(context, propertyDeclaration, semanticModel); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RenamePropertyAccordingToTypeName)) { await RenamePropertyAccordingToTypeName(context, propertyDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddMemberToInterface) && context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(propertyDeclaration.Identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); AddMemberToInterfaceRefactoring.ComputeRefactoring(context, propertyDeclaration, semanticModel); } }