Skip to content

Commit

Permalink
Remove all remaining MyCodeAction types in the repo
Browse files Browse the repository at this point in the history
Follow up to dotnet#60480 and dotnet#60557
  • Loading branch information
mavasani committed May 2, 2022
1 parent b16b817 commit 4015b93
Show file tree
Hide file tree
Showing 82 changed files with 373 additions and 761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
if (definition != null && definition.DeclaringSyntaxReferences.Length > 0)
{
context.RegisterCodeFix(
new MyCodeAction(
CodeAction.Create(
string.Format(TitleFormat, type.Name),
c => UnsealDeclarationsAsync(document.Project.Solution, definition.DeclaringSyntaxReferences, c)),
c => UnsealDeclarationsAsync(document.Project.Solution, definition.DeclaringSyntaxReferences, c),
nameof(AbstractUnsealClassCodeFixProvider)),
context.Diagnostics);
}
}
Expand Down Expand Up @@ -83,13 +84,5 @@ private static async Task<Solution> UnsealDeclarationsAsync(

return solution;
}

private sealed class MyCodeAction : CustomCodeActions.SolutionChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Solution>> createChangedSolution)
: base(title, createChangedSolution, title)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ private class MyCodeRefactoringProvider : CodeRefactoringProvider
{
public sealed override Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var codeAction = new MyCodeAction(context.Document);
var codeAction = new TestCodeAction(context.Document);
context.RegisterRefactoring(codeAction, context.Span);
return Task.CompletedTask;
}

private class MyCodeAction : CodeAction
private class TestCodeAction : CodeAction
{
private readonly Document _oldDocument;

public MyCodeAction(Document document)
public TestCodeAction(Document document)
=> _oldDocument = document;

public override string Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings

Private Class MyCodeRefactoringProvider : Inherits CodeRefactoringProvider
Public NotOverridable Overrides Function ComputeRefactoringsAsync(context As CodeRefactoringContext) As Task
Dim codeAction = New MyCodeAction(context.Document)
Dim codeAction = New TestCodeAction(context.Document)
context.RegisterRefactoring(codeAction, context.Span)
Return Task.CompletedTask
End Function

Private Class MyCodeAction : Inherits CodeAction
Private Class TestCodeAction : Inherits CodeAction
Private ReadOnly _oldDocument As Document

Public Sub New(oldDocument As Document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,5 @@ protected static ImmutableArray<SyntaxNode> GenerateAssignmentStatements(

return result.ToImmutableAndFree();
}

protected class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
: base(title, createChangedDocument, title)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Composition;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
Expand Down Expand Up @@ -50,7 +51,10 @@ statement.Parent is BlockSyntax block &&
}

context.RegisterCodeFix(
new MyCodeAction(CSharpFeaturesResources.Assign_out_parameters_at_start, GetDocumentUpdater(context)),
CodeAction.Create(
CSharpFeaturesResources.Assign_out_parameters_at_start,
GetDocumentUpdater(context),
nameof(CSharpFeaturesResources.Assign_out_parameters_at_start)),
context.Diagnostics);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var conditionalExpression = token.GetAncestor<ConditionalExpressionSyntax>();
if (conditionalExpression != null)
{
var documentChangeAction = new MyCodeAction(
c => GetChangedDocumentAsync(context.Document, conditionalExpression.SpanStart, c));
var documentChangeAction = CodeAction.Create(
CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string,
c => GetChangedDocumentAsync(context.Document, conditionalExpression.SpanStart, c),
nameof(CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string));
context.RegisterCodeFix(documentChangeAction, diagnostic);
}
}
Expand Down Expand Up @@ -122,15 +124,5 @@ private static async Task<Document> InsertCloseParenthesisAsync(
var newRoot = root.ReplaceNode(parenthesizedExpression, parenthesizedExpressionWithClosingParen);
return document.WithSyntaxRoot(newRoot);
}

private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string,
createChangedDocument,
CSharpFeaturesResources.Add_parentheses_around_conditional_expression_in_interpolated_string)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.CodeGeneration;
Expand Down Expand Up @@ -59,8 +60,10 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

context.RegisterRefactoring(
new MyCodeAction(
c => UpdateDocumentAsync(root, document, parentBlock, localFunction, c)),
CodeAction.Create(
CSharpFeaturesResources.Convert_to_method,
c => UpdateDocumentAsync(root, document, parentBlock, localFunction, c),
nameof(CSharpFeaturesResources.Convert_to_method)),
localFunction.Span);
}

Expand Down Expand Up @@ -312,13 +315,5 @@ private static string GenerateUniqueMethodName(ISymbol declaredSymbol)
baseName: declaredSymbol.Name,
reservedNames: declaredSymbol.ContainingType.GetMembers().Select(m => m.Name));
}

private sealed class MyCodeAction : CodeActions.CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Convert_to_method, createChangedDocument, nameof(CSharpFeaturesResources.Convert_to_method))
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
}

context.RegisterRefactoring(
new MyCodeAction((purpose, cancellationToken) => EnableNullableReferenceTypesAsync(document.Project, purpose, cancellationToken)));
new CodeActionWithPurpose((purpose, cancellationToken) => EnableNullableReferenceTypesAsync(document.Project, purpose, cancellationToken)));
}

private static async Task<Solution> EnableNullableReferenceTypesAsync(Project project, CodeActionPurpose purpose, CancellationToken cancellationToken)
Expand Down Expand Up @@ -252,11 +252,11 @@ private enum CodeActionPurpose
Apply,
}

private sealed class MyCodeAction : CodeAction.SolutionChangeAction
private sealed class CodeActionWithPurpose : CodeAction.SolutionChangeAction
{
private readonly Func<CodeActionPurpose, CancellationToken, Task<Solution>> _createChangedSolution;

public MyCodeAction(Func<CodeActionPurpose, CancellationToken, Task<Solution>> createChangedSolution)
public CodeActionWithPurpose(Func<CodeActionPurpose, CancellationToken, Task<Solution>> createChangedSolution)
: base(
CSharpFeaturesResources.Enable_nullable_reference_types_in_project,
cancellationToken => createChangedSolution(CodeActionPurpose.Apply, cancellationToken),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
return;

context.RegisterRefactoring(
new MyCodeAction(c => InlineTemporaryAsync(document, variableDeclarator, c)),
CodeAction.Create(
CSharpFeaturesResources.Inline_temporary_variable,
c => InlineTemporaryAsync(document, variableDeclarator, c),
nameof(CSharpFeaturesResources.Inline_temporary_variable)),
variableDeclarator.Span);
}

Expand Down Expand Up @@ -442,13 +445,5 @@ private static bool IsInDeconstructionAssignmentLeft(ExpressionSyntax node)

return false;
}

private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Inline_temporary_variable, createChangedDocument, nameof(CSharpFeaturesResources.Inline_temporary_variable))
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
}

context.RegisterRefactoring(
new MyCodeAction(
CodeAction.Create(
Title,
c => UpdateDocumentAsync(document, declaredType, c)),
c => UpdateDocumentAsync(document, declaredType, c),
nameof(Title)),
declaredType.Span);
}

Expand Down Expand Up @@ -130,13 +131,5 @@ private async Task<Document> UpdateDocumentAsync(Document document, TypeSyntax t
var newRoot = editor.GetChangedRoot();
return document.WithSyntaxRoot(newRoot);
}

private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
: base(title, createChangedDocument, title)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp.CodeGeneration;
using Microsoft.CodeAnalysis.CSharp.Extensions;
Expand Down Expand Up @@ -59,7 +60,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
return;

context.RegisterRefactoring(
new MyCodeAction(
CodeAction.Create(
CSharpFeaturesResources.Use_recursive_patterns,
_ => Task.FromResult(document.WithSyntaxRoot(replacementFunc(root))),
nameof(CSharpFeaturesResources.Use_recursive_patterns)));
Expand Down Expand Up @@ -502,13 +503,5 @@ when canConvertToSubpattern(name, arg) && !memberAccess.Expression.IsKind(Syntax
}
}
}

private sealed class MyCodeAction : CodeActions.CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument, string equivalenceKey)
: base(title, createChangedDocument, equivalenceKey)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
if (IsVerbatim(literalExpression))
{
// always offer to convert from verbatim string to normal string.
context.RegisterRefactoring(new MyCodeAction(
context.RegisterRefactoring(new PriorityBasedCodeAction(
CSharpFeaturesResources.Convert_to_regular_string,
c => ConvertToRegularStringAsync(document, literalExpression, c)));
}
else if (ContainsSimpleEscape(charService, subStringTokens))
{
// Offer to convert to a verbatim string if the normal string contains simple
// escapes that can be directly embedded in the verbatim string.
context.RegisterRefactoring(new MyCodeAction(
context.RegisterRefactoring(new PriorityBasedCodeAction(
CSharpFeaturesResources.Convert_to_verbatim_string,
c => ConvertToVerbatimStringAsync(document, literalExpression, c)));
}
Expand Down Expand Up @@ -177,7 +177,7 @@ private static bool ContainsSimpleEscape(VirtualCharSequence chars)
return false;
}

private class MyCodeAction : CodeAction.DocumentChangeAction
private class PriorityBasedCodeAction : CodeAction.DocumentChangeAction
{
/// <summary>
/// This is a generally useful feature on strings. But it's not likely to be something
Expand All @@ -186,7 +186,7 @@ private class MyCodeAction : CodeAction.DocumentChangeAction
/// </summary>
internal override CodeActionPriority Priority => CodeActionPriority.Low;

public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
public PriorityBasedCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
: base(title, createChangedDocument, title)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte

var formattingOptions = await document.GetSyntaxFormattingOptionsAsync(context.Options, cancellationToken).ConfigureAwait(false);

context.RegisterRefactoring(new MyCodeAction(
context.RegisterRefactoring(CodeAction.Create(
info.Value.title, c => ConvertAsync(document, namespaceDecl, formattingOptions, c), info.Value.equivalenceKey));
}

Expand All @@ -72,13 +72,5 @@ private static bool IsValidPosition(BaseNamespaceDeclarationSyntax baseDeclarati

throw ExceptionUtilities.UnexpectedValue(baseDeclaration.Kind());
}

private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument, string equivalenceKey)
: base(title, createChangedDocument, equivalenceKey)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
if (!CanOfferUseProgramMain(option, root, compilation, forAnalyzer: false))
return;

context.RegisterRefactoring(new MyCodeAction(
context.RegisterRefactoring(new PriorityBasedCodeAction(
c => ConvertToProgramMainAsync(document, c)));
}

private class MyCodeAction : CodeAction.DocumentChangeAction
private class PriorityBasedCodeAction : CodeAction.DocumentChangeAction
{
internal override CodeActionPriority Priority => CodeActionPriority.Low;

public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
public PriorityBasedCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpAnalyzersResources.Convert_to_Program_Main_style_program, createChangedDocument, nameof(ConvertToProgramMainCodeRefactoringProvider))
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
return;
}

context.RegisterRefactoring(new MyCodeAction(
context.RegisterRefactoring(new PriorityBasedCodeAction(
c => ConvertToTopLevelStatementsAsync(document, methodDeclaration, CodeCleanupOptions.CreateProvider(context.Options), c)));
}

private class MyCodeAction : CodeAction.DocumentChangeAction
private class PriorityBasedCodeAction : CodeAction.DocumentChangeAction
{
internal override CodeActionPriority Priority => CodeActionPriority.Low;

public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
public PriorityBasedCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpAnalyzersResources.Convert_to_top_level_statements, createChangedDocument, nameof(ConvertToTopLevelStatementsCodeRefactoringProvider))
{
}
Expand Down
Loading

0 comments on commit 4015b93

Please sign in to comment.