Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React to breaking api change #7589

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,21 @@ protected override CodeAction CreateCodeAction(Document document, SyntaxNode arg
return new CSharpReplaceStringLiteralWithCharLiteralCodeAction(document, argumentListNode, sourceCharLiteral);
}

private sealed class CSharpReplaceStringLiteralWithCharLiteralCodeAction : ReplaceStringLiteralWithCharLiteralCodeAction
private sealed class CSharpReplaceStringLiteralWithCharLiteralCodeAction(
Document document, SyntaxNode argumentListNode, char sourceCharLiteral)
: ReplaceStringLiteralWithCharLiteralCodeAction(document, argumentListNode, sourceCharLiteral)
{
public CSharpReplaceStringLiteralWithCharLiteralCodeAction(Document document, SyntaxNode argumentListNode, char sourceCharLiteral) : base(document, argumentListNode, sourceCharLiteral)
{
}

protected override void ApplyFix(
DocumentEditor editor,
SemanticModel model,
SyntaxNode oldArgumentListNode,
char c)
{
var argumentNode = editor.Generator.Argument(editor.Generator.LiteralExpression(c));
var argumentNode = (ArgumentSyntax)editor.Generator.Argument(editor.Generator.LiteralExpression(c));
var arguments = new[] { argumentNode }.Concat(((ArgumentListSyntax)oldArgumentListNode).Arguments
.Select(arg => model.GetOperation(arg) as IArgumentOperation)
.Where(PreserveArgument)
.Select(arg => arg!.Syntax));
.Select(arg => (arg, operation: model.GetOperation(arg) as IArgumentOperation))
.Where(t => PreserveArgument(t.operation))
.Select(t => t.arg));
var argumentListNode = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments));

editor.ReplaceNode(oldArgumentListNode, argumentListNode.WithTriviaFrom(oldArgumentListNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.NetCore.Analyzers.Performance

Namespace Microsoft.NetCore.VisualBasic.Analyzers.Performance

<ExportCodeFixProvider(LanguageNames.VisualBasic), [Shared]>
Public NotInheritable Class BasicUseStringMethodCharOverloadWithSingleCharactersFixer
Inherits UseStringMethodCharOverloadWithSingleCharactersFixer
Expand Down Expand Up @@ -65,15 +64,16 @@ Namespace Microsoft.NetCore.VisualBasic.Analyzers.Performance
End Sub

Protected Overrides Sub ApplyFix(editor As DocumentEditor, model As SemanticModel, oldArgumentListNode As SyntaxNode, c As Char)
Dim argumentNode = editor.Generator.Argument(editor.Generator.LiteralExpression(c))
Dim argumentNode = DirectCast(editor.Generator.Argument(editor.Generator.LiteralExpression(c)), ArgumentSyntax)
Dim arguments = {argumentNode}.Concat(
CType(oldArgumentListNode, ArgumentListSyntax).Arguments.
[Select](Function(arg) TryCast(model.GetOperation(arg), IArgumentOperation)).Where(Function(arg) PreserveArgument(arg)).[Select](Function(arg) arg.Syntax))
Select(Function(arg) (arg, operation:=TryCast(model.GetOperation(arg), IArgumentOperation))).
Where(Function(t) PreserveArgument(t.operation)).
Select(Function(t) t.arg))
Dim argumentListNode = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))

editor.ReplaceNode(oldArgumentListNode, argumentListNode.WithTriviaFrom(oldArgumentListNode))
End Sub
End Class
End Class

End Namespace