public static async Task ComputeRefactoringsAsync(RefactoringContext context, IndexerDeclarationSyntax indexerDeclaration) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkContainingClassAsAbstract) && indexerDeclaration.HeaderSpan().Contains(context.Span)) { MarkContainingClassAsAbstractRefactoring.ComputeRefactoring(context, indexerDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && indexerDeclaration.HeaderSpan().Contains(context.Span) && MakeMemberAbstractRefactoring.CanRefactor(indexerDeclaration)) { context.RegisterRefactoring( "Make indexer abstract", cancellationToken => MakeMemberAbstractRefactoring.RefactorAsync(context.Document, indexerDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberVirtual) && indexerDeclaration.HeaderSpan().Contains(context.Span)) { MakeMemberVirtualRefactoring.ComputeRefactoring(context, indexerDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && indexerDeclaration.HeaderSpan().Contains(context.Span)) { await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, indexerDeclaration).ConfigureAwait(false); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, EventFieldDeclarationSyntax eventFieldDeclaration) { if (context.IsAnyRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic, RefactoringIdentifiers.MarkAllMembersAsStatic) && eventFieldDeclaration.Span.Contains(context.Span) && MarkMemberAsStaticRefactoring.CanRefactor(eventFieldDeclaration)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic)) { context.RegisterRefactoring( "Mark event as static", cancellationToken => MarkMemberAsStaticRefactoring.RefactorAsync(context.Document, eventFieldDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkAllMembersAsStatic)) { MarkAllMembersAsStaticRefactoring.RegisterRefactoring(context, (ClassDeclarationSyntax)eventFieldDeclaration.Parent); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkContainingClassAsAbstract) && eventFieldDeclaration.Span.Contains(context.Span)) { MarkContainingClassAsAbstractRefactoring.ComputeRefactoring(context, eventFieldDeclaration); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.GenerateEventInvokingMethod)) { await GenerateOnEventMethodRefactoring.ComputeRefactoringAsync(context, eventFieldDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandEvent) && eventFieldDeclaration.Span.Contains(context.Span) && ExpandEventRefactoring.CanRefactor(eventFieldDeclaration)) { context.RegisterRefactoring( "Expand event", cancellationToken => { return(ExpandEventRefactoring.RefactorAsync( context.Document, eventFieldDeclaration, cancellationToken)); }); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && eventFieldDeclaration.Span.Contains(context.Span)) { await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, eventFieldDeclaration).ConfigureAwait(false); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, PropertyDeclarationSyntax propertyDeclaration) { if (context.IsAnyRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic, RefactoringIdentifiers.MarkAllMembersAsStatic) && propertyDeclaration.Span.Contains(context.Span) && MarkMemberAsStaticRefactoring.CanRefactor(propertyDeclaration)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic)) { context.RegisterRefactoring( "Mark property as static", cancellationToken => MarkMemberAsStaticRefactoring.RefactorAsync(context.Document, propertyDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkAllMembersAsStatic)) { MarkAllMembersAsStaticRefactoring.RegisterRefactoring(context, (ClassDeclarationSyntax)propertyDeclaration.Parent); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkContainingClassAsAbstract) && propertyDeclaration.HeaderSpan().Contains(context.Span)) { MarkContainingClassAsAbstractRefactoring.ComputeRefactoring(context, 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)); } 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)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandPropertyAndAddBackingField)) { context.RegisterRefactoring( "Expand property and add backing field", cancellationToken => ExpandPropertyAndAddBackingFieldRefactoring.RefactorAsync(context.Document, propertyDeclaration, context.Settings.PrefixFieldIdentifierWithUnderscore, cancellationToken)); } } if (context.IsRefactoringEnabled(RefactoringIdentifiers.NotifyPropertyChanged) && await NotifyPropertyChangedRefactoring.CanRefactorAsync(context, propertyDeclaration).ConfigureAwait(false)) { context.RegisterRefactoring( "Notify property changed", cancellationToken => { return(NotifyPropertyChangedRefactoring.RefactorAsync( context.Document, propertyDeclaration, context.SupportsCSharp6, cancellationToken)); }); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MakeMemberAbstract) && propertyDeclaration.HeaderSpan().Contains(context.Span) && MakeMemberAbstractRefactoring.CanRefactor(propertyDeclaration)) { context.RegisterRefactoring( "Make property abstract", cancellationToken => MakeMemberAbstractRefactoring.RefactorAsync(context.Document, propertyDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) && propertyDeclaration.HeaderSpan().Contains(context.Span)) { await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, propertyDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.RenamePropertyAccordingToTypeName)) { TypeSyntax type = propertyDeclaration.Type; if (type != null) { SyntaxToken identifier = propertyDeclaration.Identifier; if (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(identifier)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(type, context.CancellationToken); if (typeSymbol?.IsErrorType() == false) { string newName = Identifier.CreateName(typeSymbol); if (!string.IsNullOrEmpty(newName)) { newName = StringUtility.FirstCharToUpper(newName); if (!string.Equals(identifier.ValueText, newName, StringComparison.Ordinal)) { ISymbol symbol = semanticModel.GetDeclaredSymbol(propertyDeclaration, context.CancellationToken); bool isUnique = await Identifier.IsUniqueMemberNameAsync( symbol, newName, context.Solution, context.CancellationToken).ConfigureAwait(false); if (isUnique) { context.RegisterRefactoring( $"Rename property to '{newName}'", cancellationToken => Renamer.RenameSymbolAsync(context.Document, symbol, newName, cancellationToken)); } } } } } } } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, MethodDeclarationSyntax methodDeclaration) { if (methodDeclaration.Span.Contains(context.Span)) { if (context.IsAnyRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic, RefactoringIdentifiers.MarkAllMembersAsStatic) && MarkMemberAsStaticRefactoring.CanRefactor(methodDeclaration)) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic)) { context.RegisterRefactoring( "Mark method as static", cancellationToken => MarkMemberAsStaticRefactoring.RefactorAsync(context.Document, methodDeclaration, cancellationToken)); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkAllMembersAsStatic)) { MarkAllMembersAsStaticRefactoring.RegisterRefactoring(context, (ClassDeclarationSyntax)methodDeclaration.Parent); } } await ChangeMethodReturnTypeToVoidRefactoring.ComputeRefactoringAsync(context, methodDeclaration).ConfigureAwait(false); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkContainingClassAsAbstract) && methodDeclaration.HeaderSpan().Contains(context.Span)) { MarkContainingClassAsAbstractRefactoring.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); } }